Integration Toolbox
for IBM® TIVOLI® Storage Manager

package query; import static hu.user.toolbox.tsm.ITSMSession.MAXDATE; 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.exception.ToolboxException; import hu.user.toolbox.tsm.internal.structures.DsUint160_t; import hu.user.toolbox.tsm.query.IBackupQuery; /** * <b>Function:</b><br> * Queries backup objects. Detailed information of every object is printed. * <p> * Before executing this program send some objects to the server using * the BackupSingleObject, BackupSingleObjectManagementClassOverride or * BackupMultipleObjects 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 with the name from command line arguments.</li> * <li>Querying backup objects with the parameters: * high-level name "/BACKUP", low-level name "/* and object type "ANY_TYPE".</li> * <li>Iterating through the returned ResultSet, printing the details of * each match, then closing the result set.</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 query/QueryBackupObjects.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 query.QueryBackupObjects {filespace-name} * </pre> */ public class QueryBackupObjects { private static final String NODE_NAME = "TOOLBOX"; private static final String PASSWORD = "PASSWORD"; private static final String LOW_LEVEL_NAME_ANY = "/*"; private static final String HIGH_LEVEL_NAME = "/BACKUP"; public static void main(final String args[]) throws ToolboxException { ITSMSession session = null; String filespaceName = null; if(args.length<1){ System.out.println("Usage: java QueryBackupObjects {filespace name}."); return; }else{ filespaceName = args[0]; } 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(filespaceName); if (filespace == null) { System.out.printf("Warning: %s does not exists.\n", filespaceName); return; } IResultSet backups = null; IBackupQuery backupQuery = filespace.createBackupQuery(); boolean hasObjects = false; try{ // Querying all backup objects matching the specified criteria backups = backupQuery .highLevelNameMatches(HIGH_LEVEL_NAME) .lowLevelNameMatches(LOW_LEVEL_NAME_ANY) .ownerMatchesAny() // Matches any owner name .pitDate(MAXDATE) // Matches any date .filesAndDirectories() // Query for both files and directories .allVersions() // Query for both active and inactive versions .execute(); // Execute the query // Iterating over the returned result set while (backups.next()) { hasObjects = true; IBackupObject backupObject = (IBackupObject) backups.get(); printDetails(backupObject); } if (!hasObjects) { System.out.printf("The filespace '%s' does not contain any backup objects.\n", filespaceName); } } catch (Exception e) { e.printStackTrace(); } finally{ // The result set must be closed. backups.close(); } } catch (ToolboxException e) { e.printStackTrace(); } finally { // Disconnecting session.disconnect(); // Cleaning up the environment Toolbox.cleanUp(); } } /** * 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(); } }