IBM Books

Command Reference

BACKUP DATABASE

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

Scope

This command only affects the node on which it is executed.

Authorization

One of the following:

Required Connection

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

Command Syntax

>>-BACKUP----+-DATABASE-+---database-alias---------------------->
             '-DB-------'
 
>-----+---------------------------------------+----------------->
      '-USER--username--+------------------+--'
                        '-USING--password--'
 
>-----+--------------------------------------------+------------>
      |                .-,------------------.      |
      |                V                    |      |
      '-TABLESPACE--(-----tablespace-name---+---)--'
 
>-----+---------+----------------------------------------------->
      '-ONLINE--'
 
>-----+-------------------------------------------------------+->
      +-USE ADSM--+-------------------------------+-----------+
      |           '-OPEN--num-sessions--SESSIONS--'           |
      |     .-,--------.                                      |
      |     V          |                                      |
      +-TO----+-dir-+--+--------------------------------------+
      |       '-dev-'                                         |
      '-LOAD--library-name--+-------------------------------+-'
                            '-OPEN--num-sessions--SESSIONS--'
 
>-----+-----------------------------+--------------------------->
      '-WITH--num-buffers--BUFFERS--'
 
>-----+----------------------+---+-----------------+------------>
      '-BUFFER--buffer-size--'   '-PARALLELISM--n--'
 
>----+-------------------+-------------------------------------><
     '-WITHOUT PROMPTING-'
 

Command Parameters

DATABASE database-alias
Specifies the alias of the database to back up.

USER username
Identifies the user name under which to back up the database.

USING password
The password used to authenticate the user name. If the password is omitted, the user is prompted to enter it.

TABLESPACE tablespace-name
A list of names used to specify the table spaces to be backed up.

ONLINE
Specifies online backup. The default is offline backup. Online backups are only available for databases configured with logretain or userexit enabled.
Note:An online backup operation may time out if there is an IX lock on sysibm.systables, because the DB2 backup utility requires an S lock on objects containing LOBs.

USE ADSM
Specifies that the backup is to use ADSM managed output.

OPEN num-sessions SESSIONS
The number of I/O sessions to be used with ADSM or another product.

TO dir/dev
A list of directory or tape device names. The full path on which the directory resides must be specified. The target must reside on the database server. This parameter may be repeated to specify the target directories and devices that the backup image will span. If more than one target is specified (target1, target2, and target3, for example), target1 will be 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.

Use of tape devices or floppy disks may generate messages and prompts for user input. Valid response options are:

c
Continue. Continue using the device that generated the warning message (for example, when a new tape has been mounted)

d
Device terminate. Stop using only the device that generated the warning message (for example, when there are no more tapes)

t
Terminate. Abort the backup or restore utility.

Tape is not supported on OS/2. On OS/2, 0 or 0: can be specified to cause the backup operation to call the user exit program (see the Administration Guide). This option is not valid on any other platform.

LOAD library-name
The name of the shared library (DLL on OS/2 or the Windows operating system) 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 will default to the path on which the user exit program resides.

WITH num-buffers BUFFERS
The number of buffers to be used.

BUFFER buffer-size
The size, in pages, of the buffer used when building the backup image. The minimum value for this parameter is 8 pages; the default value is 1024 pages. If a buffer size of zero is specified, the value of the database manager configuration parameter backbufsz must be set to 16.

To use tape devices, DB2 users on SCO UnixWare 7 must specify a buffer size of 16.

PARALLELISM n
Specifies the number of buffer manipulators to be spawned during the backup process. The default value is 1.

WITHOUT PROMPTING
Specifies that the backup will run unattended, and that any actions which normally require user intervention will return an error message.

Examples

   db2 backup database sample use adsm open 2 sessions with 4 buffers
 
   db2 backup database payroll tablespace syscatspace, userspace1 to
      /dev/rmt0, /dev/rmt1 with 8 buffers without prompting

Usage Notes

Database Level Backup
Note:Backup each database on a regular basis. If a database becomes damaged or corrupted, it can be returned to the state of the backed-up copy (see RESTORE DATABASE).

If a successfully restored database was enabled for roll-forward recovery at the time of the backup operation, it can be returned to the state it was in prior to the occurrence of damage (see ROLLFORWARD DATABASE).

The backup can be directed to fixed disk, diskette, tape, ADSM utility, or to other vendor products enabled for DB2.

On UNIX based systems, a backup file name consists of the concatenation of several units of information separated by periods:

dbname.type.instance.nodexxxx.catnxxxx.yyyymmddhhmmss.seq

