DB2 Version 9.7 for Linux, UNIX, and Windows

Restoring from a snapshot backup image

Restoring from a snapshot backup uses the fast copying technology of a storage device to perform the data copying portion of the restore.

Before you begin

To perform snapshot backup and restore operations, you need a DB2® ACS API driver for your storage device. Integrated into IBM® Data Server is a DB2 ACS API driver for the following storage hardware:

You must perform a snapshot backup before you can restore from a snapshot backup. See: Performing a snapshot backup.

Procedure

You can restore from a snapshot backup using the RESTORE DATABASE command with the USE SNAPSHOT parameter, or the db2Restore API with the SQLU_SNAPSHOT_MEDIA media type:

RESTORE DATABASE command:

db2 restore db sample use snapshot

db2Restore 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_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(db2Version900, &restoreStruct, &sqlca);

  return 0;
}