BACKUP DATABASE command
The BACKUP DATABASE command creates a backup copy of a database or a table space. A backup of your database and related stored data must be created to prevent data loss if a database service outage occurs.
For information about database backup operations between different operating systems and hardware
platforms, see Backup and restore operations between different operating systems and hardware
platforms
.
Scope
In a partitioned database environment, if no database partitions are specified, this command affects only the database partition on which it is run.
If the option to run a partitioned backup is specified, the command can be called only on the catalog database partition. 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 command.
Authorization
- SYSADM
- SYSCTRL
- SYSMAINT
Required connection
Command syntax
Command parameters
- DATABASE | DB database-alias
- Specifies the alias of the database to back up.
- USER username
- Identifies the username under which to back up the database.
- USING password
- The password that is used to authenticate the username. If the password is omitted, the user is prompted to enter it.
- ON
- Back up the database on a set of database partitions.
- DBPARTITIONNUM db-partition-number1
- Specifies a database partition number in the database partition list.
- DBPARTITIONNUMS db-partition-number1 TO db-partition-number2
- Specifies a range of database partition numbers so that all partitions from db-partition-number1 up to and including db-partition-number2 are included in the database partition list.
- ALL DBPARTITIONNUMS
- Specifies that the database is to be backed up on all partitions that are specified in the
db2nodes.cfg file.
- EXCEPT
- Specifies that the database is to be backed up on all partitions that are specified in the
db2nodes.cfg file, except for those partitions specified in the database
partition list.
- DBPARTITIONNUM db-partition-number1
- Specifies a database partition number in the database partition list.
- DBPARTITIONNUMS db-partition-number1 TO db-partition-number2
- Specifies a range of database partition numbers so that all partitions from db-partition-number1 up to and including db-partition-number2 are included in the database partition list.
- TABLESPACE tablespace-name
- A list of names that are used to specify the table spaces to be backed up.
- NO TABLESPACE
-
Specifies a backup that includes no table space user data. A backup image of this type includes database metadata. Additionally, active and extraction transaction log files for online images are included by default. Among the metadata that the backup image does contain is the database's recovery history file. This file can be restored by using the HISTORY FILE option of the RESTORE DATABASE command. To avoid including active and extraction transaction log files in an online image, use the EXCLUDE LOGS option of the BACKUP DATABASE command.
- ONLINE
-
Specifies online backup. The default is offline backup. Online backups are only available for databases that are configured with logarchmeth1 enabled. During an online backup, Db2® obtains IN (Intent None) locks on all tables that exist in SMS table spaces as they are processed. S (share locks) is no longer held on LOB data in SMS table spaces during online backup.
- INCREMENTAL
- Specifies a cumulative (incremental) backup image. An incremental backup image is a copy of all
database data that changed since the most recent successful, full backup operation.
- DELTA
- Specifies a noncumulative (delta) backup image. A delta backup image is a copy of all database data that changed since the most recent successful backup operation of any type.
- USE
-
- TSM
- Specifies that the backup is to use Tivoli® Storage Manager (TSM) as the target device.
- SNAPSHOT
- Specifies that a snapshot backup is to be taken. You cannot use the SNAPSHOT parameter with any of the following parameters:
- TABLESPACE
- INCREMENTAL
- WITH num-buffers BUFFERS
- BUFFER
- PARALLELISM
- COMPRESS
- UTIL_IMPACT_PRIORITY
- SESSIONS
The default behavior for a snapshot backup is a full database offline backup of all paths that make up the database. This backup includes 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).
Snapshot backup is supported when ENCRLIB is set in the following conditions: the database is encrypted. This setting ensures that the snapshot backup is itself encrypted. The configured encryption library is one of the native Db2 encryption libraries. This library can be the encryption library or one of the combined encryption and compression libraries. If you configured a non-IBM encryption library for backups, it is assumed that you want this setting to be used for all backups. Creating a snapshot backup by using native Db2 encryption violates this preference.
- LIBRARY library-name
- If you have storage hardware, and a Db2 ACS API driver for
that storage hardware, you can use the LIBRARY parameter to specify the
Db2
ACS API driver.
The value of the LIBRARY parameter is a fully qualified library file name.
- SCRIPT script-name
- The name of the executable script capable of running a snapshot backup operation. The script name must be a fully qualified file name.
- OPTIONS
-
- "options-string"
- Specifies options to be used for the backup operation. The string is passed exactly as it was entered, without the double quotation marks.
- @ file-name
- Specifies that the options to be used for the backup operation are contained in a file on the Db2 server. The string is passed to the vendor support library. The file must be a fully qualified file name.
You cannot use the vendoropt database configuration parameter to specify vendor-specific options for snapshot backup operations. You must use the OPTIONS parameter of the backup utilities instead.
- OPEN num-sessions SESSIONS
- The number of I/O sessions to create between the Db2 product and the TSM product or another backup vendor product. If you specify the INCLUDE LOGS parameter for an online backup, an extra session is created for the OPEN num-sessions SESSIONS parameter after the initial sessions are closed. If you are creating a Single System View (SSV) online backup, for each node that is backed up, an extra session is created for the OPEN num-sessions SESSIONS parameter after the initial sessions are closed. If you use this parameter with the TSM option, the number of entries that are created in the history file is equal to the number of sessions created.
- TO dir | pipename | dev | remote-storage
-
A list of paths, named pipes, devices, or remote storage locations to which the backup image is to be stored. Backing up to a named pipe is supported on only Unix and Linux platforms.
The full path to each target directory must be specified. If USE TSM, TO, and LOAD are omitted, the default target directory is the current working directory of the client computer. The target directories or devices must be locally addressable on the database server. If the target directory is on Network File System (NFS), the NFS needs to be configured with the nolock option (llock on AIX). Otherwise, the backup may hang.
To back up to remote storage, such as IBM® or Amazon Simple Storage Service (S3), specify a remote storage location by using a storage access alias. The syntax for specifying a remote storage location is
DB2REMOTE://<alias>/<container>/<object>
. For more information, see Remote storage requirements.In a partitioned database, the target directory or device must exist on all database partitions, and can be a shared path. The directory or device name can be specified by using a database partition expression. For more information about database partition expressions, see Using database partition expressions.
This parameter can be repeated to specify the target directories and devices that the backup image spans. If more than one target is specified (target1, target2, and target3, for example), target1 is opened first. The media header and special files (including the configuration file, table space table, and history file) are placed in target1. All remaining targets are opened, and are then used in parallel during the backup operation.
- LOAD library-name
- The name of the shared library (DLL on Windows operating systems) containing the vendor backup and restore I/O functions to be used. It can contain the full path. If the full path is not given, it defaults to the path where the user exit program is located.
- DEDUP_DEVICE
- Optimizes the format of the backup images for target storage devices that support data deduplication.
- WITH num-buffers BUFFERS
- The number of buffers to be used. If the number of buffers that you specify is not enough to create a successful backup, then the minimum value necessary to complete the backup is automatically chosen for this parameter. If you are backing up to multiple locations, you can specify a larger number of buffers to improve performance. If you specify the COMPRESS parameter, to help improve performance, you can add an extra buffer for each table space that you specify for the PARALLELISM parameter.
- BUFFER buffer-size
- The size, in 4 KB pages, of the buffer that is used to help build the backup image. Db2 automatically chooses an optimal value for this parameter unless you explicitly enter a value. The minimum value for this parameter is eight pages.
- PARALLELISM n
- Determines the number of table spaces that can be read in parallel by the backup utility. Db2 automatically chooses an optimal value for this parameter unless you explicitly enter a value.
- UTIL_IMPACT_PRIORITY priority
- Specifies that the backup runs in throttled mode, with the priority specified. Throttling provides a way for you to regulate the performance impact of the backup operation. Priority can be any number between 1 and 100, with 1 representing the lowest priority, and 100 representing the highest priority. If the UTIL_IMPACT_PRIORITY keyword is specified with no priority, the backup runs with the default priority of 50. If UTIL_IMPACT_PRIORITY is not specified, the backup runs in unthrottled mode. An impact policy must be defined by setting the util_impact_lim configuration parameter for a backup to run in throttled mode.
- COMPRESS|ENCRYPT
- Indicates that the backup is to be compressed or encrypted. You cannot specify both
parameters simultaneously. The COMPRESS and ENCRYPT
parameters are synonyms and can be used interchangeably only when either
COMPRLIB or ENCRLIB is specified too. If you specify
COMPRESS without COMPRLIB, the default compression library
libdb2compr.so is used for compression. If you specify
ENCRYPT without ENCRLIB, the default encryption library
libdb2encr.so is used for encryption. If you want to specify another library,
you can use COMPRESS and ENCRYPT interchangeably. You can
use either COMPRLIB or ENCRLIB to specify the
libdb2compr_encr.so,
libdb2zcompr_encr.so, or
libdb2nx842_encr.a library.Note: The libdb2zcompr_encr.so library is available in Db2 11.5.7 and later versions.If the encrlib database configuration parameter is set to a non-NULL value, then the COMPRLIB and ENCRLIB command options cannot be specified. If encrlib database configuration parameter is not set, a specified ENCROPTS command option is used rather than the encropts database configuration parameter. If the encrlib and encropts database configuration parameters are set to a non-NULL value, then the COMPROPTS and ENCROPTS command options can be specified on the command.Note: For databases that are natively encrypted, data is decrypted before backup. Encryption of the backup can be achieved by using this ENCRYPT parameter of the BACKUP DATABASE command. Encryption of the backup can also be achieved through the encrlib database configuration parameter. The backup is encrypted by using the algorithm that is employed by the specified encryption library, independent of any database native encryption configured cipher or algorithm.
- COMPRLIB|ENCRLIB name
- Indicates the name of the library that is used during the compression or encryption process. For example, db2compr.dll for Windows; libdb2compr.so for Linux® and UNIX operating systems. The name must be a fully qualified path that refers to a file on the server. If this parameter is not specified, the default Db2 compression library is used. If the specified library cannot be loaded, the backup operation fails.
- EXCLUDE
- Indicates that the library is not stored in the backup image.
- COMPROPTS|ENCROPTS string
- Describes a block of binary data that is passed to the initialization routine in the library.
The database manager passes this string directly from the client to the server. Any issues of byte
reversal or code page conversion are handled by the compression library. If the first character of
the data block is '@', the rest of the data is interpreted as the name of a file on the server. The
database manager then replaces the contents of the string with the contents of this file and passes
this new value to the initialization routine. The maximum length for string is
1024 bytes.For the default Db2 libraries libdb2compr_encr.so (compression and encryption), libdb2zcompr_encr.so (zlib-based compression and encryption), libdb2nx842_encr.a (NX842 compression and encryption) or libdb2encr.so (encryption only), the format of the ENCROPTS string is as follows:
Cipher=cipher-name:Mode=mode-name:Key Length=key-length: Master Key Label=label-name-1...:Master Key Label=label-name-n
- Cipher is optional. AES is the valid value (the default is AES).
- Mode is optional. The default is CBC.
- Key length is optional. Valid values for AES are 128, 192, and 256 (the default is 256).
- If the database is encrypted, master key label is optional. The default is the database master key label. If the database is not encrypted, master key label is mandatory.
Note: The libdb2zcompr_encr.so library is available in Db2 11.5.7 and later versions.If you are using other libraries, the format of the ENCROPTS string depends on those libraries.
- EXCLUDE LOGS
- Specifies that the backup image must not include any active or extraction log files. When you
run an offline backup operation, logs are excluded regardless of whether this option is specified,
except for snapshot backups. Logs are excluded by default in the following backup scenarios:
- Offline backup of a single-partitioned database.
- Online or offline backup of a multi-partitioned database, when not using a single system view backup.
- INCLUDE LOGS
- Specifies that the backup image must include the range of log files that are needed to restore
and roll forward this image to some consistent point in time.
In Db2 11.5.6 and later, if the database is configured for Advanced Log Space Management, Db2 selects the optimal combination of extraction and active log files to be included in the image. The success of this action depends on the availability of extraction log files at the time of the backup.
This option is not valid for an offline backup, except for snapshot backups. INCLUDE LOGS is always the default option for any online backup operation, except a multi-partitioned online backup where each database partition is backed up independently (a nonsingle system view backup).
If active log files that are needed for the backup are no longer in the log path, then the Db2 database manager retrieves them for backup from the set overflow log path. Files might be removed from the log path due to previously being archived.
If the overflow log path is not set, the database manager retrieves them for backup from the current log path or mirror log path. These log files are removed from the log path after the backup is complete.
- WITHOUT PROMPTING
-
Specifies that the backup runs unattended, and that any actions that normally require user intervention returns an error message.
Note:- If the backup command indicates which partitions in a partitioned database are to be backed up, the backup operation is implicitly run WITHOUT PROMPTING.
- Options that are specified on the BACKUP DATABASE command in a partitioned database environment are applied on each partition individually. For example, if a backup operation is specified to USE TSM OPEN 3 SESSIONS, Db2 opens three TSM sessions on each partition.
Examples
- The following example shows the command to run an offline backup of all the WSDB database
partitions to /dev3/backup, from database partition 0. The database WSDB is
defined on all four database partitions, numbered 0 - 3. The path /dev3/backup
is accessible from all database partitions. Database partition 0 is the catalog partition.
db2 BACKUP DATABASE wsdb ON ALL DBPARTITIONNUMS TO /dev3/backup
The backup runs simultaneously on all partitions. All four database partition backup images are stored in the /dev3/backup directory. This directory can be a shared directory that is accessible from more than one partition, or a locally mounted directory accessible from each partition individually, or a combination of both.
- You
can use a named pipe to back up one database directly into another without saving the intermediate
backup image.
The following example copies a source database (srcdb
) into the target database (tgtdb
). You can enter the BACKUP and RESTORE commands in either order.(in one session)
(in another session)$ db2 backup db srcdb to /<pipename>
$ db2 restore db srcdb from /<pipename> into tgtdb
- The following example shows the command to back up the database SAMPLE to a TSM server that uses
two concurrent TSM client sessions. Db2 calculates
the optimal buffer size for this environment.
db2 backup database sample use tsm open 2 sessions with 4 buffers
- The USE TSM OPTIONS keywords can be used to specify the TSM information to
use for the backup operation. The following example shows how to use the USE TSM
OPTIONS keywords to specify a fully qualified file name:
The file myoptions.txt contains the following information:db2 backup db sample use TSM options @/u/dmcinnis/myoptions.txt
-fromnode=bar -fromowner=dmcinnis
- The following example shows a sample weekly incremental backup strategy for a recoverable
database. It includes a weekly full database backup operation, a daily noncumulative (delta) backup
operation, and a midweek cumulative (incremental) backup operation:
(Sun) db2 backup db sample use tsm (Mon) db2 backup db sample online incremental delta use tsm (Tue) db2 backup db sample online incremental delta use tsm (Wed) db2 backup db sample online incremental use tsm (Thu) db2 backup db sample online incremental delta use tsm (Fri) db2 backup db sample online incremental delta use tsm (Sat) db2 backup db sample online incremental use tsm
- The following example shows three identical target directories that are specified for a backup
operation on database SAMPLE. This action is suitable if the target file system is made up of
multiple physical disks.
The data is concurrently backed up to the three target directories, and three backup images are generated with extensionsdb2 backup database sample to /dev3/backup, /dev3/backup, /dev3/backup
.001
,.002
, and.003
. - The following example shows the command that is used to run an online backup of table space
USERSPACE1 on database partitions 1 and 2 from partition 0, with the backup image to be stored on a
TSM server. The database WSDB is defined on all four database partitions, numbered 0 - 3. Database
partition 0 is the catalog partition:
db2 BACKUP DATABASE wsdb ON DBPARTITIONNUMS (1, 2) TABLESPACE (USERSPACE1) ONLINE USE TSM
- The following examples show sample output that is generated to indicate the
sqlcode
returned by each partition.- Example 1
- All partitions are successful (sqlcode >=
0)
$ db2 backup db foo on all dbpartitionnums tablespace(T1) Part Result ---- ------ 0000 DB20000I The BACKUP DATABASE command completed successfully. 0001 SQL2430W The database backup succeeded, but the following table spaces do not exist on this database partition: "T1". Backup successful. The timestamp for this backup image is : 20040908010203
- Example 2
- One or more partitions fail (sqlcode <
0)
$ db2 backup db foo on all dbpartitionnums to /backups Part Result ---- ------ 0000 SQL2001N The utility was interrupted. The output data may be incomplete. 0001 SQL2419N The target disk "/backups" has become full. SQL2429N The database backup failed. The following database partitions returned errors: "1".
- The following backups include the log directories in the image
created:
db2 backup db sample use snapshot
db2 backup db sample online use snapshot
db2 backup db sample use snapshot INCLUDE LOGS
db2 backup db sample online use snapshot INCLUDE LOGS
- The following backups do NOT include the log directories in the image
created:
db2 backup db sample use snapshot EXCLUDE LOGS
db2 backup db sample online use snapshot EXCLUDE LOGS
-
The following
command encrypts a backup image by using the default encryption
options:
BACKUP DATABASE ccards ENCRYPT;
- The following commands encrypt a backup image by using the default encryption
library and explicitly provided encryption options:-->
BACKUP DATABASE ccards ENCRYPT ENCRLIB 'libdb2encr.so' ENCROPTS 'Cipher=AES'; BACKUP DATABASE ccards ENCRYPT ENCRLIB 'libdb2encr.so' ENCROPTS 'Master Key Label=mylabel.mydb.myinstance.myserver';
-
The following command creates a backup image that is both compressed and encrypted:
BACKUP DATABASE ccards ENCRYPT ENCRLIB libdb2compr_encr.so;
Usage notes
- The data in a backup cannot be protected by the database server. Make sure that backups are properly safeguarded, particularly if the backup contains LBAC-protected data.
- The backup utility cannot be used with a Type 2 connection.
- Complement snapshot backups with regular disk backups, in case of failure in the filer and storage systems.
- Doing regular backups of your database can result in large database backup images, many database logs, and load copy images. An accumulation of these files takes up a large amount of disk space, but you can safely remove unneeded recovery files. For more information, see Managing recovery objects.
- You can use the OPTIONS parameter to enable backup
operations in TSM environments that support proxy nodes. For more information, see the
Configuring a Tivoli Storage Manager client
topic. - You can use the DB2_BCKP_PAGE_VERIFICATION registry variable to enable DMS and AS page validation during
the backup operation. The validation can identify many types of structural integrity
problems. Types of problems include page checksum validation failures of data, index, and XML
objects, and anomalies in the meta information of these pages. It is not possible to identify all
imaginable integrity problems. The following limitations exist:
- Whether the version of a data page reflects what Db2 last wrote to the table space container file on disk (that is, a lost I/O write) is not identified.
- Any logical discontinuity between data on a page and the objects that are correlated to the data, is not identified. These correlated objects include indexes, constraints, and MQTs.
- The version of a misplaced data page is not detected if it is located in a table space where a page with the same object ID is expected.
- The integrity of LOB or Long Field data pages is not validated.
- The integrity of empty (zeroed out) pages is not verified and is not reported as errors, even when the pages are expected to contain data.
- For SMS table spaces, integrity validation is limited to assuring page counts are correct per object. No further validation is run.
- You can use the DB2_BCKP_INCLUDE_LOGS_WARNING registry variable to specify that some online backups can now succeed even if they do not include all of the needed logs.
- After you issue a BACKUP DATABASE command with the ONLINE option and the INCLUDE LOGS option, the resulting backed-up database image includes all the log files necessary to roll forward to the end of backup.