DB2数据库利用备份实现异机还原实例分析
一生产的DB2数据库需要将其数据全部备份,然后还原导入到一测试库中,中间遇到一些问题,最后还是圆满解决了,现将步骤记录下来方便学习和分析。
系统环境:AIX5.3
数据库: DB2 V9.1
两台服务器: 生产服务器 192.168.11.178
测试服务器 10.10.11.81
一、备份
分别备份一下生产服务器和测试服务器的数据库(两个服务器上数据库一样)
$ db2 backup db LAW online to /basefsnew/db2bak0111 include logs
备份成功。此备份映像的时间戳记是:20130111180236
$ db2 backup db LAW online to /basefsnew/db2bak0111 include logs
备份成功。此备份映像的时间戳记是:20130111180236
二、将生产库的备份传送到测试服务器
大家可以利用SCP命令或其他文件传输软件来传送备份,这里提醒一下传过来的备份需要改属主和属组还有权限,否则将导致还原时出错
三、具体还原过程和问题解决
$ db2 force applications all (先停止所有应用连接)
DB20000I The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately.
在测试服务器上开始还原
$ db2 restore db LAW from /home taken at 20130111180236
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.
还原成功
但随后连接数据库时报错
$ db2 connect to LAW
SQL1117N A connection to or activation of database "LAW" cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019
这个提示是说需要前滚期间的日志才能激活数据库
下面执行此句
$ db2 rollforward db LAW to end of logs and complete
SQL4970N Roll-forward recovery on database "LAW" cannot reach the specified
stop point (end-of-log or point-in-time) because of missing log file(s) on
node(s) "0".
提示缺失日志,不能到达结束点
注:比较顺利一次成功时,是这个状态
$db2 rollforward db LAW to end of logs and complete
Rollforward Status
Input database alias = db
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = -
Last committed transaction = 2013-1-11-10.59.23.000000
DB20000I The ROLLFORWARD command completed successfully.