db2 开启归档日志在线备份

一、概述

db2数据库默认不开启归档日志
在线online备份的时候,就会报错
db2 backup db sample online to /home/db2inst1/
"SQL2413N Online backup is not allowed because the database is not recoverable or a backup pending condition is in effect."

翻译过来就是:要想做online backup,有2个步骤:
首先要enable “forward recovery” (通过配置 LOGARCHMETH1 或者 LOGARCHMETH2 );
然后再做一次offline backup;
如果1没做,就是 the database is not recoverable 。
如果2没做,就是 a backup pending condition is in effect

做offline backup的时候,所有东西都在backup文件里了,所以只需从backup文件做restore就行;
做online backup的时候,在backup的同时,DB本身还在工作,所以backup文件本身的信息并不全,其它信息(transaction log)只能从
log里取了。总结就是 backup + log才能完整的restore;
更进一步,我们也能理解为什么online backup一定要先设置 LOGARCHMETH1 (即archive log),因为Db2 默认是circular log,也就是
循环使用log,因此后面的log可能会覆盖前面的log,这样的话,Db2就认为DB处于不可恢复(not recoverable)的状态,这就是默认状态
下online backup报错的原因。

二、数据库开启归档日志

1、查看数据库是否开启归档日志
db2 get db cfg for sample |grep -i LOGARCHMETH
First log archive method (LOGARCHMETH1) = OFF
Options for logarchmeth1 (LOGARCHOPT1) =
Second log archive method (LOGARCHMETH2) = OFF
Options for logarchmeth2 (LOGARCHOPT2) =
2、创建归档路径,并开启归档
mkdir /home/db2inst1/arch
db2 update db cfg for sample using LOGARCHMETH1 'disk:/home/db2inst1/arch'
db2 get db cfg for sample |grep -i LOGARCHMETH1
First log archive method (LOGARCHMETH1) = DISK:/home/db2inst1/arch/
Options for logarchmeth1 (LOGARCHOPT1) =
相当于给DB设置了一个archive log目录。
使用的版本时9.7
并没有重启,就已经生成了路径
/home/db2inst1/arch/db2inst1/SAMPLE/NODE0000/C0000000
部分文档说归档日志必须重启db2才能生效,此处目的仅为online备份,不考虑重启
3、离线备份
db2 backup db sample to /home/db2inst1
4、在线备份
db2 backup db sample online to /home/db2inst1/
5、随手验证是否成功归档
[db2inst1@db01 ~]$ db2 terminate
DB20000I The TERMINATE command completed successfully.
[db2inst1@db01 ~]$ db2 archive log for db testdb1
DB20000I The ARCHIVE LOG command completed successfully.
##全程并没有重启db2
发表评论

相关文章