至于如何开启归档日志,不在再次进行描述,只有开启归档日志,才能在线备份
1、数据库在线备份操作命令如下:
DB2 backup db 数据库名 online to 备份路径
例如:db2 backup db zhangsan online to /home/db2inst/db2backup
2、数据库拷贝到新服务器恢复操作命令如下:
Db2 restore db 旧数据库名 taken at 时间戳 into 恢复数据库名
例如:要把这个备份的数据库恢复到qingchen这个数据库ZHANGSAN.0.db2inst.DBPART000.20160619201225.001
db2 restore db ZHANGSAN taken at 20160619201225 into lisi
备注:还原数据库时如果数据库名相同可以把into lisi省略不写
3、如果执行恢复数据库命令时出现如下提示:
http://www.ibm.com/developerworks/cn/data/library/techarticle/dm-1011db2purescalefeature/
SQL1117N A connection to or activation of database "LISI" cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019
4、执行以下命令:
db2 rollforward db lisi to end of logs and complete
此命令根据根据日志logs前滚,新服务器没有日志文件,肯定就会报第五步的错
5、如果执行第4步,没有成功,出现以下提示:
SQL1273N An operation reading the logs on database "LISI" cannot continue
because of a missing log file "S0000020.LOG" on database partition "0" and log stream "0".
6、获取 db2数据库管理配置环境信息
db2 get db cfg for 数据库名
例如:db2 get db cfg for LISI
7、执行第6步出现如下信息:
Database Configuration for Database lisi
Database configuration release level = 0x0f00
……..........(其他内容省略)
Changed path to log files (NEWLOGPATH) =
Path to log files /home/db2inst/db2inst/NODE0000/SQL00001/LOGSTREAM0000/
Overflow log path (OVERFLOWLOGPATH) =
Mirror log path (MIRRORLOGPATH) =
First active log file = S0000020.LOG
Block log on disk full (BLK_LOG_DSK_FUL) = NO
………….. (其他内容省略)
8、找到S0000020.LOG (此日志文件根据查询出来的日志文件为准)这个日志文件,然后把此日志文件上传到需要恢复备份的数据库服务器所对应的
目录下,如
/home/db2inst/db2inst/NODE0000/SQL00001/LOGSTREAM0000/
最后再次执行以下命令即可完成本次数据库恢复操作
db2 rollforward db lisi to end of logs and complete