The following articles mainly describe how to back up and restore the DB2 database, including setting archiving parameters, online database backup, and offline database recovery, I hope you will have a better understanding of it.
Database
Step 1. Set archiving parameters:
1. db2 update db cfg for using implements logpath/home/db2inst1/mirror_log // mirror log
2. db2 get db cfg for // check whether it is successful
3. db2 update db cfg for using userexit on // Enable User exit
4. db2 update db cfg for using logretain on // enable archiving logs
5. db2 update db cfg for using trackmod on // enable the Incremental backup function
6. db2stop force
7. db2start
8. After db2 backup db to/home/db2inst1/off_back // starts the preceding parameter, the database is in the backup pending state and requires offline backup of the database. Otherwise, the SQL1116N error is prompted.
Step 2. Back up the online database
9. db2 backup db online to/home/db2inst1/on_back // online backup
10. db2 backup db online incremental to/home/db2inst1/on_back // perform incremental backup online
11. db2 list history backup all for // view backup records
12. db2 get db cfg for // view the location of the log, cp to a secure directory for rollforward use.
13. db2stop force; db2start; db2 drop db // manually drop the database to simulate disaster recovery
Step 3. Restore an online database
14. db2ckrst-d-t 20070608032820-r database // The help tool prompts recovery.
15. db2 restore db incremental from/home/db2inst1/on_back taken at 20070608032820 // restore the data file
Recover the full backup first, and then restore the Incremental backup. You cannot automatically find the full backup file.
16. db2 rollforward database to end of logs and complete overflow log path' (/home/db2inst1/log) '// roll back the log
I do not agree: "recover full backup first and then restore Incremental Backup"
For incremental recovery, your practice is reversed. If you do this, you will receive the SQL2574N error message.
In db2ckrst, we have clearly indicated the order of recovery.
The following are the steps to test the backup and recovery of logs in the backup image:
Note:/home/db2inst1/on_back/# indicates the location of the backup file.
/Home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# Is the Database log location, which is obtained through db2 get db cfg.
10. db2stop force; db2start; db2 drop db # simulate a disaster and drop the database.
20. db2 backup db online to/home/db2inst1/on_back/include logs # Back up image files with logs
21. db2 backup db online incremental to/home/db2inst1/on_back/include logs # Back up incremental image files with logs
30. db2 RESTORE db incremental automatic FROM/home/db2inst1/on_back/taken at 20070612070526 LOGTARGET/home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# RESTORE data with a timestamp of 20070612070526 images and log files
40. db2 rollforward database to end of logs and complete // roll back log
The database has been dropped in "10". How do I perform online backup in "20?
Note:/home/db2inst1/on_back/# indicates the location of the backup file/home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# indicates the location of the database log, you can use db2 get db cfg.
10. db2 backup db online to/home/db2inst1/on_back/include logs # Back up image files with logs
20. db2 backup db online incremental to/home/db2inst1/on_back/include logs # Back up incremental image files with logs
30. db2stop force; db2start; db2 drop db # simulate a disaster and drop the database.
40. db2 RESTORE db incremental automatic FROM/home/db2inst1/on_back/taken at 20070612070526 LOGTARGET/home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/# RESTORE data with a timestamp of 20070612070526 images and log files
50. db2 rollforward database to end of logs and complete // roll back the log. The above content is an introduction to the steps for backing up and restoring the DB2 database. I hope you will get some benefits.