How to copy a DB2 database using a redirection recovery operation

Source: Internet
Author: User

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:

 
 
  1. set DB2INSTANCE=PROD 
  2. db2start  
  3. 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 ):

 
 
  1. 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.

 
 
  1. set DB2INSTANCE=MYINST 
  2. db2start  
  3. 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:

 
 
  1. db2 set tablespace containers for 0 using (path 'd:\ts0con1')  
  2. db2 set tablespace containers for 1 using (path 'd:\ts1con1')  
  3. 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:

 
 
  1. 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:

 
 
  1. db2 list db directory  
  2. db2 connect to movies  
  3. db2 list tablespace containers for 0  
  4. db2 list tablespace containers for 1  
  5. db2 list tablespace containers for 2  
  6. db2 connect reset  
  7. db2 terminate  
  8. db2stop  
  9. set DB2INSTANCE=PROD 
  10. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.