DB2 Version 9.7 for Linux, UNIX, and Windows

db2Backup API - Back up a database or table space

Creates a backup copy of a database or a table space.

Scope

In a partitioned database environment, by default this API affects only the database partition on which it is executed.

If the option to perform a partitioned backup is specified, the command can be called only on the catalog node. If the option specifies that all database partition servers are to be backed up, it affects all database partition servers that are listed in the db2nodes.cfg file. Otherwise, it affects the database partition servers that are specified on the API.

Authorization

One of the following:
  • sysadm
  • sysctrl
  • sysmaint

Required connection

Database. This API automatically establishes a connection to the specified database.

The connection will be terminated upon the completion of the backup.

API include file

db2ApiDf.h

API and data structure syntax

SQL_API_RC SQL_API_FN
  db2Backup (
       db2Uint32 versionNumber,
       void * pDB2BackupStruct,
       struct sqlca * pSqlca);

typedef SQL_STRUCTURE db2BackupStruct
{
  char *piDBAlias;
  char oApplicationId[SQLU_APPLID_LEN+1];
  char oTimestamp[SQLU_TIME_STAMP_LEN+1];
  struct db2TablespaceStruct *piTablespaceList;
  struct db2MediaListStruct *piMediaList;
  char *piUsername;
  char *piPassword;
  void *piVendorOptions;
  db2Uint32 iVendorOptionsSize;
  db2Uint32 oBackupSize;
  db2Uint32 iCallerAction;
  db2Uint32 iBufferSize;
  db2Uint32 iNumBuffers;
  db2Uint32 iParallelism;
  db2Uint32 iOptions;
  db2Uint32 iUtilImpactPriority;
  char *piComprLibrary;
  void *piComprOptions;
  db2Uint32 iComprOptionsSize;
  db2int32 iAllNodeFlag;
  db2int32 iNumNodes;
  db2NodeType *piNodeList;
  db2int32 iNumMPPOutputStructs;
  struct db2BackupMPPOutputStruct *poMPPOutputStruct;
} db2BackupStruct;

typedef SQL_STRUCTURE db2TablespaceStruct
{
  char                        **tablespaces;
  db2Uint32 numTablespaces;
} db2TablespaceStruct;

typedef SQL_STRUCTURE db2MediaListStruct
{
  char                        **locations;
  db2Uint32 numLocations;
  char locationType;
} db2MediaListStruct;

typedef SQL_STRUCTURE db2BackupMPPOutputStruct
{
  db2NodeType nodeNumber;
  db2Uint64 backupSize;
  struct sqlca 	sqlca;
} db2BackupMPPOutputStruct; 

SQL_API_RC SQL_API_FN
  db2gBackup (
       db2Uint32 versionNumber,
       void * pDB2gBackupStruct,
       struct sqlca * pSqlca);

typedef SQL_STRUCTURE db2gBackupStruct
{
  char *piDBAlias;
  db2Uint32 iDBAliasLen;
  char *poApplicationId;
  db2Uint32 iApplicationIdLen;
  char *poTimestamp;
  db2Uint32 iTimestampLen;
  struct db2gTablespaceStruct *piTablespaceList;
  struct db2gMediaListStruct *piMediaList;
  char *piUsername;
  db2Uint32 iUsernameLen;
  char *piPassword;
  db2Uint32 iPasswordLen;
  void *piVendorOptions;
  db2Uint32 iVendorOptionsSize;
  db2Uint32 oBackupSize;
  db2Uint32 iCallerAction;
  db2Uint32 iBufferSize;
  db2Uint32 iNumBuffers;
  db2Uint32 iParallelism;
  db2Uint32 iOptions;
  db2Uint32 iUtilImpactPriority;
  char *piComprLibrary;
  db2Uint32 iComprLibraryLen;
  void *piComprOptions;
  db2Uint32 iComprOptionsSize;
  db2int32 iAllNodeFlag;
  db2int32 iNumNodes;
  db2NodeType *piNodeList;
  db2int32 iNumMPPOutputStructs;
  struct db2gBackupMPPOutputStruct *poMPPOutputStruct;
} db2gBackupStruct;

typedef SQL_STRUCTURE db2gTablespaceStruct
{
  struct db2Char *tablespaces;
  db2Uint32 numTablespaces;
} db2gTablespaceStruct;

typedef SQL_STRUCTURE db2gMediaListStruct
{
  struct db2Char *locations;
  db2Uint32 numLocations;
  char locationType;
} db2gMediaListStruct;

