联机备份必须处在归档模式下,可用下面两条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. 在备份集目录,删除基备份,测试第二次增量备份的恢复
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>
从测试结果来看,达梦数据库的增量备份,要基于全库备份文件进行比较来确认要增量备份哪些数据,少了这个文件就没法做后续的增量。
BLOG: http://blog.csdn.net/xcl168