Guidance:How to use the database recovery operation to use the database backup image to recreate the database. To clone a database from one machine to another, the simplest way is to restore the database from the backup image. The file system path used by the database is also included in the backup image. Therefore, the redirection recovery operation is required unless the file system and physical devices referenced by the database on the source system are set in the same way as those of the target system.
Tip: If DB2 V8 is available, you can obtain a backup from any high-priority server and restore it to any other high-priority server. For example, you can restore a backup image from DB2 for HP-UX to DB2 for AIX®Or Sun Solaris. However, this does not apply to Windows and Linux.
The redirection recovery operation involves two steps to recover the database, and there is a tablespace container definition step in the middle:
Issue the restore database command with the REDIRECT option.
Use the set tablespace containers command to define the TABLESPACE container of the recovered database DB2 needs to know where you want the TABLESPACE to reside on the target system ).
Issue the restore database command again, and specify the CONTINUE option this time.
The whole redirect recovery operation must be called in the same session; otherwise, SQL0900N will be returned, and the recovery operation will fail. Remember this is important. One way to avoid this is to create and run a script that contains all three parts of the Redirect recovery process.
The following Windows) example shows how to successfully perform the Redirect recovery operation. I will demonstrate how to restore a backup image from different instances, rather than from another server. The principle is the same, and the details are the same.
The source Instance name in this example is PROD. The name of the target instance is MYINST. The name of the existing database on PROD to be restored on MYINST is MOVIES. The MOVIES database is on the D disk.
Create a complete database backup image for the MOVIES database on PROD:
Set DB2INSTANCE = PROD
Db2start
Db2 backup db movies
The time stamp of this image is 20021006213640, and the image is in D: \ MOVIES.0 \ PROD \ NODE0000 \ CATN0000 \ 20021006. DB2 creates this subdirectory tree in the directory where the backup database command is issued. The subdirectory name indicates the following meanings:
\\\\
In this subdirectory tree, there will be a file 213640.0 indicating the actual backup image ). The file name indicates the time when the backup was obtained.
Create a similar path using MYINST instead of PROD ):
Md MOVIES.0 \ MYINST \ NODE0000 \ CATN0000/20021006
This is a key step:If this path is not correctly created, subsequent database recovery operations will fail. If you are re-locating the backup image to another machine, create the above path on the target machine and replace MYINST with the appropriate target Instance name). In this case, the backup image is 213640.0) copy to this directory. You can also use a compression tool to package backup images when maintaining the directory tree for transmission.
Start MYINST, and then call the first step of the redirection recovery operation.
Set DB2INSTANCE = MYINST
Db2start
Db2 restore db movies from d taken at 20021006213640 to d redirect
If the database restore command is called FROM a directory that never contains a backup image, the FROM parameter must be specified. The TO parameter specifies that the target database directory must be specified on a Windows operating system ).
Define a new tablespace container for the three default tablespace SYSCATSPACE, TEMPSPACE1, and USERSPACE1 related to the recovered database:
Db2 set tablespace containers for 0 using (path 'd: \ ts0con1 ')
Db2 set tablespace containers for 1 using (path 'd: \ ts1con1 ')
Db2 set tablespace containers for 2 using (path 'd: \ ts2con1 ')
You can use the list tablespaces show detail command to obtain information about all TABLESPACES in the source database. This will help you ensure that containers have been set for all TABLESPACES in the target database.
Complete the Redirect recovery operation:
Db2 restore db movies continue
Verify that a directory is correctly created for the recovered database and whether the tablespace container defined for it is actually related to the recovered database:
Db2 list db directory
Db2 connect to movies
Db2 list tablespace containers for 0
Db2 list tablespace containers for 1
Db2 list tablespace containers for 2
Db2 connect reset
Db2 terminate
Db2stop
Set DB2INSTANCE = PROD
Db2stop