typedef SQL_STRUCTURE db2gBackupMPPOutputStruct
{
  db2NodeType nodeNumber;
  db2Uint64 backupSize;
  struct sqlca  sqlca;
} db2gBackupMPPOutputStruct;

typedef SQL_STRUCTURE db2Char
{
   char *pioData;
   db2Uint32 iLength;
   db2Uint32 oLength;
} db2Char;

db2Backup API parameters

versionNumber
Input. Specifies the version and release level of the structure passed as the second parameter pDB2BackupStruct.
pDB2BackupStruct
Input. A pointer to the db2BackupStruct structure.
pSqlca
Output. A pointer to the sqlca structure.

db2BackupStruct data structure parameters

piDBAlias
Input. A string containing the database alias (as cataloged in the system database directory) of the database to back up.
oApplicationId
Output. The API will return a string identifying the agent servicing the application. Can be used to obtain information about the progress of the backup operation using the database monitor.
oTimestamp
Output. The API will return the time stamp of the backup image
piTablespaceList
Input. List of table spaces to be backed up. Required for table space level backup only. Must be NULL for a database level backup. See structure db2TablespaceStruct.
piMediaList
Input. This structure allows the caller to specify the destination for the backup operation. For more information, see the db2MediaListStruct structure below.
piUsername
Input. A string containing the user name to be used when attempting a connection. Can be NULL.
piPassword
Input. A string containing the password to be used with the user name. Can be NULL.
piVendorOptions
Input. Used to pass information from the application to the vendor functions. This data structure must be flat; that is, no level of indirection is supported. Note that byte-reversal is not done, and code page is not checked for this data.
iVendorOptionsSize
Input. The length of the piVendorOptions field, which cannot exceed 65535 bytes.
oBackupSize
Output. Size of the backup image (in MB).
iCallerAction
Input. Specifies action to be taken. Valid values (defined in db2ApiDf header file, located in the include directory) are:
DB2BACKUP_BACKUP
Start the backup.
DB2BACKUP_NOINTERRUPT
Start the backup. Specifies that the backup will run unattended, and that scenarios which normally require user intervention will either be attempted without first returning to the caller, or will generate an error. Use this caller action, for example, if it is known that all of the media required for the backup have been mounted, and utility prompts are not desired.
DB2BACKUP_CONTINUE
Continue the backup after the user has performed some action requested by the utility (mount a new tape, for example).
DB2BACKUP_TERMINATE
Terminate the backup after the user has failed to perform some action requested by the utility.
DB2BACKUP_DEVICE_TERMINATE
Remove a particular device from the list of devices used by backup. When a particular medium is full, backup will return a warning to the caller (while continuing to process using the remaining devices). Call backup again with this caller action to remove the device which generated the warning from the list of devices being used.
DB2BACKUP_PARM_CHK
Used to validate parameters without performing a backup. This option does not terminate the database connection after the call returns. After successful return of this call, it is expected that the user will issue a call with SQLUB_CONTINUE to proceed with the action.
DB2BACKUP_PARM_CHK_ONLY
Used to validate parameters without performing a backup. Before this call returns, the database connection established by this call is terminated, and no subsequent call is required.
iBufferSize
Input. Backup buffer size in 4 KB allocation units (pages). Minimum is 8 units.
iNumBuffers
Input. Specifies number of backup buffers to be used. Minimum is 2. Maximum is limited by memory.
iParallelism
Input. Degree of parallelism (number of buffer manipulators). Minimum is 1. Maximum is 1024.
iOptions
Input. A bitmap of backup properties. The options are to be combined using the bitwise OR operator to produce a value for iOptions. Valid values (defined in db2ApiDf header file, located in the include directory) are:
DB2BACKUP_OFFLINE
Offline gives an exclusive connection to the database.
DB2BACKUP_ONLINE
Online allows database access by other applications while the backup operation occurs.
Note: An online backup operation may appear to hang if users are holding locks on SMS LOB data.
DB2BACKUP_DB
Full database backup.
DB2BACKUP_TABLESPACE
Table space level backup. For a table space level backup, provide a list of table spaces in the piTablespaceList parameter.
DB2BACKUP_INCREMENTAL
Specifies a cumulative (incremental) backup image. An incremental backup image is a copy of all database data that has changed since the most recent successful, full backup operation.
DB2BACKUP_DELTA
Specifies a noncumulative (delta) backup image. A delta backup image is a copy of all database data that has changed since the most recent successful backup operation of any type.
DB2BACKUP_DEDUP_DEVICE
Optimizes the format of the backup image for target storage devices that support data deduplication. Available in Version 9.7 Fix Pack 3 and later fix packs.
DB2BACKUP_COMPRESS
Specifies that the backup should be compressed.
DB2BACKUP_INCLUDE_COMPR_LIB
Specifies that the library used for compressing the backup should be included in the backup image.
DB2BACKUP_EXCLUDE_COMPR_LIB
Specifies that the library used for compressing the backup should be not included in the backup image.
DB2BACKUP_INCLUDE_LOGS
Specifies that the backup image should also include the range of log files required to restore and roll forward this image to some consistent point in time. This option is not valid for an offline backup or a multi-partition backup.
DB2BACKUP_EXCLUDE_LOGS
Specifies that the backup image should not include any log files.
Note: When performing an offline backup operation, logs are excluded whether or not this option is specified, with the exception of snapshot backups where INCLUDE is the default.
DB2BACKUP_MPP
Perform backup in a manner suitable for a partitioned database.
iUtilImpactPriority
Input. Specifies the priority value to be used during a backup.
  • If this value is non-zero, the utility will run throttled. Otherwise, the utility will run unthrottled.
  • If there are multiple concurrent utilities running, this parameter is used to determine a relative priority between the throttled tasks. For example, consider two concurrent backups, one with priority 2 and another with priority 4. Both will be throttled, but the one with priority 4 will be allotted more resources. Setting priorities to 2 and 4 is no different than setting them to 5 and 10 or 30 and 60. Priorities values are purely relative.
