13.4. Performing Database and Table Space BackupsThere are two different granularities that you can choose for your backups, and you have two different options for how the backup can be performed. You can choose to back up the entire database or one or more table spaces from within the database. You can also choose whether you want the backup to be taken online, meaning regular database access is permitted while the backup is taken, or offline, meaning that no database access is permitted while the backup is take. All four of these options can be combined to give you a very flexible recovery mechanism for your databases. 13.4.1. Online Access Versus Offline AccessIn the following sections we use the terms "online" and "offline" quite often. An online operation (backup, restore, or roll forward) allows other applications or processes to connect to the database, as well as read and modify data while the operation is running. An offline operation does not allow other applications or processes access to the database and its objects while the operation is being performed. 13.4.2. Database BackupA database backup is a complete copy of your database objects. Besides the data, a backup copy contains information about the table spaces, containers, the database configuration file, the log control file, and the recovery history file. Note that a backup does not store the Database Manager Configuration file or the values of registry variables. Only the database configuration file is backed up. You must have SYSADM, SYSCTRL, or SYSMAINT authority to perform a backup. The following is the syntax for the BACKUP DATABASE command:
If not specified, DB2 automatically chooses optimal values for the number of buffers, the buffer size, and the parallelism settings. The values will be based on the amount of utility heap memory available, the number of processors available, and the database configuration. The objective is to minimize the time it takes to complete a backup operation. There is no keyword OFFLINE in the syntax, as this is the default mode.
Since there are users accessing the database while it is being backed up, it is likely that some of the changes made by these users will not be stored in the backup. A transaction may be in the middle of processing when the backup was taken. This means the backup image contains a database in an inconsistent state. If this online backup is used to restore a database, as soon as the restore operation finishes, DB2 places the database in roll forward pending state. A roll forward operation must be performed to bring the database back to a consistent state before you can use it. If you have set LOGARCHMETH1 to USEREXIT, DISK, TSM, or VENDOR, DB2 automatically retrieves the logs into the active log directory. Otherwise, if LOGRETAIN was set, you must retrieve the log files manually before rolling forward the database. To perform the roll forward, all logs that were active at the time of the backup must be in the active log directory. NOTE Archival logging must be enabled to perform online backups.
For example, to take an online backup of the SAMPLE database along with the logs, using the destination directory /dev/rdir1, issue: BACKUP DATABASE sample ONLINE TO /dev/rdir1 INCLUDE LOGS 13.4.3. Table Space BackupIn a database where only some of your table spaces change considerably, you may opt not to back up the entire database but only specific table spaces. To perform a table space backup you can use the following syntax: BACKUP DATABASE sample TABLESPACE (syscatspace, userspace1, userspace2) ONLINE TO /db2tbsp/backup1, /db2tbsp/backup2 The keyword TABLESPACE indicates this is a table space backup, not a full database backup. You can also see from the example that you can include as many table spaces as desired in the backup. Temporary table spaces cannot be backed up using a table space-level backup. You will usually back up related table spaces together. For example, if using DMS table spaces where one table space is used for the table data, another one for the indexes, and another one for LOBs, you should back up all of these table spaces at the same time so that you have consistent information. This is also true for table spaces containing tables defined with referential constraints between them. 13.4.4. Incremental BackupsAs database sizes continue to expand, the time and hardware resources required to back up and recover these databases also grows substantially. Full database and table space backups are not always the best approach when dealing with large databases, because the storage requirements for multiple copies of such databases are enormous. To address this issue, DB2 provides incremental backup and recovery. An incremental backup is a backup image that contains only pages that have been updated since the previous backup was taken. In addition to updated data and index pages, each incremental backup image also contains all of the initial database metadata (such as database configuration, table space definitions, database history, and so on) that is normally stored in full backup images. There are two kinds of incremental backups.
Figure 13.4 illustrates these concepts. Figure 13.4. Incremental and delta backupsFor incremental backups, if there was a crash after the incremental backup on Friday, you would restore the first Sunday full backup, followed by the incremental backup taken on Friday. For delta backups, if there was a crash after the delta backup on Friday, you would restore the first Sunday full backup, followed by each of the delta backups taken from Monday until Friday inclusive. To enable incremental and delta backups, the TRACKMOD database parameter must be set to YES. This allows the database manager to track database modifications so that the backup database utility can detect which subsets of the database pages must be examined by an incremental backup and potentially included in the backup image. After setting this parameter to YES, you must take a full database backup to have a baseline against which incremental backups can be taken. For example, to perform a cumulative incremental backup on the SAMPLE database to destination directory /dev/rdir1, issue: BACKUP DB sample INCREMENTAL TO /dev/rdir1 To perform a delta backup on the SAMPLE database to destination directory /dev/rdir1, issue: BACKUP DB sample INCREMENTAL DELTA TO /dev/rdir1 13.4.5. Performing Backups with the Control CenterYou can use the Backup Wizard to perform backups. From the Control Center, expand your database folder, right-click on the database name you wish to back up and select Backup. The database Backup Wizard appears. Figure 13.5 shows that you can choose to perform either a database-level backup or a table space-level backup. From here, the Backup Wizard will guide you through backup command options. Figure 13.5. The Backup Wizard13.4.6. The Backup FilesThe backup images are stored as files. The name of a backup file contains the following parts:
The exact naming convention varies slightly by platform. In Figure 13.6, you can see that on Windows systems the file that actually contains the backup image is 131259.001. Figure 13.6. Backup file name hierarchyWhen DB2 backs up a database on Windows, it creates a hierarchy of directories. For example, the command BACKUP DATABASE sample to D:\temp produces the directories and backup image shown in Figure 13.7. Figure 13.7. Backup file hierarchy on WindowsWhen performing a restore, you specify the directory that was specified in the BACKUP DATABASE command, not the subdirectory where the backup image actually resides. On Linux and UNIX systems, DB2 does not create additional directories. The backup image can be found in the directory specified in the BACKUP DATABASE command, or the current directory where the command is issued. |