DB2备份恢复流程

DB2备份恢复流程

数据库的归档日志设置和数据库前滚恢复

1.设置归档日志
可以有多种设置方法,具体参考InfoCenter
CMD:
login (user: db2inst1)
db2 connect to sample
db2 update db cfg using LOGARCHMETH1 logretain

2.设置成归档日志后的备份
设置成归档日志后的数据库处在备份暂挂(BACKUP PENDING)状态,需要进行备份
CMD: db2 connect to sample
SQL1116N A connection to or activation of database “SAMPLE” cannot be made
because of BACKUP PENDING. SQLSTATE=57019
CMD: db2 backup database sample to /mnt/hgfs/F/backup/
Backup successful. The timestamp for this backup image is : 20100624210336
备份后数据库恢复正常。

3.数据修改
CMD: db2 “insert into act values(999, ‘TEST’, ‘TESTDESC’)”
db2 “select * from act”
ACTNO ACTKWD ACTDESC
—— —— ——————–
10 MANAGE MANAGE/ADVISE
20 ECOST ESTIMATE COST
30 DEFINE DEFINE SPECS
40 LEADPR LEAD PROGRAM/DESIGN
50 SPECS WRITE SPECS
60 LOGIC DESCRIBE LOGIC
70 CODE CODE PROGRAMS
80 TEST TEST PROGRAMS
90 ADMQS ADM QUERY SYSTEM
100 TEACH TEACH CLASSES
110 COURSE DEVELOP COURSES
120 STAFF PERS AND STAFFING
130 OPERAT OPER COMPUTER SYS
140 MAINT MAINT SOFTWARE SYS
150 ADMSYS ADM OPERATING SYS
160 ADMDB ADM DATA BASES
170 ADMDC ADM DATA COMM
180 DOC DOCUMENT
999 TEST TESTDESC

4.误操作删除表空间
CMD:
cd /home/db2inst1/db2inst1/NODE0000/SAMPLE
mv * /mnt/hgfs/F/TS
ls
db2 connect reset
db2 connect to sample
SQL0293N Error accessing a table space container. SQLSTATE=57048

5.备份中恢复
db2 restore database sample from /mnt/hgfs/F/backup/
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
DB20000I The RESTORE DATABASE command completed successfully.
6.回复后数据库处于前滚暂挂(ROLL-FORWARD PENDING)状态
db2 connect to sample
SQL1117N A connection to or activation of database “SAMPLE” cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019

7.执行前滚恢复
CMD: db2 rollforward database sample to end of logs and stop
Rollforward Status

Input database alias = sample
Number of nodes have returned status = 1

Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000000.LOG – S0000000.LOG
Last committed transaction = 2010-06-25-04.28.39.000000 UTC

DB20000I The ROLLFORWARD command completed successfully.

8.数据确认
CMD:
db2 connect to sample
db2 “select * from act”
ACTNO ACTKWD ACTDESC
—— —— ——————–
10 MANAGE MANAGE/ADVISE
20 ECOST ESTIMATE COST
30 DEFINE DEFINE SPECS
40 LEADPR LEAD PROGRAM/DESIGN
50 SPECS WRITE SPECS
60 LOGIC DESCRIBE LOGIC
70 CODE CODE PROGRAMS
80 TEST TEST PROGRAMS
90 ADMQS ADM QUERY SYSTEM
100 TEACH TEACH CLASSES
110 COURSE DEVELOP COURSES
120 STAFF PERS AND STAFFING
130 OPERAT OPER COMPUTER SYS
140 MAINT MAINT SOFTWARE SYS
150 ADMSYS ADM OPERATING SYS
160 ADMDB ADM DATA BASES
170 ADMDC ADM DATA COMM
180 DOC DOCUMENT
999 TEST TESTDESC

备份后的数据变化被前滚恢复了。

转载自:http://blog.sina.com.cn/s/blog_68bd10c701014zou.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注