视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
db2备份与恢复
2025-10-02 19:15:16 责编:小OO
文档
1.数据库级别的备份和恢复:

离线备份:

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下载本文

显示全文
专题