DB2 10.5 for Linux, UNIX, and Windows

Performing a snapshot backup with a script

Using a custom script allows you to perform snapshot backup operations to storage devices that are not supported by DB2® ACS

Before you begin

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

About this task

Snapshot backups allow you to use the functionality of your underlying storage system to instantly create a copy of all database data and transaction logs without any interruptions. With a custom script, you can specify various options for the snapshot backup operation as well as utilize a wide range of storage devices that do not provide a vendor library.

During online snapshot backups, the database manager temporarily suspends all write operations to disk before creating the snapshot. This ensures that no changes occur to the data during the few seconds when the snapshot is taken.

Procedure

To perform a snapshot backup:

  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. Optional: Create a protocol file repository. This directory will contain the protocol files for the snapshot. Ensure that the directory is readable and writable.

    If you do not create the repository, the protocol files will be written to the directory that contains your script.

  3. 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
    BACKUP DATABASE dbname ONLINE
    	USE SNAPSHOT SCRIPT path-to-script
    	OPTIONS 'path-to-repository additional options'
    ADMIN_CMD procedure
    CALL SYSPROC.ADMIN_CMD
       (backup database dbname online
    		use snapshot script path-to-script
    		options 'path-to-repository additional options')
    db2Backup API
    int sampleBackupFunction( char dbAlias[],
                              char user[],
                              char pswd[],
                              char workingPath[] )
    {
      db2MediaListStruct mediaListStruct = { 0 };
    
      mediaListStruct.locations = &workingPath;
      mediaListStruct.numLocations = 1;   
      mediaListStruct.locationType = SQLU_SNAPSHOT_SCRIPT_MEDIA;
         
      db2BackupStruct backupStruct = { 0 };    
    
      backupStruct.piDBAlias = dbAlias;   
      backupStruct.piUsername = user;   
      backupStruct.piPassword = pswd;   
      backupStruct.piVendorOptions = NULL;   
      backupStruct.piMediaList = &mediaListStruct;    
      db2Backup(db2Version1050, &backupStruct, &sqlca);    
    
      return 0; 
    }

Results

The snapshot operation generates a snapshot backup image and a protocol file. Ensure that you keep the protocol file so it can be used for subsequent restore, query, delete operations.