一、在DB2中查看数据库设置,如发现如下信息
则说明为非归档模式, 默认情况下为循环日志
二、设置DB2的归档
开启归档
db2 update db cfg for 数据库名 using userexit on
db2 update db cfg for 数据库名 using LOGRETAIN ON
设置归档日志路径
db2 update db cfg for 数据库名 using LOGARCHMETH1 "disk:/home/db2inst1/archive/数据库名_dblog"
然后停止数据库,再开启数据库进行冷备
$ db2 backup db 数据库名 to /home/db2inst1/backup
三、恢复
把备份和日志传输到其他服务器,注意属主和权限
然后开始还原
db2 restore db 数据库名 from /backup taken at 20140212190154 to /backup/log17
DB20000I The RESTORE DATABASE command completed successfully.
这是是不能连接数据库的,还需要前滚日志
$ db2 connect to 数据库名
SQL1117N A connection to or activation of database "数据库名" cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019
db2inst1@sqdb01:~> db2 rollforward db 数据库名 to end of logs and complete
Rollforward Status
Input database alias = 数据库名
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 = 2014-02-12-11.01.58.000000 UTC
DB20000I The ROLLFORWARD command completed successfully.
db2inst1@sqdb01:~> db2 connect to mblog
Database Connection Information
Database server = DB2/LINUXX8664 9.7.6
SQL authorization ID = DB2INST1
Local database alias = MBLOG
或者还有一种方式
切换到db2inst1用户
有原库的话删除原库
进入备份所在的目录
执行如下语句
db2 restore db mblog without rolling forward
(会恢复到/home/db2inst1)
恢复完,检查库是否可连,查看数据库目录和归档目录,如果空间有限的话,进行修改放到空间大的目录下。