包含当数据库的所有或部分必须恢复到给定时间点时,可用来确定恢复选项的备份信息的摘要
用来跟踪其他操作中与恢复相关的事件,如备份和复原操作
文件位于数据库目录中,文件名是DB2RHIST.ASC及其备份 DB2RHIST.BAK
要查看恢复历史记录文件中的条目,可使用 LIST HISTORY 命令
db2 list history since 20190108105338for sample
db2 list history backup containing userspace1 for sample
db2 list history dropped table all for db sample
db2 list history all for SAMPLE
db2_all "db2 list history since 20190108105338 for sample"
db2 list history since 20190108105338for database sample
A - Create table space
B - Backup
C - Load copy
D - Drop table
F - Rollforward
G - Reorganize
L - Load
N - Rename table space
O - Drop table space
Q - Quiesce
R - Restore
T - Alter table space
U - Unload
X - Archive log
D - Database
I - Index
P - Table space
T - Table
R - Partitioned table
Alter table space operation types:
— C - Add container
— R - Rebalance
Archive log operation types:
— F - Failover archive path
— M - Secondary (mirror) log path
— N - Archive log command
— P - Primary log path
— 1 - Primary log archive method
— 2 - Secondary log archive method
•Backup and restore operation types:
— D - Delta offline
— E - Delta online
— F - Offline
— I - Incremental offline
— M - Merged
— N - Online
— O - Incremental online
— R - Rebuild
— Z - Quiesce reset
备注:
增量备份:DB2备份自上一次数据库完整备份以来发生变化的所有数据。
delta备份:DB2备份自上一次成功执行的完整备份、增量备份或delta备份以来发生的变化的数据
切换到 db2instl(实例用户)用户:
su - db2instl
查看实例下有多少个数据库:
db2 list db directory
启动实例:
db2start
连接到 mydb 数据库中:
db2 connect to mydb
创建测试表:
db2 "create table mytest(id int)"
插入测试数据:
db2 "insert into mytest values(1)"
查看测试数据:
db2 "select * from mytest"
在线备份数据库:
db2 backup database mydb online
备份完需要重新连接数据库,不然报数据库没有链接上
插入并查看数据
查看备份信息
db2 list history all for mydb
恢复数据库
db2 restore database mydb taken at 20190109111850
恢复完数据库需要进行前滚,不然报(SQL1117N A connection to or activation of database “MYDB” cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019)
前滚数据库
db2 rollforward database mydb to end of backup and complete
连接数据库并检查测试数据:
db2 connect to mydb
db2 "select * from mytest"
完整代码
连接数据库:db2 connect to mydb
在线备份数据库:db2 backup database mydb online
重新连接数据库:db2 connect to mydb
在测试表中插入测试数据:db2 "insert into mytest values(2)"
检查测试数据:db2 "select * from mytest"
查看备份信息:db2 list history all for mydb
恢复数据库:db2 restore database mydb taken at 20190109111850
前滚数据库:db2 rollforward database mydb to end of backup and complete
连接数据库:db2 connect to mydb
检查测试数据: db2 "select * from mytest"
# 在测试表中插入测试数据:
db2 "insert into mytest values(2)"
# 在线备份数据库以及日志:
db2 backup database mydb online include logs
# 查看备份信息:
db2 list history all for mydb
# 恢复数据库:
db2 restore database mydb taken at 20190121093540
前滚数据库:
db2 rollforward database mydb to end of logs and complete
# 连接数据库:
db2 connect to mydb
# 检查测试数据:
db2 "select * from mytest"
备份表空间:
db2 "backup database mydb tablespace(userspace1) online to /home/db2instl/db_tablespace"
连接数据库:
db2 connect to mydb
查看表空间状态:
db2 list tablespaces
恢复某个表空间:
db2 "restore database mydb tablespace (USERSPACE1) online taken at 20190121101902"
查看表空间状态:
db2 list tablespaces
前滚表空间:
db2 "rollforward database mydb to end of logs and complete tablespace (USERSPACE1) "
连接数据库: db2 connect to mydb
查看表空间状态:db2 list tablespaces
对数据库进行在线的全备份:
— db2 backup database mydb online include logs
对数据库进行增量备份
— db2 backup database mydb online incremental include logs
检查数据库的备份信息
— db2 list history all for testdb
恢复数据库
—db2 restore database mydb incremental automatic taken at 20190121104112
前滚数据库:
—db2 rollforward database mydb to end of logs and complete
注:恢复完数据库后必须进行前滚数据库,不然报(SQL1117N A connection to or activation of database “MYDB” cannot be made because of ROLL-FORWARD PENDING. SQLSTATE=57019)