Correct steps and code for DB2 backup and cross-platform migration

Source: Internet
Author: User

The following articles mainly describe the correct steps for DB2 backup and cross-platform migration. If you are curious about the correct steps for DB2 backup and cross-platform migration, the following articles will unveil its secrets. The following is a detailed description of the article. I hope you can learn from it.

Database, backup, DB2, cross-platform migration, migration

First, set the archive parameters.

Java code

 
 
  1. 1. db2 update db cfg for using implements logpath/home/db2inst1/mirror_log // mirror log
  2. 2. db2 get db cfg for // check whether it is successful
  3. 3. db2 update db cfg for using userexit on // Enable User exit
  4. 4. db2 update db cfg for using logretain on // enable archiving logs
  5. 5. db2 update db cfg for using trackmod on // enable the Incremental backup function
  6. 6. db2stop force
  7. 7. db2start
  8. 8. db2 backup db to/home/db2inst1/off_back //
  9. Db2 update db cfg for using implements logpath/home/db2inst1/mirror_log // mirror log
  10. Db2 get db cfg for // check whether the operation is successful
  11. Db2 update db cfg for using userexit on // Enable User exit
  12. Db2 update db cfg for using logretain on // enable archiving logs
  13. Db2 update db cfg for using trackmod on // enable the Incremental backup function
  14. Db2stop force
  15. Db2start
  16. Db2 backup db to/home/db2inst1/off_back //

DB2 Online Database Backup

Java code

 
 
  1. 1. db2 backup db online to/home/db2inst1/on_back // online backup
  2. 2. db2 backup db online incremental to/home/db2inst1/on_back // online incremental backup
  3. 3. db2 list history backup all for // view backup records
  4. 4. db2 get db cfg for // view the location of the log and cp to a secure directory for rollforward.
  5. 5. db2stop force; db2start; db2 drop db // manually drop the database to simulate disaster recovery
  6. Db2 backup db online to/home/db2inst1/on_back // online backup
  7. Db2 backup db online incremental to/home/db2inst1/on_back // perform incremental backup online
  8. Db2 list history backup all for // view backup records
  9. Db2 get db cfg for // view the location of the log, cp to a secure directory for rollforward use.
  10. Db2stop force; db2start; db2 drop db // manually drop the database to simulate disaster recovery

Restore online database

Db2 code

 
 
  1. 1. db2ckrst-d-t 20070608032820-r database // The help tool prompts recovery.
  2. 2. db2 restore db incremental from/home/db2inst1/on_back taken at 20070608032820 // restore the data file
  3. 3. Restore the full backup first, and then restore the Incremental backup. You cannot automatically find the full backup file.
  4. 4. db2 rollforward database to end of logs and complete overflow log path '(/home/db2inst1/log)' // The rollback log does not agree with the following: "recover full backup first, and then restore the Incremental Backup"
  5. 5. For incremental recovery, your practice is reversed. If you do this, you will receive the SQL2574N error message.
  6. 6. The order of recovery has been clearly indicated in db2ckrst.
  7. 7. The following are the steps to test the log backup and recovery in the backup image:
  8. 8. Note:/home/db2inst1/on_back/# indicates the location of the backup file.
  9. 9./home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# Is the Database log location, which is obtained through db2 get db cfg.
  10. 10. db2stop force; db2start; db2 drop db # simulate a disaster and drop the database.
  11. 11. db2 backup db online to/home/db2inst1/on_back/include logs # Back up image files with logs
  12. 12. db2 backup db online incremental to/home/db2inst1/on_back/include logs # Back up incremental image files with logs
  13. 13. db2 RESTORE db incremental automatic FROM/home/db2inst1/on_back/taken at 20070612070526 LOGTARGET

    /Home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# restore Data images and log files with timestamps of 20070612070526
  14. 14. db2 rollforward database to end of logs and complete // roll back log
  15. 15. The database has been dropped in "10". How do I perform online backup in "20?
  16. 16. Note:/home/db2inst1/on_back/# indicates the location of the backup file.
  17. 17./home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# Is the Database log location, which is obtained through db2 get db cfg.
  18. 18. db2 backup db online to/home/db2inst1/on_back/include logs # Back up image files with logs
  19. 19. db2 backup db online incremental to/home/db2inst1/on_back/include logs # Back up incremental image files with logs
  20. 20. db2stop force; db2start; db2 drop db # simulate a disaster and drop the database.
  21. 21. db2 RESTORE db incremental automatic FROM/home/db2inst1/on_back/taken at 20070612070526 LOGTARGET

    /Home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# restore Data images and log files with timestamps of 20070612070526
  22. 22. db2 rollforward database to end of logs and complete // roll back log
  23. Db2ckrst-d-t 20070608032820-r database // The help tool prompts recovery.
  24. Db2 restore db incremental from/home/db2inst1/on_back taken at 20070608032820 // restore the data file
  25. Recover the full backup first, and then restore the Incremental backup. You cannot automatically find the full backup file.
  26. Db2 rollforward database to end of logs and complete overflow log path '(/home/db2inst1/log)' // The rollback log does not agree with the following: "recover full backup first, and then restore the Incremental Backup"
  27. For incremental recovery, your practice is reversed. If you do this, you will receive the SQL2574N error message.
  28. In db2ckrst, we have clearly indicated the order of recovery.
  29. The following are the steps to test the backup and recovery of logs in the backup image:
  30. Note:/home/db2inst1/on_back/# indicates the location of the backup file.
  31. /Home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# Is the Database log location, which is obtained through db2 get db cfg.
  32. Db2stop force; db2start; db2 drop db # simulate a disaster and drop the database.
  33. Db2 backup db online to/home/db2inst1/on_back/include logs # Back up image files with logs
  34. Db2 backup db online incremental to/home/db2inst1/on_back/include logs # Back up incremental image files with logs
  35. Db2 RESTORE db incremental automatic FROM/home/db2inst1/on_back/taken at 20070612070526 LOGTARGET

    /Home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# restore Data images and log files with timestamps of 20070612070526
  36. Db2 rollforward database to end of logs and complete // roll back log
  37. The database has been dropped in "10". How do I perform online backup in "20?
  38. Note:/home/db2inst1/on_back/# indicates the location of the backup file.
  39. /Home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# Is the Database log location, which is obtained through db2 get db cfg.
  40. Db2 backup db online to/home/db2inst1/on_back/include logs # Back up image files with logs
  41. Db2 backup db online incremental to/home/db2inst1/on_back/include logs # Back up incremental image files with logs
  42. Db2stop force; db2start; db2 drop db # simulate a disaster and drop the database.
  43. Db2 RESTORE db incremental automatic FROM/home/db2inst1/on_back/taken at 20070612070526 LOGTARGET

    /Home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# restore Data images and log files with timestamps of 20070612070526
  44. Db2 rollforward database to end of logs and complete // roll back log

The above is the DB2 backup method

The following describes how to migrate DB2 data across platforms.

Source database AIX platform + DB2 target platform LINUX

First, export the warehouse structure from the source database.

Db2 code

 
 
  1. 1. db2look -d dbname -e -o db2look.sql  
  2. db2look -d dbname -e -o db2look.sql  

Then export the source database DB2 data

Db2 code

 
 
  1. 1. db2move dbname export –u user –p password  
  2. db2move dbname export –u user –p password  

Db2move. lst records all exported files and can be edited to determine which data tables to import.

Then, create a new DB2 database on the target linux host, import the structure and data,

Db2 code

 
 
  1. 1. db2 -tvf db2look.sql   
  2. 2. db2move dbname import  

The above content is an introduction to DB2 backup and cross-platform migration. I 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.