关于增量备份的主要参考<<DM_DBA>> p273。达梦的增量必须基于一个备份才可能生成。所以如果一个数据库还没进行去备份,而直接用“backup database increment with backupdir ...”去备份,会提示说找不到基备份。所以要做一次完整的增量备份测试,需要下面步骤:
1. 做一次完整的全库联机备份,并记下存放目录,作以后续增量备份的基备份和文件存放目录。
2. 做增量备份,并指定全库联机备份所在目录。并最好指定bakfile参数指向全库备份所在目录,以便作归档。如果没指定,会在默认目录,
即数据库所在目录生成默认文件(DB_<数据库名>_<时间点>.bak).这不利于整理。
另外一个要注意的是,每一次备份时,备份集名称都要变。 把备份集交给数据库管理员负责是达梦与其它库很不同的一个地方之一。
同时dm.ini也要记得备份,恢复时会用到。
同时还作了下面测试:
1. 正常的增量备份测试
2. 尝试将基备份全库备份文件移开,再去执行增量备份看看效果
3. 尝试仅保留基备份全库备份文件,将其它增量备份文件移开,再去执行增量备份看看效果
4. 正常的增量备份恢复测试
5. 在增量备份恢复前,先在备份集目录,删除基备份,再进行恢复看效果
测试版本: V7.1.2.215-Build(2013.11.08-36626trunc)
一。检查并设置数据库为归档模式
联机备份必须处在归档模式下,可用下面两条sql查看数据库当前状态
--查看归档是否打开 select arch_mode from v$database; --查看归档日志信息 select arch_name,arch_type,arch_dest from v$dm_arch_ini;如何设置归档可看:达梦(3)如何设置归档模式
二。创建测试数据
-- 创建表空间test_data(数据文件TEST_DATA01.DBF大小为50m) create tablespace test_data datafile ‘C:\dmdbms\data\DAMENG\TEST_DATA01.DBF‘ size 50; -- 增加用户 create user "TESTUSER" identified by "111111" default tablespace "TEST_DATA"; -- 授权 grant "DBA" to "TESTUSER"; -- 创建模式 create schema test_sch authorization testuser; -- 创建 表 create table test_sch.t2(id int primary key ,name varchar(20)) storage(on test_data); -- 插入数据 -- insert into test_sch.t2 values(1,‘aaa‘); insert into test_sch.t2 values(0,‘full‘); -- 检索数据 select * from test_sch.t2;三。备份数据库
基备份,必不可少,以后所有的增量都基于这个备份.
服务器[localhost:5236]:处于普通打开状态 登录使用时间: 6.205(毫秒) disql V7.1.2.215-Build(2013.11.08-36626trunc) Connected to: DM 7.1.2.215 SQL>select * from test_sch.t2; 行号 ID NAME ---------- ----------- ---- 1 0 full 已用时间: 0.266(毫秒). 执行号:67. SQL>backup database full to dmincord0full bakfile ‘C:\xcl\inc\dmincord0full.bak‘ backupinfo ‘作为增量的基备份的全库联机备份‘ maxsize 50 ; 操作已执行 已用时间: 00:00:02.041. 执行号:68. SQL>第一次增量备份:
SQL>insert into test_sch.t2 values(1,‘inc1‘); 影响行数 1 已用时间: 0.891(毫秒). 执行号:69. SQL>backup database increment with backupdir ‘C:\xcl\inc‘ to dmincord1 bakfile ‘C:\xcl\inc\dmincord1.bak‘ backupinfo ‘测试增量备份1‘ ; 操作已执行 已用时间: 00:00:01.774. 执行号:70. SQL>insert into test_sch.t2 values(2,‘inc2‘); 影响行数 1 已用时间: 0.442(毫秒). 执行号:71. SQL> select * from test_sch.t2; 行号 ID NAME ---------- ----------- ---- 1 0 full 2 1 inc1 3 2 inc2 已用时间: 0.516(毫秒). 执行号:72.第二次增量备份:
SQL>backup database increment with backupdir ‘C:\xcl\inc‘ to dmincord2 bakfile ‘C:\xcl\inc\dmincord2.bak‘ backupinfo ‘测试增量备份2‘ ; 操作已执行 已用时间: 00:00:01.756. 执行号:73. SQL>insert into test_sch.t2 values(3,‘inc3‘); 影响行数 1 已用时间: 0.862(毫秒). 执行号:74. SQL>select * from test_sch.t2; 行号 ID NAME ---------- ----------- ---- 1 0 full 2 1 inc1 3 2 inc2 4 3 inc3 已用时间: 0.411(毫秒). 执行号:75. SQL>第三次增量备份:
注意:
在执行备份前,将基备份全库备份文件移开,再去执行增量备份,发现会提示找不到基备份
SQL>backup database increment with backupdir ‘C:\xcl\inc‘ to dmincord3 bakfile ‘C:\xcl\inc\dmincord3.bak‘ backupinfo ‘测试增量备份3‘ ; backup database increment with backupdir ‘C:\xcl\inc‘ to dmincord3 bakfile ‘C:\xcl\inc\dmincord3.bak‘ backupinfo ‘测试增量备份3‘ ; [-8036]:无基备份. SQL>backup database increment with backupdir ‘C:\xcl\inc‘ to dmincord3 bakfile ‘C:\xcl\inc\dmincord3.bak‘ backupinfo ‘测试增量备份3‘ ; 操作已执行 已用时间: 00:00:02.162. 执行号:123. SQL> insert into test_sch.t2 values(4,‘inc4‘); 影响行数 1 已用时间: 0.761(毫秒). 执行号:126. SQL>select * from test_sch.t2; 行号 ID NAME ---------- ----------- ---- 1 0 full 2 1 inc1 3 2 inc2 4 3 inc3 5 4 inc4 已用时间: 0.229(毫秒). 执行号:127. SQL>第四次增量备份:
注意:
尝试仅保留基备份全库备份文件,将其它增量备份文件移开,再去执行增量备份看看效果:
发现只剩下基备份的情况下,新的增量还是可以执行成功。
SQL>backup database increment with backupdir ‘C:\xcl\inc‘ to dmincord4 bakfile ‘C:\xcl\inc\dmincord4.bak‘ backupinfo ‘测试增量备份4‘ ; 操作已执行 已用时间: 00:00:01.768. 执行号:130. SQL> SQL> insert into test_sch.t2 values(4,‘inc5‘); 影响行数 1 已用时间: 0.470(毫秒). 执行号:131. SQL> select * from test_sch.t2; 行号 ID NAME ---------- ----------- ---- 1 0 full 2 1 inc1 3 2 inc2 4 3 inc3 5 4 inc5 已用时间: 0.175(毫秒). 执行号:132.
如何查看备份?
在"DM管理工具" -> 备份 ->库备份 可以查看。
不过你会发现我上面测试的增量备份并没有出来。原因是要更改"指定工作目录"
DM才会列出指定目录下的备份文件。
四。删除数据库后进行恢复测试
1. 测试最后一次增量备份的恢复c:\dmdbms\bin>dminit.exe PATH=C:\dmdbms\data DB_NAME=DAMENG INSTANCE_NAME=DMSERVER initdb V7.1.2.215-Build(2013.11.08-36626trunc) db version: 0X70008 file dm.key not found, use default license! create dm database success. 2014-01-16 10:31:54 c:\dmdbms\bin>dmrestore ini_path=C:\xcl\inc\dm.ini file=C:\xcl\inc\dmincord4.bak restore V7.1.2.215-Build(2013.11.08-36626trunc) Global parameter value of HA_OTHER_INST_PORT is illegal, use max value! backup DMINCORD4 info: backup sig: BA backup tool version: 12595 backup db name: DAMENG backup db magic: 1389776595 backup name: DMINCORD4 backup type: increment backup level: online backup range: database backup description: 测试增量备份4 compressed level: 0 rac node: 0 page check: 0 length in char: 0 backup time: 2014-01-16 10:24:34 page size: 8 KB extent size: 16 case sensitive: 1 log page size: 512 B unicode flag: 0 data version: 0x70008 sys version: V7.1.2.215-Build(2013.11.08-36626trunc) enable policy: 0 parallel type: 0 parallel info len: 0 backup db fil num: 6 archive flag: 1 base backup LSN: 31266 base name: DMINCORD0FULL backup with log: Yes before backup LSN: 31369 after backup LSN: 31369 file_seq file_path size(KB) 1 C:\xcl\inc\dmincord4.bak 16384 file_seq file_path mirror_path 1 C:\dmdbms\data\DAMENG\SYSTEM.DBF 2 C:\dmdbms\data\DAMENG\ROLL.DBF 3 C:\dmdbms\data\DAMENG\MAIN.DBF 4 C:\dmdbms\data\DAMENG\BOOKSHOP.DBF 5 C:\dmdbms\data\DAMENG\TEST_DATA01.DBF Continue?[Y/N]:y restore bak_file: C:\xcl\inc\dmincord0full.bak ... start restore database... start restore file: C:\dmdbms\data\DAMENG\SYSTEM.DBF(SYSTEM), pages: 281 end restore file: C:\dmdbms\data\DAMENG\SYSTEM.DBF(SYSTEM) start restore file: C:\dmdbms\data\DAMENG\ROLL.DBF(ROLL), pages: 366 end restore file: C:\dmdbms\data\DAMENG\ROLL.DBF(ROLL) start restore file: C:\dmdbms\data\DAMENG\MAIN.DBF(MAIN), pages: 24 end restore file: C:\dmdbms\data\DAMENG\MAIN.DBF(MAIN) start restore file: C:\dmdbms\data\DAMENG\BOOKSHOP.DBF(BOOKSHOP), pages: 133 end restore file: C:\dmdbms\data\DAMENG\BOOKSHOP.DBF(BOOKSHOP) start restore file: C:\dmdbms\data\DAMENG\TEST_DATA01.DBF(TEST_DATA), pages: 10 end restore file: C:\dmdbms\data\DAMENG\TEST_DATA01.DBF(TEST_DATA) end restore database data files. restore bak_file: C:\xcl\inc\dmincord4.bak ... start restore database... start restore file: C:\dmdbms\data\DAMENG\SYSTEM.DBF(SYSTEM), pages: 1 end restore file: C:\dmdbms\data\DAMENG\SYSTEM.DBF(SYSTEM) start restore file: C:\dmdbms\data\DAMENG\ROLL.DBF(ROLL), pages: 8 end restore file: C:\dmdbms\data\DAMENG\ROLL.DBF(ROLL) start restore file: C:\dmdbms\data\DAMENG\TEST_DATA01.DBF(TEST_DATA), pages: 3 end restore file: C:\dmdbms\data\DAMENG\TEST_DATA01.DBF(TEST_DATA) end restore database data files. restore finished, code = 0! restore successfully! restore time used: 2514.679(ms) c:\dmdbms\bin> SQL>select * from test_sch.t2; 行号 ID NAME ---------- ----------- ---- 1 0 full 2 1 inc1 3 2 inc2 4 3 inc3 已用时间: 56.357(毫秒). 执行号:3. SQL>2. 在备份集目录,删除基备份,测试第二次增量备份的恢复
测试流程如下:
2.1 初始化库
dminit.exe PATH=C:\dmdbms\data DB_NAME=DAMENG INSTANCE_NAME=DMSERVER
2.2 移开基备份dmincord0full.bak
2.3 执行恢复命令
dmrestore ini_path=C:\xcl\inc\dm.ini file=C:\xcl\inc\dmincord2.bak
结果提示"无基备份,restore error code : -8036"
2.4 把基备份还原回去,再执行恢复命令,还原成功。
执行过程:
c:\dmdbms\bin>dminit.exe PATH=C:\dmdbms\data DB_NAME=DAMENG INSTANCE_NAME=DMSERVER initdb V7.1.2.215-Build(2013.11.08-36626trunc) db version: 0X70008 file dm.key not found, use default license! create dm database success. 2014-01-16 10:35:34 c:\dmdbms\bin>dmrestore ini_path=C:\xcl\inc\dm.ini file=C:\xcl\inc\dmincord2.bak restore V7.1.2.215-Build(2013.11.08-36626trunc) backup DMINCORD2 info: backup sig: BA backup tool version: 12595 backup db name: DAMENG backup db magic: 1389776595 backup name: DMINCORD2 backup type: increment backup level: online backup range: database backup description: 测试增量备份2 compressed level: 0 rac node: 0 page check: 0 length in char: 0 backup time: 2014-01-16 10:01:15 page size: 8 KB extent size: 16 case sensitive: 1 log page size: 512 B unicode flag: 0 data version: 0x70008 sys version: V7.1.2.215-Build(2013.11.08-36626trunc) enable policy: 0 parallel type: 0 parallel info len: 0 backup db fil num: 6 archive flag: 1 base backup LSN: 31272 base name: DMINCORD1 backup with log: Yes before backup LSN: 31278 after backup LSN: 31278 file_seq file_path size(KB) 1 C:\xcl\inc\dmincord2.bak 16384 file_seq file_path mirror_path 1 C:\dmdbms\data\DAMENG\SYSTEM.DBF 2 C:\dmdbms\data\DAMENG\ROLL.DBF 3 C:\dmdbms\data\DAMENG\MAIN.DBF 4 C:\dmdbms\data\DAMENG\BOOKSHOP.DBF 5 C:\dmdbms\data\DAMENG\TEST_DATA01.DBF Continue?[Y/N]:y 无基备份,restore error code : -8036 c:\dmdbms\bin> c:\dmdbms\bin> dmrestore ini_path=C:\xcl\inc\dm.ini file=C:\xcl\inc\dmincord2.bak restore V7.1.2.215-Build(2013.11.08-36626trunc) backup DMINCORD2 info: backup sig: BA backup tool version: 12595 backup db name: DAMENG backup db magic: 1389776595 backup name: DMINCORD2 backup type: increment backup level: online backup range: database backup description: 测试增量备份2 compressed level: 0 rac node: 0 page check: 0 length in char: 0 backup time: 2014-01-16 10:01:15 page size: 8 KB extent size: 16 case sensitive: 1 log page size: 512 B unicode flag: 0 data version: 0x70008 sys version: V7.1.2.215-Build(2013.11.08-36626trunc) enable policy: 0 parallel type: 0 parallel info len: 0 backup db fil num: 6 archive flag: 1 base backup LSN: 31272 base name: DMINCORD1 backup with log: Yes before backup LSN: 31278 after backup LSN: 31278 file_seq file_path size(KB) 1 C:\xcl\inc\dmincord2.bak 16384 file_seq file_path mirror_path 1 C:\dmdbms\data\DAMENG\SYSTEM.DBF 2 C:\dmdbms\data\DAMENG\ROLL.DBF 3 C:\dmdbms\data\DAMENG\MAIN.DBF 4 C:\dmdbms\data\DAMENG\BOOKSHOP.DBF 5 C:\dmdbms\data\DAMENG\TEST_DATA01.DBF Continue?[Y/N]:y restore bak_file: C:\xcl\inc\dmincord0full.bak ... start restore database... start restore file: C:\dmdbms\data\DAMENG\SYSTEM.DBF(SYSTEM), pages: 281 end restore file: C:\dmdbms\data\DAMENG\SYSTEM.DBF(SYSTEM) start restore file: C:\dmdbms\data\DAMENG\ROLL.DBF(ROLL), pages: 366 end restore file: C:\dmdbms\data\DAMENG\ROLL.DBF(ROLL) start restore file: C:\dmdbms\data\DAMENG\MAIN.DBF(MAIN), pages: 24 end restore file: C:\dmdbms\data\DAMENG\MAIN.DBF(MAIN) start restore file: C:\dmdbms\data\DAMENG\BOOKSHOP.DBF(BOOKSHOP), pages: 133 end restore file: C:\dmdbms\data\DAMENG\BOOKSHOP.DBF(BOOKSHOP) start restore file: C:\dmdbms\data\DAMENG\TEST_DATA01.DBF(TEST_DATA), pages: 10 end restore file: C:\dmdbms\data\DAMENG\TEST_DATA01.DBF(TEST_DATA) end restore database data files. restore bak_file: C:\xcl\inc\dmincord1.bak ... start restore database... start restore file: C:\dmdbms\data\DAMENG\ROLL.DBF(ROLL), pages: 2 end restore file: C:\dmdbms\data\DAMENG\ROLL.DBF(ROLL) start restore file: C:\dmdbms\data\DAMENG\TEST_DATA01.DBF(TEST_DATA), pages: 3 end restore file: C:\dmdbms\data\DAMENG\TEST_DATA01.DBF(TEST_DATA) end restore database data files. restore bak_file: C:\xcl\inc\dmincord2.bak ... start restore database... start restore file: C:\dmdbms\data\DAMENG\ROLL.DBF(ROLL), pages: 2 end restore file: C:\dmdbms\data\DAMENG\ROLL.DBF(ROLL) start restore file: C:\dmdbms\data\DAMENG\TEST_DATA01.DBF(TEST_DATA), pages: 3 end restore file: C:\dmdbms\data\DAMENG\TEST_DATA01.DBF(TEST_DATA) end restore database data files. restore finished, code = 0! restore successfully! restore time used: 3072.867(ms) c:\dmdbms\bin> SQL>select * from test_sch.t2; 行号 ID NAME ---------- ----------- ---- 1 0 full 2 1 inc1 3 2 inc2 已用时间: 40.276(毫秒). 执行号:3. SQL>从测试结果来看,达梦数据库的增量备份,要基于全库备份文件进行比较来确认要增量备份哪些数据,少了这个文件就没法做后续的增量。
但如果在连续做几次增量备份,再将其文件移开,再做增量,从属性可以看到,其基备份直接指向全备,而不像之前那些一样基备份依于前一次的增量备份文件。
个人理解这相当于这一次的增量变成增量差量备份。备份程序这种方法能解决备份目录下增量备份文件丢失的问题,但如果我要强制指定增量差量备份,
就要自己每次备份完,就把备份出来的备份文件移出这个目录来实现......
MAIL:xcl_168@aliyun.com
BLOG: http://blog.csdn.net/xcl168