DB2 Version 9.7 for Linux, UNIX, and Windows

Restoring from a snapshot backup image with a script

Using a custom script allows you to restore snapshot backup images taken using storage devices that are not supported by DB2® ACS.

About this task

A snapshot restore operation restores a snapshot backup. You have to use a custom script for that restore operation if your storage device does not provide a vendor library.

During snapshot restore operations, the protocol files written during the snapshot backup are read. As well, a new protocol file is written for the restore operation to show its progress. If the restore operation is successful, the protocol file is deleted; if the operation fails, you can use the protocol file to help investigate the cause of the failure.

A restore operation restores the latest image that matches the specified timestamp. For example, if there are two images for the timestamp 20121120--one taken at 201211201000 and one taken at 201211202000--the last one is chosen.

Restrictions

Before you begin

You must have one of the following authorities: SYSADM, SYSCTRL, or SYSMAINT.

Procedure

To perform a snapshot restore:

  1. Create a script that implements the DB2 ACS API. The script must be executable. For information on custom scripts, see DB2 Advanced Copy Services (ACS) user scripts.
  2. Initiate® the backup operation using either the BACKUP DATABASE command, the ADMIN_CMD procedure with BACKUP DB option, or the db2Backup API.
    BACKUP DATABASE command
    RESTORE DATABASE dbname 
    	USE SNAPSHOT SCRIPT path-to-script
    	OPTIONS 'path-to-repository'
     TAKEN AT timestamp LOGTARGET INCLUDE
    ADMIN_CMD procedure
    CALL SYSPROC.ADMIN_CMD
       (restore database dbname 
    	use snapshot script path-to-script
    	options 'path-to-repository'
     taken at timestamp logtarget include)
    db2Backup API
    int sampleRestoreFunction( char dbAlias[],
                               char restoredDbAlias[],
                               char user[],
                               char pswd[],
                               char workingPath[] )
    {
      db2MediaListStruct mediaListStruct = { 0 };
    
      rmediaListStruct.locations = &workingPath;
      rmediaListStruct.numLocations = 1;      
      rmediaListStruct.locationType = SQLU_SNAPSHOT_SCRIPT_MEDIA;
    
      db2RestoreStruct restoreStruct = { 0 };        
    
      restoreStruct.piSourceDBAlias = dbAlias;    
      restoreStruct.piTargetDBAlias = restoredDbAlias;
      restoreStruct.piMediaList = &mediaListStruct;
      restoreStruct.piUsername = user;
      restoreStruct.piPassword = pswd;  
      restoreStruct.iCallerAction = DB2RESTORE_STORDEF_NOINTERRUPT;
    
      struct sqlca sqlca = { 0 };
    
      db2Restore(db2Version1050, &restoreStruct, &sqlca);
    
      return 0;     
    }