00001 SYSCATSPACE
00002 USERSPACE1
00003 SYSTOOLSPACE
----------------------------------------------------------------------------
Comment: DB2 BACKUP LEOTEST ONLINE
Start Time: 20130824233334
End Time: 20130824233527
Status: A
----------------------------------------------------------------------------
EID: 67 Location: /home/db2inst1/backup_data/online_bak
$ db2 restore db leotest logs logtarget /home/db2inst1/backup_data/online_bak
DB20000I The RESTORE DATABASE command completed successfully.
$ db2 list history backup since 20130824 for leotest
Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
B D 20130824233334001 N D S0000026.LOG S0000048.LOG
----------------------------------------------------------------------------
中的第一个日志和最后一个日志是完全一样的。
7.在数据库中插入一些数据:
$ db2 "select count(*) from test"
1
-----------
1921
1 record(s) selected.
$ db2 "select count(*) from test"
$ sh insert.sh
$ db2 "select count(*) from test"
1
-----------
1940
1 record(s) selected.
8.保留此备份,然后,将数据库的活动日志,归档日志,全部删除
活动日志:
$ cd /home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/
$ ls
S0000021.LOG S0000064.LOG S0000065.LOG S0000066.LOG
$ pwd
/home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR
$ mv * /home/db2inst1/backup_data/
$ ls -l
total 0
$
归档日志:
$ cd /home/db2inst1/archlog/
$ ls
db2inst1 db2inst1_old
$ mv db2inst1 db2inst1_old_2
$ ls
db2inst1_old db2inst1_old_2
$
9.使用刚才的备份进行数据库restore,同时,将log释放到活动日志目录下:
$ db2 restore db leotest logtarget /home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR
SQL2539W Warning! Restoring to an existing database that is the same as the
backup image database. The database files will be deleted.
Do you want to continue ? (y/n) y
10.restore完毕,进行查看日志并前滚
$ ls
S0000026.LOG S0000030.LOG S0000034.LOG S0000038.LOG S0000042.LOG S0000046.LOG
S0000027.LOG S0000031.LOG S0000035.LOG S0000039.LOG S0000043.LOG S0000047.LOG
S0000028.LOG S0000032.LOG S0000036.LOG S0000040.LOG S0000044.LOG S0000048.LOG
S0000029.LOG S0000033.LOG S0000037.LOG S0000041.LOG S0000045.LOG
$ pwd
/home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR
日志已经全部从备份中抽出并放到了活动日志目录中
开始前滚:
$ db2 rollforward db leotest query status
Rollforward Status
Input database alias = leotest
Number of nodes have returned status = 1
Node number = 0
Rollforward status = DB pending
Next log file to be read = S0000026.LOG
Log files processed = -
Last committed transaction = 2013-08-24-15.35.22.000000 UTC
$ db2 rollforward db leotest to end of logs and stop
Rollforward Status
Input database alias = leotest
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000026.LOG - S0000049.LOG
Last committed transaction = 2013-08-24-15.35.22.000000 UTC
DB20000I The ROLLFORWARD command completed successfully.
$ db2 rollforward db leotest query status
Rollforward Status
Input database alias = leotest
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000026.LOG - S0000049.LOG
Last committed transaction = 2013-08-24-15.35.22.000000 UTC
$ db2 connect to leotest
Database Connection Information
Database server = DB2/LINUXX8664 9.7.0
SQL authorization ID = DB2INST1
Local database alias = LEOTEST
前滚成功。
11.查看数据情况:
$ db2 "select count(*) from test"
1
-----------
1921
1 record(s) selected.
$
发现备份之后的操作,都没有了,这和我们的预期一样。
12.将备份之后的日志(活动和归档)拷回到活动日志目录,然后对数据库进行强制前滚到日志结尾:
$ cd backup_data/
$ ls
offline_bak online_bak S0000021.LOG S0000064.LOG S0000065.LOG S0000066.LOG
$ mv S* /home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR
$ cd /home/db2inst1/archlog/
$ ls
db2inst1 db2inst1_old db2inst1_old_2
$ cd db2inst1_old_2
$ ls
LEOTEST
$ cd LEOTEST/
$ ls
NODE0000
$ cd NODE0000/
$ ls
C0000004 C0000005
$ cd C0000004
$ ls
$ ls
$ cd ..
$ ls
C0000004 C0000005
$ cd C0000005
$ ls
S0000022.LOG S0000029.LOG S0000036.LOG S0000043.LOG S0000050.LOG S0000057.LOG S0000064.LOG
S0000023.LOG S0000030.LOG S0000037.LOG S0000044.LOG S0000051.LOG S0000058.LOG
S0000024.LOG S0000031.LOG S0000038.LOG S0000045.LOG S0000052.LOG S0000059.LOG
S0000025.LOG S0000032.LOG S0000039.LOG S0000046.LOG S0000053.LOG S0000060.LOG
S0000026.LOG S0000033.LOG S0000040.LOG S0000047.LOG S0000054.LOG S0000061.LOG
S0000027.LOG S0000034.LOG S0000041.LOG S0000048.LOG S0000055.LOG S0000062.LOG
S0000028.LOG S0000035.LOG S0000042.LOG S0000049.LOG S0000056.LOG S0000063.LOG
$ ls /home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR
S0000021.LOG S0000028.LOG S0000035.LOG S0000042.LOG S0000049.LOG S0000056.LOG S0000063.LOG
S0000022.LOG S0000029.LOG S0000036.LOG S0000043.LOG S0000050.LOG S0000057.LOG S0000064.LOG
S0000023.LOG S0000030.LOG S0000037.LOG S0000044.LOG S0000051.LOG S0000058.LOG S0000065.LOG
S0000024.LOG S0000031.LOG S0000038.LOG S0000045.LOG S0000052.LOG S0000059.LOG S0000066.LOG
S0000025.LOG S0000032.LOG S0000039.LOG S0000046.LOG S0000053.LOG S0000060.LOG
S0000026.LOG S0000033.LOG S0000040.LOG S0000047.LOG S0000054.LOG S0000061.LOG
S0000027.LOG S0000034.LOG S0000041.LOG S0000048.LOG S0000055.LOG S0000062.LOG
将数据块强制设置为rollforward pending,然后进行前滚