piComprLibrary
Input. Indicates the name of the external library to be used to perform compression of the backup image. The name must be a fully-qualified path referring to a file on the server. If the value is a null pointer or a pointer to an empty string, DB2® will use the default library for compression. If the specified library is not found, the backup will fail.
piComprOptions
Input. Describes a block of binary data that will be passed to the initialization routine in the compression library. DB2 will pass this string directly from the client to the server, so any issues of byte-reversal or code-page conversion will have to be handled by the compression library. If the first character of the data block is '@', the remainder of the data will be interpreted by DB2 as the name of a file residing on the server. DB2 will then replace the contents of piComprOptions and iComprOptionsSize with the contents and size of this file respectively and will pass these new values to the initialization routine instead.
iComprOptionsSize
Input. A four-byte unsigned integer representing the size of the block of data passed as piComprOptions. iComprOptionsSize shall be zero if and only if piComprOptions is a null pointer.
iAllNodeFlag
Input. Partitioned database environments only. Indicates whether the backup operation is to be applied to all or some database partition servers defined in db2nodes.cfg. Valid values are:
DB2_NODE_LIST
Apply to database partition servers in a list that is passed in piNodeList.
DB2_ALL_NODES
Apply to all database partition servers. piNodeList should be NULL. This is the default value.
DB2_ALL_EXCEPT
Apply to all database partition servers except those in a list that is passed in piNodeList.
iNumNodes
Input. Specifies the number of database partition servers in the piNodeList array.
piNodeList
Input. A pointer to an array of database partition server numbers on which to perform the backup.
iNumMPPOutputStructs
Input. Specifies the number of elements in the piMPPOutputStruct array. This must be equal to or greater than the number of database partition servers that participate in this backup operation.
piMPPOutputStruct
Output. A pointer to an array of db2BackupMPPOutputStruct structures that specify output parameters for particular database partition servers.

db2TablespaceStruct data structure specific parameters

tablespaces
Input. A pointer to the list of table spaces to be backed up. For C, the list is null-terminated strings. In the generic case, it is a list of db2Char structures.
numTablespaces
Input. Number of entries in the tablespaces parameter.

db2MediaListStruct data structure parameters

locations
Input. A pointer to the list of media locations. For C, the list is null-terminated strings. In the generic case, it is a list of db2Char structures.
numLocations
Input. The number of entries in the locations parameter.
locationType
Input. A character indicating the media type. Valid values (defined in sqlutil header file, located in the include directory.) are:
SQLU_LOCAL_MEDIA: 'L'
Local devices (tapes, disks, diskettes, or named pipes).
SQLU_XBSA_MEDIA: 'X'
XBSA interface.
SQLU_TSM_MEDIA: 'A'
Tivoli® Storage Manager.
SQLU_OTHER_MEDIA: 'O'
Vendor library.
SQLU_SNAPSHOT_MEDIA: 'F'
Specifies that a snapshot backup is to be taken.
You cannot use SQLU_SNAPSHOT_MEDIA with any of the following:
  • DB2BACKUP_COMPRESS
  • DB2BACKUP_TABLESPACE
  • DB2BACKUP_INCREMENTAL
  • iNumBuffers
  • iBufferSize
  • iParallelism
  • piComprOptions
  • iUtilImpactPriority
  • numLocations field of this structure must be 1 for snapshot restore

