Integration Toolbox
for IBM® TIVOLI® Storage Manager

package backup_group; import hu.user.toolbox.tsm.IBackupGroupLeader; import hu.user.toolbox.tsm.IBackupObject; import hu.user.toolbox.tsm.IFilespace; import hu.user.toolbox.tsm.IResultSet; import hu.user.toolbox.tsm.ITSMSession; import hu.user.toolbox.tsm.Toolbox; import hu.user.toolbox.tsm.enums.ObjectType; import hu.user.toolbox.tsm.exception.ToolboxErrorCodes; import hu.user.toolbox.tsm.exception.ToolboxException; import hu.user.toolbox.tsm.internal.structures.DsUint160_t; import hu.user.toolbox.tsm.query.IBackupGroupQuery; import hu.user.toolbox.tsm.query.IBackupQuery; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; /** * <b>Function:</b><br> * Creates a backup group leader and presents all group functions. * <p> * Before executing this program register a filespace named "/BACKUPFS" * using the RegisterFilespace sample. * <p> * The following operations are performed: * <ol> * <li>Initializing a single-threaded TSM API environment.</li> * <li>Creating a new TSMSession instance. * Setting default connection options. Connecting to the server using * the node name "TOOLBOX" and password "PASSWORD".</li> * <li>Retrieving the filespace named "/BACKUPFS"</li> * <li>Creating a new backup group leader object with the following parameters: * high-level name "/GROUP", low-level name "/leader and type "FILE".</li> * <li>Opening the backup group.</li> * <li>Querying open groups.</li> * <li>Creating a new backup object with the following parameters: * high-level name "/GROUP", low-level name "/assigned_member" and sending it to the server.</li> * <li>Querying the sent member object.</li> * <li>Assigning the backup object to the group.</li> * <li>Creating a new backup object with the following parameters: * high-level name "/GROUP", low-level name "/added_member".</li> * <li>Adding a new member to the group.</li> * <li>Querying all member objects.</li> * <li>Querying closed groups.</li> * <li>Disconnecting from the server and cleaning up the resources.</li> * </ol> * <p> * <b>Compile:</b> * <pre> * javac -d bin -cp ../lib/toolboxfortsm.jar backup_group/BackupGroup.java * </pre> * <p> * <b>Execute:</b><br> * You should first set the environment variables to point to the correct * files/directories. * <pre> * set DSMI_CONFIG={Full path of your dsm.opt} * set DSMI_DIR={Tivoli Storage Manager API installation directory} * set DSMI_LOG={Any arbitrary directory} * </pre> * Then use the java command to execute the program: * <p> * <pre> * java -cp bin:../lib/toolboxfortsm.jar:../lib/ext/log4j-1.2.17.jar:../config * -Djava.library.path=../lib backup_group.BackupGroup * </pre> */ public class BackupGroup { private static final String NODE_NAME = "TOOLBOX"; private static final String PASSWORD = "PASSWORD"; private static final String LOW_LEVEL_NAME_MEMBER_ADDED = "/added_member"; private static final String DATA_MEMBER_ASSIGNED = "assigned member data"; private static final String LOW_LEVEL_NAME_MEMBER_ASSIGNED = "/assigned_member"; private static final String DATA_MEMBER_ADDED = "member data"; private static final String UNIQUE_TAG = "BackupGroup"; private static final String LOW_LEVEL_NAME_LEADER = "/leader"; private static final String HIGH_LEVEL_NAME = "/GROUP"; private static final String FILESPACE_NAME = "/BACKUPFS"; public static void main(final String args[]) throws ToolboxException, IOException { ITSMSession session = null; try { // Initializing a single-threaded environment Toolbox.initSingleThreading(); // Connecting to the server with the default connection options session = Toolbox.createSession(NODE_NAME, PASSWORD); // Registering the filespace IFilespace filespace = session.retrieveFilespace(FILESPACE_NAME); // Checking if filespace exists if (filespace == null) { System.out.printf("Warning: '%s' does not exists.\n", FILESPACE_NAME); return; } // Creating the backup group leader IBackupGroupLeader leader = filespace.createBackupGroupLeader( HIGH_LEVEL_NAME, LOW_LEVEL_NAME_LEADER, ObjectType.FILE); // Opening the group leader.open(UNIQUE_TAG); IResultSet openGroups = null; IBackupGroupQuery backupGroupQuery = filespace.createBackupGroupQuery(); try{ // Querying all backup groups matching the specified criteria openGroups = backupGroupQuery .ownerMatchesAny() // Matches any owner .open() // Query for open groups .execute(); // Execute the query // Iterating over the returned result set while (openGroups.next()) { IBackupGroupLeader backupGroupLeader = (IBackupGroupLeader) openGroups.get(); printDetails(backupGroupLeader); } } catch (Exception e) { e.printStackTrace(); } finally{ // The result set must be closed. openGroups.close(); } // Creating a new member backup object IBackupObject memberToAssign = filespace.createBackupFile( HIGH_LEVEL_NAME, LOW_LEVEL_NAME_MEMBER_ASSIGNED); try { // Binding the management class memberToAssign.bindManagementClass(); } catch (ToolboxException e) { // Checking for backup copy group if (e.getReturnCode() == ToolboxErrorCodes.TSM_EXCEPTION) { System.out.println(e.getCause().getMessage()); } return; } // Setting object size memberToAssign.setEstimatedSize(DATA_MEMBER_ASSIGNED.length()); InputStream in = new ByteArrayInputStream(DATA_MEMBER_ASSIGNED.getBytes()); // Beginning a transaction session.beginTransaction(); try { // Sending the object to the server memberToAssign.send(in); session.commit(); } catch(ToolboxException e) { // Rolling back the current transaction session.rollback(); } List<IBackupObject> objectList = new ArrayList<IBackupObject>(); IBackupQuery backupQuery = null; IResultSet backups = null; backupQuery = filespace.createBackupQuery(); try{ // Querying all backup objects matching the specified criteria backups = backupQuery .highLevelNameMatches(HIGH_LEVEL_NAME) .lowLevelNameMatches(LOW_LEVEL_NAME_MEMBER_ASSIGNED) .ownerMatchesAny() // Matches any owner name .files() // Query for files .allVersions() // Query for both active and inactive versions .execute(); // Execute the query // Iterating over the returned result set while (backups.next()) { objectList.add((IBackupObject) backups.get()); } }catch (Exception e) { e.printStackTrace(); }finally{ // The result set must be closed. backups.close(); } // Assigning the list of backups to the backup group leader.assign(objectList); // Creating a new backup object IBackupObject memberToAdd = filespace.createBackupFile( HIGH_LEVEL_NAME, LOW_LEVEL_NAME_MEMBER_ADDED); try { // Binding the management class memberToAdd.bindManagementClass(); } catch (ToolboxException e) { // Checking for backup copy group if (e.getReturnCode() == ToolboxErrorCodes.TSM_EXCEPTION) { System.out.println(e.getCause().getMessage()); } return; } // Setting object size memberToAdd.setEstimatedSize(DATA_MEMBER_ADDED.length()); in = new ByteArrayInputStream(DATA_MEMBER_ADDED.getBytes()); // Beginning to add new members to the backup group session.beginTransaction(); try { // Sending the object to the server memberToAdd.send(in); leader.endAddMembers(); } catch(ToolboxException e) { // Rolling back the current transaction leader.cancelAddMembers(); } // Querying all members IResultSet members = leader.queryMembers(ObjectType.ANY_TYPE); // Iterating over the returned result set while (members.next()) { IBackupObject backupObject = (IBackupObject) members.get(); printDetails(backupObject); } members.close(); // Closing the backup group leader.close(UNIQUE_TAG); IResultSet closedGroups = null; backupGroupQuery = filespace.createBackupGroupQuery(); try { // Querying all backup groups matching the specified criteria closedGroups = backupGroupQuery .ownerMatchesAny() // Matches any owner .closed() // Query for closed groups .execute(); // Execute the query // Iterating over the returned result set while (closedGroups.next()) { IBackupGroupLeader backupGroupLeader = (IBackupGroupLeader) closedGroups.get(); printDetails(backupGroupLeader); } } catch (Exception e) { e.printStackTrace(); }finally{ // THe result set must be closed. closedGroups.close(); } } catch (ToolboxException e) { e.printStackTrace(); } finally { // Disconnecting session.disconnect(); // Cleaning up the environment Toolbox.cleanUp(); } } /** * Prints the details of the backup group leader. */ private static void printDetails(IBackupGroupLeader o){ DsUint160_t restOrder = o.getRestoreOrderExt(); System.out.printf(" Backup group name: %s%s%s\n", o.getFilespaceName(), o.getHighLevelName(), o.getLowLevelName()); System.out.printf(" Object type: %s\n", o.getType()); System.out.printf(" Object state: %s\n", o.getState()); System.out.printf(" Is open: %s\n", o.isOpenGroup()); System.out.printf(" Insert date: %s\n", o.getInsertionDate()); System.out.printf(" Expiration date: %s\n", o.getExpirationDate()); System.out.printf(" Owner: %s\n", o.getOwner()); System.out.printf(" Restore order: %d-%d-%d-%d-%d\n", restOrder.getTop(), restOrder.getHi_hi(), restOrder.getHi_lo(), restOrder.getLo_hi(), restOrder.getLo_lo()); System.out.printf(" Object ID: %d\n", o.getId()); System.out.printf(" Copy group: %d\n", o.getCopyGroup()); System.out.printf(" Media class: %s\n", o.getMediaClass()); System.out.printf(" Management class: %s\n", o.getManagementClass().getName()); System.out.printf(" Object information: %s\n", o.getInformation()); System.out.printf("Estimated size (byte): %d\n", o.getEstimatedSize()); System.out.printf(" Compression: %s\n", o.getCompressionType()); System.out.printf(" Encryption: %s\n", o.getEncryptionType()); System.out.printf(" Client deduplicated: %s\n", o.isClientDeduplicated() ? "YES" : "NO"); System.out.println(); } /** * Prints the details of the backup object. */ private static void printDetails(IBackupObject o){ DsUint160_t restOrder = o.getRestoreOrderExt(); System.out.printf(" Name: %s%s%s\n", o.getFilespaceName(), o.getHighLevelName(), o.getLowLevelName()); System.out.printf(" Object type: %s\n", o.getType()); System.out.printf(" Object state: %s\n", o.getState()); System.out.printf(" Insert date: %s\n", o.getInsertionDate()); System.out.printf(" Expiration date: %s\n", o.getExpirationDate()); System.out.printf(" Owner: %s\n", o.getOwner()); System.out.printf(" Restore order: %d-%d-%d-%d-%d\n", restOrder.getTop(), restOrder.getHi_hi(), restOrder.getHi_lo(), restOrder.getLo_hi(), restOrder.getLo_lo()); System.out.printf(" Object ID: %d\n", o.getId()); System.out.printf(" Copy group: %d\n", o.getCopyGroup()); System.out.printf(" Media class: %s\n", o.getMediaClass()); System.out.printf(" Management class: %s\n", o.getManagementClass().getName()); System.out.printf(" Object information: %s\n", o.getInformation()); System.out.printf("Estimated size (byte): %d\n", o.getEstimatedSize()); System.out.printf(" Compression: %s\n", o.getCompressionType()); System.out.printf(" Encryption: %s\n", o.getEncryptionType()); System.out.printf(" Client deduplicated: %s\n", o.isClientDeduplicated() ? "YES" : "NO"); System.out.println(); } }