1. 离线备份
(1) 备份
backup database mydb1 to '/db2/db2inst2/duanbb/backup'(2) 恢复
restore database mydb1 from '/db2/db2inst2/duanbb/backup'(3) 备份目录有多个备份版本,恢复指定的版本
[db2inst2@localhost backup]$ ls MYDB1.0.db2inst2.DBPART000.20150413143601.001 MYDB1.0.db2inst2.DBPART000.20150413144713.001
restore database mydb1 from '/db2/db2inst2/duanbb/backup' taken at 20150413144713
2. 在线备份
(1) 查看是否开启归档
db2 get db cfg for mydb2
下列两个条件,满足一个即为开启归档
(2) 启用归档日志
V9.5之前:
db2 update db cfg for mydb2 using LOGRETAIN ONV9.5之后
db2 update db cfg for mydb2 using LOGARCHMETH1 LOGRETAIN
db2 backup database mydb2 to '/db2/db2inst2/duanbb/backup'
db2 backup db mydb2 online to '/db2/db2inst2/duanbb/backup' include logs
db2 restore db mydb2 from /db2/db2inst2/duanbb/backup taken at 20150415134135 LOGTARGET /db2/db2inst2/duanbb/backup/log db2 rollforward db mydb2 to end of logs and stop overflow log path '(/db2/db2inst2/duanbb/backup/log)'
其它相关命令
1. 检查备份版本: db2ckbkp -h <备份文件>
2. 启用归档日志用户出口程序:
V9.5前: db2 update db cfg for <dbname> using userexit on
V9.5后: db2 update db cfg for <dbname> using LOGARCHMETH1 userexit
3. 启用增量备份
db2 update database configuration for <dbname> using trackmod yes
4. 获取备份历史信息
db2 list history backup all for database <dbname>
5. 有时离线备份总是报"The database is currently in use",重启数据库也不管用
可能是产生了死锁,通过如下命令解锁,然后再重启数据库备份
db2set DB2_RR_TO_RS=YES