The default behavior for a snapshot backup is a FULL DATABASE OFFLINE backup of all paths that make up the database including all containers, local volume directory, database path (DBPATH), and primary log and mirror log paths (INCLUDE LOGS is the default for all snapshot backups unless EXCLUDE LOGS is explicitly stated).

Only one snapshot can be run at a time and only database snapshot operations are permitted. When restoring on a different system that would depend on the access to the storage as long as the database paths are the same. You may use db2relocatedb afterwords to change the instance after the restore completes.

Integrated into IBM® Data Server is a DB2 ACS API driver for the following storage hardware:
  • IBM TotalStorage SAN Volume Controller
  • IBM Enterprise Storage Server® Model 800
  • IBM System Storage® DS6000™
  • IBM System Storage DS8000®
  • IBM System Storage N Series
  • IBM XIV®
  • NetApp V-series
  • NetApp FAS
SQLU_SNAPSHOT_SCRIPT_MEDIA: 'f'
Specifies that a scripted snapshot backup is to be taken.

db2BackupMPPOutputStruct and db2gBackupMPPOutputStruct data structure parameters

nodeNumber
The database partition server to which the option applies.
backupSize
The size of the backup on the specified database partition, in kilobytes.
sqlca
The sqlca from the specified database partition.

db2gBackupStruct data structure specific parameters

iDBAliasLen
Input. A 4-byte unsigned integer representing the length in bytes of the database alias.
iApplicationIdLen
Input. A 4-byte unsigned integer representing the length in bytes of the poApplicationId buffer. Should be equal to SQLU_APPLID_LEN+1 (defined in sqlutil.h).
iTimestampLen
Input. A 4-byte unsigned integer representing the length in bytes of the poTimestamp buffer. Should be equal to SQLU_TIME_STAMP_LEN+1 (defined in sqlutil.h).
iUsernameLen
Input. A 4-byte unsigned integer representing the length in bytes of the user name. Set to zero if no user name is provided.
iPasswordLen
Input. A 4-byte unsigned integer representing the length in bytes of the password. Set to zero if no password is provided.
iComprLibraryLen
Input. A four-byte unsigned integer representing the length in bytes of the name of the library specified in piComprLibrary. Set to zero if no library name is given.

db2Char data structure parameters

pioData
A pointer to a character data buffer. If NULL, no data will be returned.
iLength
Input. The size of the pioData buffer.
oLength
Output. The number of valid characters of data in the pioData buffer.

Usage notes

You can only perform a snapshot backup with versionNumber db2Version950 or higher. If you specify media type SQLU_SNAPSHOT_MEDIA with a versionNumber lower than db2Version950, DB2 database will return an error.

This function is exempt from all label-based access control (LBAC) rules. It backs up all data, even protected data. Also, the data in the backup itself is not protected by LBAC. Any user with the backup and a place in which to restore it can gain access to the data.

As you regularly backup your database, you might accumulate very large database backup images, many database logs and load copy images, all of which might be taking up a large amount of disk space. Refer to "Managing recovery objects" for information on how to manage these recovery objects.

Usage notes for a single system view (SSV) backup in a partitioned database environment
  • To perform an SSV backup, specify iOptions DB2BACKUP_MPP and one of DB2BACKUP_DB or DB2BACKUP_TABLESPACE.

  • You can only perform a SSV backup with versionNumber db2Version950 or higher. If you specify iOptions DB2BACKUP_MPP with a versionNumber lower than db2Version950, DB2 database will return an error. If you specify other options related to SSV backup with a versionNumber lower than db2Version950, DB2 database will ignore those options.

  • The values for piMediaList specified directly in db2BackupStruct will be used as the default values on all nodes.

  • The value of oBackupSize returned in the db2BackupStruct is the sum of the backup sizes on all nodes. The value of backupSize returned in the db2BackupMPPOutputStruct is the size of the backup on the specified database partition.

  • iAllNodeFlag, iNumNodes, and piNodeList operate the same as the similarly-named elements in db2RollforwardStruct, with the exception that there is no CAT_NODE_ONLY value for iAllNodeFlag.

  • SSV backups performed with the DB2BACKUP_BACKUP caller action are performed as if the DB2BACKUP_NOINTERRUPT caller action was specified.

  • *poMPPOutputStruct points to memory allocated by the caller that contains at least as many elements as there are database partitions participating in the backup.