DB2 rollforward exercises
-- Rollforward exercises -- Enable archiving logs DB2 Update Db cfg using logarchmeth1 Disk : / Home / Db2inst1 / Archlog1 / -- Back up database DB2 Backup Database Mydb1 online To ~ / Backup / Compress /* Backup successful. The timestamp for this backup image is: 20120725232200 */ DB2 connect To Mydb1db2" Create Table Tb1 (ID Integer Generated always As Identity (Start With 1 , Increment By 1 ), Name Varchar ( 50 ) "DB2" Insert Into Tb1 (name) Values ( ' A ' )" -- Record Timestamp DB2" Select Current Timestamp From Sysibm. sysdummy1" /* 1----------------------------2012-07-25-23.22.53.757978 1 record (s) selected. */ -- Insert subsequent data DB2" Insert Into Tb1 (name)Values ( ' B ' )" -- DB2 connect Reset -- Forcibly refresh archived logs. If not, archive logs cannot be restored. DB2 Archive Log For DB mydb1 -- Restore full backup DB2 Restore Database Mydb1 From ~ / Backup / Taken 20120725232200 -- Roll back to the timestamp registered above and complete the rollback DB2 rollforward Database Mydb1 To 2012 - 07 - 25 - 23.22 . 53.757978 Using local time And Stop -- Please note that the last committed transaction time here will overwrite the log file time in the original archive path, so that the restored data cannot be restored to the data after this time. /* Rollforward STATUS input database alias = mydb1 number of nodes have returned status = 1 node number = 0 rollforward status = dB working next log file to be read = s0000017.log log files processed = s0000016.log-s0000016.log last committed transaction = 2012-07-25-23.22.45.20.00 local */ -- DB2 connect To Mydb1 -- Verify that the restored time sheet is correct. View the data exactly after a is inserted DB2" Select * From Tb1" /* ID name ----------- -------------------------------------------------- 1 A 1 record (s) selected. */ -- Note: After a database is restored, a new archive log at this time point is generated because the location of the archived log is the same, which overwrites the commit time of the last transaction. Therefore, you must pay special attention to this issue before you can re-Restore and roll back to the last rollback time (the time in the preceding example is 2012-07-25-23.22.45.20.00 local. Therefore, we recommend that you copy the archived logs to other locations before restoring them.