db2 backup全备 + restore 笔记
【摘要】 备份db2 backup分为在线备份和离线备份,在线备份时需要打开logarchmeth1参数为非NO1.离线备份[db2inst3@CentOS6u8-123 backup]$ db2 backup database mydemo4 to <path>2.在线备份不包含日志[db2inst3@CentOS6u8-123 backup]$ db2 backup database mydemo...
备份
db2 backup分为在线备份和离线备份,在线备份时需要打开logarchmeth1参数为非NO
1.离线备份
[db2inst3@CentOS6u8-123 backup]$ db2 backup database mydemo4 to <path>
2.在线备份不包含日志
[db2inst3@CentOS6u8-123 backup]$ db2 backup database mydemo4 online to <path>
3.在线备份包含日志
[db2inst3@CentOS6u8-123 backup]$ db2 backup database mydemo4 online include logs to <path>
如果不加to参数,则备份到当前目录
检查备份文件
[db2it3@Ce backup]$ db2ckbkp -h SAMPLE.0.db2inst2.DBPART000.20170901170656.001
=====================
MEDIA HEADER REACHED:
=====================
Server Database Name -- SAMPLE
Server Database Alias -- SAMPLE
Client Database Alias -- SAMPLE
Timestamp -- 20170901170656
Database Partition Number -- 0
Instance -- db2inst2
Database Configuration Type -- 0 (Non-shared data)
Sequence Number -- 1
Database Member ID -- 0
Release ID -- 0x1000 (DB2 v10.5)
AL version -- V:10 R:5 M:0 F:5 I:0 SB:0
Database Seed -- 0x830C355A
DB Comment's Codepage (Volume) -- 0
DB Comment (Volume) --
DB Comment's Codepage (System) -- 0
DB Comment (System) --
Authentication Value -- 255 (Not specified)
Backup Mode -- 1 (Online)
Includes Logs -- 1 (Yes)
Compression -- 0 (No Library Applied)
Backup Type -- 0 (Database-level)
Backup Granularity -- 0 (Non-incremental)
Merged Backup Image -- 0 (No)
Status Flags -- 0x21
Consistent on this member
LOGARCHMETH1 is set
System Catalogs in this image -- 1 (Yes)
Catalog Partition Number -- 0
DB Codeset -- UTF-8
DB Territory -- US
LogID -- 1503821205
LogPath -- /home/db2inst2/db2inst2/NODE0000/SQL00001/LOGSTREAM0000/
Backup Buffer Size -- 2625536 (641 4K pages)
Number of Sessions -- 1
Platform -- 0x1E (Linux-x86-64)
Encrypt Info Flags -- 0x0
The proper image file name would be:
SAMPLE.0.db2inst2.DBPART000.20170901170656.001
[1] Buffers processed: #################################################################
Image Verification Complete - successful.
查看在线备份时产生的日志
在线备份时会将所有日志进行归档,然后产生一个新日志,备份完成产生另外一个日志,有可能是相同的文件,分别被参数Earliest Log Current Log记录,离线备份始终是相同的一个文件,异地恢复时需要将这两个文件一起复制到异地,进行前滚rollforward, 存放的目录可以在归档日志目录和活动日志目录下查找,可通过恢复历史文件查看这两个日志参数
[db2inst3@CentOS6u8-123 backup]$ db2 list history all for sample
Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
B D 20170901170656001 N D S0000010.LOG S0000010.LOG
----------------------------------------------------------------------------
Contains 5 tablespace(s):
00001 SYSCATSPACE
00002 USERSPACE1
00003 IBMDB2SAMPLEREL
00004 IBMDB2SAMPLEXML
00005 SYSTOOLSPACE
----------------------------------------------------------------------------
Comment: DB2 BACKUP SAMPLE ONLINE
Start Time: 20170901170656
End Time: 20170901170717
Status: A
----------------------------------------------------------------------------
EID: 79 Location: /home/db2inst2/backup
恢复
1.在线备份不p包含日志的异地恢复
复制备份文件和Earliest Log 、Current Log到服务器上
$db2 restore db 源库名from /tbmtest/DB2/db2back taken at 20111118160226.001 into 目标库名 redirect generate script newdb.clp
修改newdb.clp文件
去掉
ON '/export/home/db2inst'
SET STOGROUP PATHS FOR IBMSTOGROUP
ON '/home/db2inst3'
;
前面的--
执行i
[db2inst2@CentOS6u8-123 backup]$ db2 -tvf tbmuat.clp
此时数据库会置于前滚状态,需要把Earliest Log 、Current Log前滚。需要花费较长时间。
如果执行失败需要重新连接
[db2inst@scf 20180314db]$ db2 connnect reset
[db2inst@scf 20180314db]$ db2 terminate
如果把这两个日志复制到了目标库的活动日志目录下可以执行以下命令
$db2 rollforward database 目标库名 to end of logs and complete
如果把两个日志复制到了其他目录 可以执行以下命令,比上面命令多了overflow log path参数
[db2inst3@CentOS6u8-123 backup]$ db2 "rollforward database mydemo4 to end of logs and complete OVERFLOW LOG PATH (/home/db2inst3/backup/NODE0000/LOGSTREAM0000/)"
2.在线备份包含日志
复制备份文件到服务器上,不需要复制日志。
修改newdb.clp文件
额外打开
logtarget '<targetpath>'
前面的--, 然后指定目录,日志将被恢复到指定的目录,供后面rollforward使用
3.在线备份包含日志,只恢复日志
[db2inst3@CentOS6u8-123 backup]$ db2 restore database sample logs from /home/db2inst3/backup/ taken at 20170901170656 logtarget /home/db2inst3/backup/log/
根据日志恢复到当前时刻
进行版本恢复后,根据日志恢复到当前时刻,在目标数据库查看历史恢复文件最后恢复的一个文件。
恢复到归档日志末尾
恢复到活动日志末尾
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)