dbname
1 to 8 character database alias.

type
Type of backup taken (0 for full database, or 3 for table space level backup).

instance
1 to 8 character database instance name.

nodexxxx
The number of the node. In non-partitioned database systems, this is always zero (NODE0000). In a partitioned database system, it is NODExxxx, where xxxx is the number assigned to the node in the db2nodes.cfg file.

catnxxxx
The number of the catalog node for the database. In non-partitioned database systems, this is always zero (CATN0000). In a partitioned database system, it is CATNxxxx, where xxxx is the number assigned to the node in the db2nodes.cfg file.

yyyymmdd
Date (year month day).

hhmmss
Time (hour minute second).

seq
A file extension consisting of a 3-digit sequence number.

In addition to fixed disk, tape, ADSM and other vendors, the backup may be directed to diskettes. Since there is no general tape support on OS/2 or the Windows operating system, each type of tape device requires a unique device driver.

To back up to the FAT file system on OS/2 or the Windows operating system, users must conform to the 8.3 naming restriction. The file is placed in a 5-level subdirectory tree as follows:

dbname.type\db2instance.nodexxx\catnxxx\yyyymmdd\hhmmss.seq

dbname
1 to 8 character database alias.

type
Type of backup taken. 0 for full database, 3 for table space level backup, 4 for copy from a table load.

db2instance
1 to 8 character database instance name.

nodexxx
The number of the node. In non-partitioned database systems, this is always zero (NODE000). In a partitioned database system, it is NODExxx, where xxx is the number assigned to the node in the db2nodes.cfg file.

catnxxx
The number of the catalog node for the database. In non-partitioned database systems, this is always zero (CATN000). In a partitioned database system, it is CATNxxx, where xxx is the number assigned to the node in the db2nodes.cfg file.

yyyymmdd
Date (year month day).

hhmmss
Time (hour minute second).

seq
A file extension consisting of a 3-digit sequence number.

Online backups are permitted only if roll-forward recovery is enabled. The utility can perform an online backup while it is being accessed and modified by other applications.

To perform an offline backup, the utility must be able to connect to the database in exclusive mode. BACKUP fails if any application, including the calling application, is already connected to the database. If the connection is successful, BACKUP locks out other applications until the backup is completed.

Execute BACKUP DATABASE offline when the database is not currently needed.

An offline backup operation will fail if the database is not in a consistent state. If the database is inconsistent, it must be restarted to be brought back to a consistent state through crash recovery before BACKUP is executed (see RESTART DATABASE, and a description of the autorestart configuration parameter in the Administration Guide). If the database is in a partially restored state after a system failure during restoration, the restore operation must be successfully rerun before a backup can be executed. If the database has been restored and a roll-forward operation is needed, the database must be rolled forward to a consistent state before it can be backed up.

If a database is changed from roll-forward disabled to roll-forward enabled state, either the logretain or the userexit database configuration options must be enabled before a backup of the database can be made (see GET DATABASE CONFIGURATION).

Table Space Level Backup

A table space level backup contains one or more table spaces for a database, specified when the command is executed. A table space level backup can be taken online or offline, but the database must be configured with roll-forward recovery enabled.

Table space level backup can be used to recover from problems that only affect specific table spaces. While this recovery is taking place, all other table spaces are available for processing.

To ensure that restored table spaces are synchronized with the rest of the database, the table spaces must be rolled forward to the end of the log (or to the point where the table spaces were last used). For this reason, table space level backup and restore can only be performed if roll-forward recovery is enabled. If roll-forward recovery is disabled at any time after a table space level backup is executed, it will not be possible to restore from the backup, and then to roll the table space forward to the current point in time. In this case, all table space level backups taken prior to that time are no longer restorable. The restore operation will fail if the user tries to restore from such a backup. In cases where it cannot be determined that the backup is not valid (if, for instance, the database has been restored and rolled forward, thus creating a new log sequence), the restore may be successful, and the broken restore set will be detected during roll-forward recovery.

The user may choose to separate data, index, long field (LONG), and large objects (LOB) into different table spaces. Long field and LOB data for the same table must reside in the same table space.

Each component of a table may be backed up and restored with the table space in which it resides, independently of the other components of the table.

It is not necessary to back up table spaces for temporary tables. If a list of table spaces to be backed up contains such a table space, BACKUP fails.

Table space level backup and restore cannot be run concurrently.

See Also

MIGRATE DATABASE

RESTORE DATABASE

ROLLFORWARD DATABASE.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]