离线备份:
db2 backup db sample to [路径名];
在线备份:
首先要指定关键字online ,其次数据库日志模式为归档模式
db2 backup db sample online to [路径名]
包含日志文件在内的在线备份:
db2 backup db sample online to [路径名] include logs
数据库恢复:
restore db sample from [路径名]
taken at 时间戳
without rolling forward --针对归档日志的数据库恢复的选项
包含日志文件在内的恢复:
restore db sample from [路径名]
logtarget [本机db2日志所在的文件夹路径]
taken at 时间戳
3.增量备份:
1)首先将数据库sample配置参数trackmod 设置为 on 方法为:
db2 update db cfg for sample using trackmod on
db2 get db cfg for sample | find /i "track" ---查找trackmod参数;
2)增量备份:
db2 backup db sample incremental to [路径名](多个路径名之间用逗号隔开)
3)差量备份
db2 backup db sample incremental delta to [路径名]
增量备份恢复:
过程繁琐,推荐使用自动增量恢复:
db2 restore db sample incremental automatic taken at (时间戳)
注:上述命令的时间戳是要恢复的最近的增量备份镜像时间戳。
2.表空间的备份
db2 backup db sample tablespaces(syscatspace, userspace1, userspace2)
to [路径名]
表空间的恢复:
db2 restore db sample tablespace (表空间名称)
from [路径]
对已删除的表进行恢复:
1.条件是表空间dropped table recovery 选项是开启的,db2 9
以后版本默认是开启的,可以通过alter tablespace 修改:
alter tablespace space_name dropped table recovery on
2.要恢复已删除的表,首先恢复数据库备份,然后执行rollforward操作
1)恢复数据库
restore db sample from 路径 taken at 时间戳 into sample
2)检索已丢弃表的对象ID
list history dropped table all for db sample
3) 向前恢复数据
rollforward database sample to end of logs and stop recover
dropped table table_ID to 文件路径
4).将3)中(文件路径)下的数据插入表中
import from 路径 of del insert into table_name
数据库前滚:
rollforward db sample to end of logs and complete
上述命令将前滚到日志最后,意味着所有归档日志和活动日志都要遍历
rollforward db sample to timestamp using local time and complete
上述命令将前滚到指定的时间戳
表空间前滚:
rollforward db sample to end of logs and complete
tablespace(userspace)
RECOVER应用程序:
recover就是restore+rollforward它支持恢复和前滚
例子:
recover db sample to end of logs ---恢复数据库并回滚到日志最后
recover db sample to 2008-05-21-13.20.00 using local time --将数据库恢复到指定的时
间
查看恢复历史记录文件命令:
db2 list history all for sample
重定向恢复:
1.db2 restore db db_name redirect
2.定义数据库表容器
set tablespace containers for 4 using (PATH 'G:/DB2Containner_2/YNDC/sys' );
3.db2 restore db_name continue下载本文