DB2在线备份恢复:
1.查看数据库:
[
db2inst1@localhost ~]$ db2 list db directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = PAYMENT2
Database name = PAYMENT2
Local database directory = /home/db2inst1
Database release level = f.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = SAMPLE
Database name = SAMPLE
Local database directory = /home/db2inst1
Database release level = f.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
2.删除数据库:(模拟灾难)
[db2inst1@localhost ~]$ db2 drop db payment2
DB20000I The DROP DATABASE command completed successfully.
[db2inst1@localhost ~]$ db2 list db directory
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = SAMPLE
Database name = SAMPLE
Local database directory = /home/db2inst1
Database release level = f.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
3.
找到备份的数据
[db2inst1@localhost ~]$ cd /home/db2inst1/payment2_bak
[db2inst1@localhost payment2_bak]$ ls
PAYMENT2.0.db2inst1.DBPART000.20130514083706.001 PAYMENT2.0.db2inst1.DBPART000.20130514090118.001
PAYMENT2.0.db2inst1.DBPART000.20130514085824.001
[db2inst1@localhost payment2_bak]$ ll
总用量 475104
-rw-------. 1 db2inst1 db2iadm1 161419264 5月 14 08:37 PAYMENT2.0.db2inst1.DBPART000.20130514083706.001
-rw-------. 1 db2inst1 db2iadm1 165355520 5月 14 08:58 PAYMENT2.0.db2inst1.DBPART000.20130514085824.001
-rw-------. 1 db2inst1 db2iadm1 159727616 5月 14 09:01 PAYMENT2.0.db2inst1.DBPART000.20130514090118.001
4.
备份恢复命令
[db2inst1@localhost payment2_bak]$ db2 restore database payment2 from /home/db2inst1/payment2_bak taken at 20130514085824
DB20000I The RESTORE DATABASE command completed successfully.
5.
查看数据库是否恢复:
[db2inst1@localhost payment2_bak]$ db2 list db directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = PAYMENT2
Database name = PAYMENT2
Local database directory = /home/db2inst1
Database release level = f.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = SAMPLE
Database name = SAMPLE
Local database directory = /home/db2inst1
Database release level = f.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
6.
尝试连接数据库:
由于是在归档模式下,数据库恢复后,处于 ROLL-FORWARD PENDING 状态,所以不能连接
[db2inst1@localhost payment2_bak]$ db2 connect to payment2
SQL1117N A connection to or activation of database "PAYMENT2" cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019
7.
前滚数据库,使之可用
[db2inst1@localhost ~]$ db2 "ROLLFORWARD DATABASE payment2 TO END OF LOGS AND COMPLETE OVERFLOW LOG PATH ("/home/db2inst1/payment2_archive_log/")"
Rollforward Status
Input database alias = payment2
Number of members have returned status = 1
Member ID = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000002.LOG - S0000003.LOG
Last committed transaction = 2013-05-14-01.01.28.000000 UTC
DB20000I The ROLLFORWARD command completed successfully.
[db2inst1@localhost ~]$ db2 connect to payment2
Database Connection Information
Database server = DB2/LINUX 10.1.2
SQL authorization ID = DB2INST1
Local database alias = PAYMENT2
[db2inst1@localhost ~]$ db2 list tables