db2 rollforward的练习
db2 rollforward的练习
--rollforward的练习 --开启归档日志 db2 update db cfg using LOGARCHMETH1 DISK:/home/db2inst1/archlog1/ --备份数据库 db2 backup database mydb1 online to ~/backup/ compress /* Backup successful. The timestamp for this backup image is : 20120725232200 */ db2 connect to mydb1 db2 "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')" --记录时间戳 db2 "select current timestamp from sysibm.sysdummy1" /* 1 -------------------------- 2012-07-25-23.22.53.757978 1 record(s) selected. */ --插入后续数据 db2 "insert into tb1(name) values('b')" -- db2 connect reset --强制刷新归档日志,如果没有刷新的话无法通过归档日志来进行还原 db2 archive log for db mydb1 --还原完整备份 db2 restore database mydb1 from ~/backup/ taken at 20120725232200 --前滚到上面登记的时间戳,并完成前滚 db2 rollforward database mydb1 to 2012-07-25-23.22.53.757978 using local time and stop --请留意这里的Last committed transaction的时间会将原来的归档路径上的日志文件时间覆盖掉,导致这次还原后无法再次还原到该时间后的数据。 /* 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.000000 Local */ -- db2 connect to mydb1 --验证还原后的时间单是否正确。查看数据刚好是在a插入后的时间 db2 "select * from tb1" /* ID NAME ----------- -------------------------------------------------- 1 a 1 record(s) selected. */ --特别注意:如果还原了一次数据库后因为归档日志位置相同的原因会导致生成了该时间点新的归档日志,覆盖了最后事务提交时间。所以无法再重新还原并前滚到最后前滚时间(上面例子中的时间2012-07-25-23.22.45.000000 Local)之前,这个需要特别注意。所以建议可以将归档日志复制到其他位置后再进行还原操作