Today, we will mainly tell you how to use the redirection recovery operation to copy the DB2 database. If you want to copy the database from one machine to another, the simplest method 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 the DB2 database 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
The above content is related to how to use the redirection recovery operation to copy the DB2 database? We hope you will have some gains.