db2如何改归档与备份恢复
这篇文章主要介绍了db2如何改归档与备份恢复,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
一、在DB2中查看数据库设置,如发现如下信息
$db2 get db cfg for db_name |grep -i log
结果如下:
Log retain for recovery enabled ( LOGRETAIN) = OFF
User exit for logging enabled (USEREXIT) = OFF
HADR log write synchronization mode (HADR_SYNCMODE) = NEARSYNC
First log archive method (LOGARCHMETH1) = OFF
则说明为非归档模式, 默认情况下为循环日志
二、设置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)
恢复完,检查库是否可连,查看数据库目录和归档目录,如果空间有限的话,进行修改放到空间大的目录下。
感谢你能够认真阅读完这篇文章,希望小编分享的"db2如何改归档与备份恢复"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!