Understanding DB2: Learning Visually with Examples (2nd Edition)
13.5. Database and Table Space Recovery Using the RESTORE DATABASE Command
You can restore the backup image obtained by the BACKUP DATABASE command using the RESTORE DATABASE command. You can choose to recover the entire database or just the individual table space(s). 13.5.1. Database Recovery
You can restore a database backup image into a new or existing database. You need SYSADM, SYSCTRL, or SYSMAINT authority to restore into an existing database, and SYSADM or SYSCTRL authority restore to a new database. This syntax of the RESTORE command is: RESTORE DATABASE source-database_alias { restore_options | CONTINUE | ABORT } You can use one or more of the following for restore_options: [View full width] [USER username [USING password]] [{TABLESPACE [ONLINE] | TABLESPACE (tblspace-name [ {,tblspace-name} ... ]) [ONLINE] | HISTORY FILE [ONLINE] | COMPRESSION LIBRARY [ONLINE] | LOGS [ONLINE] }] [INCREMENTAL
To perform a restore of the sample database, use this syntax: RESTORE DATABASE sample (1)FROM C:\DBBACKUP (2) TAKEN AT 20040428131259 (3)WITHOUT ROLLING FORWARD (4)WITHOUT PROMPTING (5)
Note that there is no keyword OFFLINE in the syntax, as this is the default mode. In fact, for the RESTORE utility, this is the only mode allowed for databases.
For example, on Windows, to restore the SAMPLE database from a backup image residing in the C:\DBBACKUP directory and restore the log files to C:\DB2\NODE0000\SQL00001\SQLOGDIR directory, issue: RESTORE DATABASE sample FROM C:\DBBACKUP LOGTARGET C:\DB2\NODE0000\SQL00001\SQLOGDIR To restore just the logs, issue: RESTORE DATABASE sample LOGS FROM C:\DBBACKUP LOGTARGET C:\DB2\NODE0000\SQL00001\SQLOGDIR
13.5.2. Table Space Recovery
You can restore table spaces either from a full database backup or from a table space backup. Table space recovery requires some careful planning, as it is easy to make mistakes that can put your data into an inconsistent state. The following is an example of a table space restore: RESTORE DATABASE sample (1)TABLESPACE ( mytblspace1 ) (2) ONLINE (3)FROM /db2tbsp/backup1, /db2tbsp/backup2 (4) where:
13.5.3. Table Space Recovery Considerations
After a table space is restored, it is always placed in roll forward pending state. To make the table space accessible, the table space must be rolled forward to at least a minimum Point In Time. This minimum PIT ensures that the table space and logs are consistent with the system catalogs. For example:
A minimum PIT is updated when DDL statements are run against the table space or against tables in the table space. To determine the minimum PIT of recovery for a table space you can do either of the following:
In offline mode, the system catalog table space (SYSCATSPACE) must be rolled forward to the end of logs. We discuss more about the ROLLFORWARD command in the next section. 13.5.4. Performing RESTOREs with the Control Center
You can use the Restore Data Wizard to perform restores. In the Control Center, expand your database folder, right-click on the database name you want to restore, and select Restore. The Restore Data Wizard is launched. Figure 13.8 shows that you have the options to restore to an existing database, a new database, or only the history file. The Restore Data Wizard guides you through the restore command options. (We will discuss the history file in section 13.7, Recovering a Dropped Table.) Figure 13.8. The Restore Data Wizard
13.5.5. Redirected Restore
We mentioned earlier that a backup file includes information about the table spaces and containers. For example, let's say one of the table spaces, TS2, has a file container /database/ts2/cont1. This information is stored in the backup image. When you restore this backup image to a different server, DB2 will try to create exactly the same container. If the directory /database does not exist, DB2 will try to create it. But most likely this will fail because DB2 does not have the proper authority. In this case, a regular restore will not work. However, a redirected restore solves this problem. During a redirected restore, you can specify new paths for the table space containers, and data will be restored to the new containers. To change the container definitions during a redirected restore, you need to obtain the current container definitions on the source database. Use the LIST TABLESPACES command to list all the table spaces including their table space IDs, and then use the LIST TABLESPACE CONTAINERS FOR tablespace ID command to obtain the container definition for each table space. Once you have this information, you can proceed with the redirected restore operation. A redirected restore is performed in three steps:
You can also use redirected restore to add containers to SMS table spaces. As discussed in Chapter 7, Working with Database Objects, SMS table spaces cannot be altered to add a container. Redirected restore provides a workaround to this limitation by redefining the containers. |