Integration Toolbox
for IBM® TIVOLI® Storage Manager

package archive_retrieve; import hu.user.toolbox.tsm.IArchiveObject; import hu.user.toolbox.tsm.IArchiveObjectList; 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.query.IArchiveQuery; import java.io.FileOutputStream; import java.io.IOException; /** * <b>Function:</b><br> * Retrieves part of the archived object data that was previously * sent to the server using the ArchiveSingleObject.java example. * <p> * Before executing this program send an object to the server using * the ArchiveSingleObject 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 "/ARCHIVEFS".</li> * <li>Querying archive objects with the parameters: * high-level name "/ARCHIVE", low-level name "/OBJECT1 and object type "FILE".</li> * <li>Iterating through the returned ResultSet, adding each object * to the retrieve list, then closing the result set.</li> * <li>Setting the offset and the length of the the first object "/OBJECT1" * then retrieving to the folder "results".</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 * archive_retrieve/PartialRetrieveSingleObject.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 archive_retrieve.PartialRetrieveSingleObject * </pre> */ public class PartialRetrieveSingleObject { private static final String NODE_NAME = "TOOLBOX"; private static final String PASSWORD = "PASSWORD"; private static final String OUTPUT_FILE_NAME = "results/partialRetrieved.txt"; private static final String LOW_LEVEL_NAME = "/OBJECT1"; private static final String HIGH_LEVEL_NAME = "/ARCHIVE"; private static final String FILESPACE_NAME = "/ARCHIVEFS"; public static void main(final String args[]) throws IOException, ToolboxException { 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); // Retrieving the existing filespace from server 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; } IArchiveObjectList archiveList = session.createArchiveObjectList(); IResultSet archives = null; IArchiveObject currentObject = null; IArchiveQuery archiveQuery = filespace.createArchiveQuery(); try { // Querying all archive objects of the filespace matching the specified criteria archives = archiveQuery .highLevelNameMatches(HIGH_LEVEL_NAME) .lowLevelNameMatches(LOW_LEVEL_NAME) .ownerMatchesAny() // Matches any owner name .descriptionMatchesAny() // Matches any description .files() // Object type = File .execute(); // Execute the query // Iterating over the returned result set while (archives.next()) { currentObject = (IArchiveObject) archives.get(); break; } } catch (Exception e) { e.printStackTrace(); }finally{ // The result set must be closed. archives.close(); } // Check if object has been archived. if (currentObject == null) { System.out.printf("The object '%s%s%s' doesn't exist on the server.\n", FILESPACE_NAME, HIGH_LEVEL_NAME, LOW_LEVEL_NAME); return; } // Restoring 84 bytes beginning at offset 0 currentObject.setPartialOffset(0); currentObject.setPartialLength(84); // Starting the retrieve operation archiveList.add(currentObject); archiveList.beginPartialRetrieve(); FileOutputStream out = new FileOutputStream(OUTPUT_FILE_NAME); // Doing the actual retrieve try { currentObject.retrieve(out); System.out.printf("The object '%s%s%s' has been retrieved to file '%s'.\n", FILESPACE_NAME, HIGH_LEVEL_NAME, LOW_LEVEL_NAME, OUTPUT_FILE_NAME); } catch (Exception e) { e.printStackTrace(); } finally{ // The retrieve operation in each case must be finished archiveList.endRetrieve(); } } catch (ToolboxException e) { e.printStackTrace(); } finally { // Disconnecting session.disconnect(); // Cleaning up the environment Toolbox.cleanUp(); } } }