DM7使用dmrestore工具利用不同数据库的归档恢复数据库

使用dmrestore工具利用不同数据库的归档恢复数据库
使用不同库的归档恢复数据库,应用场景如下:
1. 创建一个源库D1;
2. 做一个备份B1;
3. 在D1上做一些操作,目的是生成一些归档A1;
4. 创建一个新库D2;
5. 用B1+A1还原恢复;
6. 在D2上做一些操作,生成一些归档A2;
7. 现在有了B1,A1,A2, 理论上应该可以恢复出一个最新状态的D2。

1) 创建源库D1,即待备份的数据库,然后启动数据库并配置归档,归档目录为/dm_home/dmdba/dmdbms/data/d1_arch。

[dmdba@shard1 data]$ dminit path=/dm_home/dmdba/dmdbms/data db_name=d1 instance_name=d1 port_num=5237 unicode_flag=0
initdb V7.1.6.46-Build(2018.02.08-89107)ENT
db version: 0x7000a
file dm.key not found, use default license!
License will expire in 14 day(s) on 2020-08-18

log file path: /dm_home/dmdba/dmdbms/data/d1/d101.log


log file path: /dm_home/dmdba/dmdbms/data/d1/d102.log

write to dir [/dm_home/dmdba/dmdbms/data/d1].
create dm database success. 2020-08-04 12:53:42

[root@shard1 root]# ./dm_service_installer.sh -i /dm_home/dmdba/dmdbms/data/d1/dm.ini -p d1 -t dmserver
ln -s '/usr/lib/systemd/system/DmServiced1.service' '/etc/systemd/system/multi-user.target.wants/DmServiced1.service'
Finished to create the service (DmServiced1)

[root@shard1 root]# service DmServiced1 start
Redirecting to /bin/systemctl start DmServiced1.service

–连接数据库配置归档

[dmdba@shard1 backup]$ disql SYSDBA/SYSDBA@localhost:5237

Server[localhost:5237]:mode is normal, state is open
login used time: 10.168(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46
SQL> alter database mount;
executed successfully
used time: 00:00:01.844. Execute id is 0.
SQL> alter database add archivelog 'dest=/dm_home/dmdba/dmdbms/data/d1_arch,type=local,file_size=256,space_limit=10240';
executed successfully
used time: 19.055(ms). Execute id is 0.
SQL> alter database archivelog;
executed successfully
used time: 28.622(ms). Execute id is 0.
SQL> alter database open;
executed successfully
used time: 666.842(ms). Execute id is 0.
SQL> select permanent_magic;

LINEID PERMANENT_MAGIC
---------- ---------------
1 -640527680

used time: 2.234(ms). Execute id is 807.
SQL> select db_magic from v$rlog;

LINEID DB_MAGIC
---------- -----------
1 -181202026

used time: 1.146(ms). Execute id is 808.

2)对数据库d1执行完全备份,备份名为B1

SQL> backup database full to b1 bakfile '/dm_home/dmdba/dmdbms/backup/b1.bak';
executed successfully
used time: 00:00:01.779. Execute id is 6.

3)在D1上做一些操作,目的是生成一些归档A1

SQL> create table tab_for_recover_01(c1 int);
executed successfully
used time: 14.595(ms). Execute id is 810.

SQL> begin
2 for i in 1 .. 100000 loop
3 insert into tab_for_recover_01 values(i);
4 end loop;
5 commit;
6 end;
7 /
DMSQL executed successfully
used time: 00:00:01.578. Execute id is 813.

[root@shard1 root]# service DmServiced1 stop
Redirecting to /bin/systemctl stop DmServiced1.service

4) 创建源库D2,即待还原的数据库,然后启动数据库并配置归档,归档目录为/dm_home/dmdba/dmdbms/data/d2_arch。

[dmdba@shard1 data]$ dminit path=/dm_home/dmdba/dmdbms/data db_name=d2 instance_name=d2 port_num=5238 unicode_flag=0
initdb V7.1.6.46-Build(2018.02.08-89107)ENT
db version: 0x7000a
file dm.key not found, use default license!
License will expire in 14 day(s) on 2020-08-18

log file path: /dm_home/dmdba/dmdbms/data/d2/d201.log


log file path: /dm_home/dmdba/dmdbms/data/d2/d202.log

write to dir [/dm_home/dmdba/dmdbms/data/d2].
create dm database success. 2020-08-04 13:10:20

[root@shard1 root]# ./dm_service_installer.sh -i /dm_home/dmdba/dmdbms/data/d2/dm.ini -p d2 -t dmserver
ln -s '/usr/lib/systemd/system/DmServiced2.service' '/etc/systemd/system/multi-user.target.wants/DmServiced2.service'
Finished to create the service (DmServiced2)
[root@shard1 root]# service DmServiced2 start
Redirecting to /bin/systemctl start DmServiced2.service

[dmdba@shard1 backup]$ disql SYSDBA/SYSDBA@localhost:5238

Server[localhost:5238]:mode is normal, state is open
login used time: 9.777(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46
SQL> alter database mount;
executed successfully
used time: 00:00:01.878. Execute id is 0.
SQL> alter database add archivelog 'dest=/dm_home/dmdba/dmdbms/data/d2_arch,type=local,file_size=256,space_limit=10240';
executed successfully
used time: 32.468(ms). Execute id is 0.
SQL> alter database archivelog;
executed successfully
used time: 70.806(ms). Execute id is 0.
SQL> alter database open;
executed successfully
used time: 752.732(ms). Execute id is 0.

5)利用源库D1的备份B1及归档A1还原数据库到D2。

[root@shard1 root]# service DmServiced2 stop
Redirecting to /bin/systemctl stop DmServiced2.service

[dmdba@shard1 backup]$ dmrestore ini_path=/dm_home/dmdba/dmdbms/data/d2/dm.ini file=/dm_home/dmdba/dmdbms/backup/b1.bak archive_dir=/dm_home/dmdba/dmdbms/data/d1_arch
restore V7.1.6.46-Build(2018.02.08-89107)ENT
file dm.key not found, use default license!


backup sig: BA
backup tool version: 12595
backup db name: d1
backup db magic: -181202026
backup pemnt magic: -640527680
backup name: B1
backup type: full
backup level: online
backup range: database
backup description:
compressed level: 0
encrypt_type: 0
encrypt_id: 2052
rac node: 0
page check: 0
rlog encrypt: 0
external cipher id: 0
external hash id: 0
length in char: 0
use new hash: 1
backup time: 2020-08-04 13:26:27
page size: 8 KB
extent size: 16
case sensitive: 1
log page size: 512 B
charset: 0
data version: 0x7000A
sys version: V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy: 0
mpp_timestamp: 1596518786
crc_check: TRUE
parallel type: 0
parallel info len: 0
backup db fil num: 4
archive flag: 1
backup with log: Yes
before backup LSN: 137137
after backup LSN: 137137


$bak_seq |$file_path |$size(K) |$used(K)
1|/dm_home/dmdba/dmdbms/backup/b1.bak | 32768.00| 15558.00


$file_seq |$type|$ts_name |$state |$size(K) |$seq_in_bak |$off_in_bak(B) |$len_in_bak(B) |$file_path |$mirror_path
1|DBF |SYSTEM |ONLINE | 21504| 1| 22528| 5095424|/dm_home/dmdba/dmdbms/data/d1/SYSTEM.DBF |
2|DBF |ROLL |ONLINE | 131072| 1| 5117952| 10780672|/dm_home/dmdba/dmdbms/data/d1/ROLL.DBF |
3|DBF |MAIN |ONLINE | 131072| 1| 15898624| 32768|/dm_home/dmdba/dmdbms/data/d1/MAIN.DBF |
4|LOG |ARCHLOG |ONLINE | 0| 1| 15931392| 0| |

Continue?[Y/N]:Y
restore bak_file: /dm_home/dmdba/dmdbms/backup/b1.bak ...
start restore database...
start restore file: /dm_home/dmdba/dmdbms/data/d2/SYSTEM.DBF(SYSTEM), pages: 622
end restore file: /dm_home/dmdba/dmdbms/data/d2/SYSTEM.DBF(SYSTEM)
start restore file: /dm_home/dmdba/dmdbms/data/d2/ROLL.DBF(ROLL), pages: 1316
end restore file: /dm_home/dmdba/dmdbms/data/d2/ROLL.DBF(ROLL)
start restore file: /dm_home/dmdba/dmdbms/data/d2/MAIN.DBF(MAIN), pages: 4
end restore file: /dm_home/dmdba/dmdbms/data/d2/MAIN.DBF(MAIN)
end restore database data files.


Apply archive log LSN from 137138 to 239573, time used:6.531s.
restore finished, code = 0!

restore successfully!
restore time used: 9133.827(ms)

6)在D2上做一些操作,生成一些归档A2;

[root@shard1 root]# service DmServiced2 start
Redirecting to /bin/systemctl start DmServiced2.service

[dmdba@shard1 backup]$ disql SYSDBA/SYSDBA@localhost:5238

Server[localhost:5238]:mode is normal, state is open
login used time: 10.015(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46
SQL> select count(*) from tab_for_recover_01;

LINEID COUNT(*)
---------- --------------------
1 100000

used time: 3.284(ms). Execute id is 3.
SQL> begin
2 for i in 100001 .. 200000 loop
3 insert into tab_for_recover_01 values(i);
4 end loop;
5 commit;
6 end;
7 /
DMSQL executed successfully
used time: 00:00:01.428. Execute id is 4.
SQL> commit;
executed successfully
used time: 0.338(ms). Execute id is 5.
SQL> select count(*) from tab_for_recover_01;

LINEID COUNT(*)
---------- --------------------
1 200000

used time: 0.289(ms). Execute id is 6.

7)关闭数据库D2,利用备份文件B1、归档A1、A2还原数据库到D2。

[root@shard1 root]# service DmServiced2 stop
Redirecting to /bin/systemctl stop DmServiced2.service

利用备份文件B1、归档A1还原目标库

[dmdba@shard1 backup]$ dmrestore ini_path=/dm_home/dmdba/dmdbms/data/d2/dm.ini file=/dm_home/dmdba/dmdbms/backup/b1.bak archive_dir=/dm_home/dmdba/dmdbms/data/d1_arch
restore V7.1.6.46-Build(2018.02.08-89107)ENT
file dm.key not found, use default license!


backup sig: BA
backup tool version: 12595
backup db name: d1
backup db magic: -181202026
backup pemnt magic: -640527680
backup name: B1
backup type: full
backup level: online
backup range: database
backup description:
compressed level: 0
encrypt_type: 0
encrypt_id: 2052
rac node: 0
page check: 0
rlog encrypt: 0
external cipher id: 0
external hash id: 0
length in char: 0
use new hash: 1
backup time: 2020-08-04 13:26:27
page size: 8 KB
extent size: 16
case sensitive: 1
log page size: 512 B
charset: 0
data version: 0x7000A
sys version: V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy: 0
mpp_timestamp: 1596518786
crc_check: TRUE
parallel type: 0
parallel info len: 0
backup db fil num: 4
archive flag: 1
backup with log: Yes
before backup LSN: 137137
after backup LSN: 137137


$bak_seq |$file_path |$size(K) |$used(K)
1|/dm_home/dmdba/dmdbms/backup/b1.bak | 32768.00| 15558.00


$file_seq |$type|$ts_name |$state |$size(K) |$seq_in_bak |$off_in_bak(B) |$len_in_bak(B) |$file_path |$mirror_path
1|DBF |SYSTEM |ONLINE | 21504| 1| 22528| 5095424|/dm_home/dmdba/dmdbms/data/d1/SYSTEM.DBF |
2|DBF |ROLL |ONLINE | 131072| 1| 5117952| 10780672|/dm_home/dmdba/dmdbms/data/d1/ROLL.DBF |
3|DBF |MAIN |ONLINE | 131072| 1| 15898624| 32768|/dm_home/dmdba/dmdbms/data/d1/MAIN.DBF |
4|LOG |ARCHLOG |ONLINE | 0| 1| 15931392| 0| |

Continue?[Y/N]:Y
restore bak_file: /dm_home/dmdba/dmdbms/backup/b1.bak ...
start restore database...
start restore file: /dm_home/dmdba/dmdbms/data/d2/SYSTEM.DBF(SYSTEM), pages: 622
end restore file: /dm_home/dmdba/dmdbms/data/d2/SYSTEM.DBF(SYSTEM)
start restore file: /dm_home/dmdba/dmdbms/data/d2/ROLL.DBF(ROLL), pages: 1316
end restore file: /dm_home/dmdba/dmdbms/data/d2/ROLL.DBF(ROLL)
start restore file: /dm_home/dmdba/dmdbms/data/d2/MAIN.DBF(MAIN), pages: 4
end restore file: /dm_home/dmdba/dmdbms/data/d2/MAIN.DBF(MAIN)
end restore database data files.


Apply archive log LSN from 137138 to 239573, time used:6.839s.
restore finished, code = 0!

restore successfully!
restore time used: 9586.006(ms)

查看归档A2的db_magic

[dmdba@shard1 d2_arch]$ ls -lrt
总用量 12984
-rw-r--r-- 1 dmdba dinstall 207872 8月 4 13:17 ARCHIVE_LOCAL1_20200804131521529_0.log
-rw-r--r-- 1 dmdba dinstall 268435456 8月 4 13:32 ARCHIVE_LOCAL1_20200804133104014_0.log

[dmdba@shard1 backup]$ dmrachk arch_fil=/dm_home/dmdba/dmdbms/data/d2_arch/ARCHIVE_LOCAL1_20200804131521529_0.log
rachk V7.1.6.46-Build(2018.02.08-89107)ENT
/*******************************************************************/
archive file /dm_home/dmdba/dmdbms/data/d2_arch/ARCHIVE_LOCAL1_20200804131521529_0.log itemize.
version : 0x7004
status : INACTIVE
n_rpags : 398
db_magic : 399359200
pemnt_magic : -1514196346
arch_lsn : 31701
arch_seq : 13564
clsn : 34492
next_seq : 13961
file len : 207872
file free : 207872
create time : 2020-08-04 13:15:21
close time : 2020-08-04 13:17:38
crc_check : TRUE
/*******************************************************************/

The SUMMARY(seqno[0]):
total files: 1
okey files: 1
fail file: 0
repeat file: 0

the rachk tool running cost 0.435 ms

[dmdba@shard1 backup]$ dmrachk arch_fil=/dm_home/dmdba/dmdbms/data/d2_arch/ARCHIVE_LOCAL1_20200804133104014_0.log
rachk V7.1.6.46-Build(2018.02.08-89107)ENT
/*******************************************************************/
archive file /dm_home/dmdba/dmdbms/data/d2_arch/ARCHIVE_LOCAL1_20200804133104014_0.log itemize.
version : 0x7004
status : INACTIVE
n_rpags : 25688
db_magic : 349450744
pemnt_magic : -640527680
arch_lsn : 239573
arch_seq : 13962
clsn : 343441
next_seq : 39649
file len : 13156352
file free : 13156352
create time : 2020-08-04 13:31:04
close time : 2020-08-04 13:40:35
crc_check : TRUE
/*******************************************************************/

The SUMMARY(seqno[0]):
total files: 1
okey files: 1
fail file: 0
repeat file: 0

the rachk tool running cost 0.394 ms

修改目标库D2的db_magic与A2的一致,A2的db_magic为349450744

[dmdba@shard1 d2]$ ls -lrt
总用量 544144
drwxr-xr-x 2 dmdba dinstall 6 8月 4 13:10 bak
-rw-r--r-- 1 dmdba dinstall 479 8月 4 13:10 sqllog.ini
drwxr-xr-x 2 dmdba dinstall 6 8月 4 13:10 HMAIN
-rw-r--r-- 1 dmdba dinstall 880 8月 4 13:10 dminit20200804131010.log
drwxr-xr-x 2 dmdba dinstall 6 8月 4 13:14 trace
-rw-r--r-- 1 dmdba dinstall 12 8月 4 13:14 rep_conflict.log
-rw-r--r-- 1 dmdba dinstall 269 8月 4 13:15 dmarch.ini
-rw-r--r-- 1 dmdba dinstall 220 8月 4 13:43 dminst.sys
-rw-r--r-- 1 dmdba dinstall 10485760 8月 4 13:43 TEMP.DBF
-rw-r--r-- 1 dmdba dinstall 5120 8月 4 13:43 dm.ctl
drwxr-xr-x 2 dmdba dinstall 4096 8月 4 13:43 ctl_bak
-rw-r--r-- 1 dmdba dinstall 134217728 8月 4 13:43 ROLL.DBF
-rw-r--r-- 1 dmdba dinstall 134217728 8月 4 13:43 MAIN.DBF
-rw-r--r-- 1 dmdba dinstall 268435456 8月 4 13:43 d201.log
-rw-r--r-- 1 dmdba dinstall 268435456 8月 4 13:43 d202.log
-rw-r--r-- 1 dmdba dinstall 633 8月 4 13:43 dm_service.prikey
-rw-r--r-- 1 dmdba dinstall 40845 8月 4 13:43 dm.ini
-rw-r--r-- 1 dmdba dinstall 22020096 8月 4 13:43 SYSTEM.DBF

[dmdba@shard1 d2]$ dmmdf type=1 file=SYSTEM.DBF
dmmdf V7.1.6.46-Build(2018.02.08-89107)ENT
**********************************************************
1 db_magic=-844697348
2 next_trxid=1127
3 pemnt_magic=-640527680
**********************************************************
Please input which parameter you want to change(1-3), q to quit: 1
Please input new value: 349450744
**********************************************************
1 db_magic=349450744
2 next_trxid=1127
3 pemnt_magic=-640527680
**********************************************************
Do you want to save the change to file (y/n): Y
Save to file success!

[dmdba@shard1 d2]$ dmmdf type=2 file=d201.log
dmmdf V7.1.6.46-Build(2018.02.08-89107)ENT
**********************************************************
1 sig = DMRLOG
2 ver = 7004
3 chksum = 0
4 dbversion = 0x7000a
5 sta = 0
6 n_magic = 35
7 db_magic = -844697348
8 clsn_fil = 0
10 next_seq = 39650
11 arch_seq = 0
12 len = 268435456
13 free = 4096
14 clsn = 239573
15 clsn_off = 4096
16 arch_lsn = 0
17 pemnt_magic = -640527680
18 fil_id = 0
19 crc_check = 1
**********************************************************
You can only reset sta(5) or db_magic (7) or clsn (14) or pemnt_magic(17) or fil_id(18).
Please input the num which one you want to change, q to quit: 7
Input the new value: 349450744
**********************************************************
1 sig = DMRLOG
2 ver = 7004
3 chksum = 0
4 dbversion = 0x7000a
5 sta = 0
6 n_magic = 35
7 db_magic = 349450744
8 clsn_fil = 0
10 next_seq = 39650
11 arch_seq = 0
12 len = 268435456
13 free = 4096
14 clsn = 239573
15 clsn_off = 4096
16 arch_lsn = 0
17 pemnt_magic = -640527680
18 fil_id = 0
19 crc_check = 1
**********************************************************
Do you want to quit and save the change to file (y/n): Y
Save to file success!
[dmdba@shard1 d2]$ dmmdf type=2 file=d202.log
dmmdf V7.1.6.46-Build(2018.02.08-89107)ENT
**********************************************************
1 sig = DMRLOG
2 ver = 7004
3 chksum = 0
4 dbversion = 0x7000a
5 sta = 0
6 n_magic = 35
7 db_magic = -844697348
8 clsn_fil = 0
10 next_seq = 0
11 arch_seq = 0
12 len = 268435456
13 free = 4096
14 clsn = 0
15 clsn_off = 0
16 arch_lsn = 0
17 pemnt_magic = -640527680
18 fil_id = 1
19 crc_check = 1
**********************************************************
You can only reset sta(5) or db_magic (7) or clsn (14) or pemnt_magic(17) or fil_id(18).
Please input the num which one you want to change, q to quit: 7
Input the new value: 349450744
**********************************************************
1 sig = DMRLOG
2 ver = 7004
3 chksum = 0
4 dbversion = 0x7000a
5 sta = 0
6 n_magic = 35
7 db_magic = 349450744
8 clsn_fil = 0
10 next_seq = 0
11 arch_seq = 0
12 len = 268435456
13 free = 4096
14 clsn = 0
15 clsn_off = 0
16 arch_lsn = 0
17 pemnt_magic = -640527680
18 fil_id = 1
19 crc_check = 1
**********************************************************
Do you want to quit and save the change to file (y/n): Y
Save to file success!

利用归档A2恢复。

[dmdba@shard1 backup]$ dmrestore ini_path=/dm_home/dmdba/dmdbms/data/d2/dm.ini archive_dir=/dm_home/dmdba/dmdbms/data/d2_arch res_type=2
restore V7.1.6.46-Build(2018.02.08-89107)ENT
file dm.key not found, use default license!

Continue?[Y/N]:Y
try to apply archive log from LSN: 239573 to LSN: 9223372036854775807.

Apply archive log LSN from 239574 to 343441, time used:1.372s.

restore successfully!
restore time used: 2406.492(ms)

8)启动数据D2查看结果。

[root@shard1 root]# service DmServiced2 start
Redirecting to /bin/systemctl start DmServiced2.service

SQL> select count(*) from tab_for_recover_01;

LINEID COUNT(*)
---------- --------------------
1 200000

used time: 0.309(ms). Execute id is 4.

DM7使用dmrestore执行并行映射文件还原

使用dmrestore执行并行映射文件还原
对于并行备份产生的备份文件,系统支持利用还原工具对数据库进行并行还原。与并行备份一样,并行还原需要用户指定并行映射文件的存储位置。由于并行备份可能是增量备份,而备份的基础备份也有可能是并行备份,因此执行并行还原需要指定一个映射文件存放的目录,用于还原的并行备份的映射文件都存放在该目录下。并行还原能提高还原性能,使得数据服务迅速还原。需要说明的是,备份时的映射文件内容应与还原时映射文件内容保持一致,但这不是必需的,系统在还原前,会对用户设置的映射文件内容进行校验,判断映射文件内容是否与备份时映射文件内容兼容,保证系统能正确还原数据库。

创建并行映射文件

[dmdba@shard1 backup]$ vi bak.parallel
[DMHR,USERS]=/dm_home/dmdba/dmdbms/backup/backup1
[FG_PERSON]=/dm_home/dmdba/dmdbms/backup/backup2
[default]=/dm_home/dmdba/dmdbms/backup/backup3

创建数据库的备份文件

SQL> backup database full to para_bak bakfile '/dm_home/dmdba/dmdbms/backup/parallel.bak' parallel '/dm_home/dmdba/dmdbms/backup/bak.parallel';
executed successfully
used time: 00:00:12.628. Execute id is 164.

[dmdba@shard1 backup]$ ls -lrt
-rw-r--r-- 1 dmdba dinstall       146 8月   4 11:50 bak.parallel
drwxr-xr-x 2 dmdba dinstall        47 8月   4 12:10 backup3
drwxr-xr-x 2 dmdba dinstall        47 8月   4 12:10 backup2
drwxr-xr-x 2 dmdba dinstall        47 8月   4 12:10 backup1
-rw-r--r-- 1 dmdba dinstall  33554432 8月   4 12:10 parallel.bak
[dmdba@shard1 backup]$ cd backup1
[dmdba@shard1 backup1]$ ls -lrt
总用量 1512
-rw-r--r-- 1 dmdba dinstall 33554432 8月   4 12:10 DB_jydm_20200804121005000554_1.bak
[dmdba@shard1 backup1]$ cd ..
[dmdba@shard1 backup]$ cd backup2
[dmdba@shard1 backup2]$ ls -lrt
总用量 28
-rw-r--r-- 1 dmdba dinstall 33554432 8月   4 12:10 DB_jydm_20200804121005000554_1.bak
[dmdba@shard1 backup2]$ cd ..
[dmdba@shard1 backup]$ cd backup3
[dmdba@shard1 backup3]$ ls -lrt
总用量 390420
-rw-r--r-- 1 dmdba dinstall 402653184 8月   4 12:10 DB_jydm_20200804121005000554_1.bak

使用并行备份文件来还原数据库,并行映射文件为/dm_home/dmdba/dmdbms/backup/bak.parallel

[root@shard1 oracle]# service DmServicejydm stop
Redirecting to /bin/systemctl stop  DmServicejydm.service

[dmdba@shard1 backup]$ dmrestore ini_path=/dm_home/dmdba/dmdbms/data/jydm/dm.ini file=/dm_home/dmdba/dmdbms/backup/parallel.bak   parallel_dir=/dm_home/dmdba/dmdbms/backup/bak.parallel
restore V7.1.6.46-Build(2018.02.08-89107)ENT
file dm.key not found, use default license!


backup sig:            BA
backup tool version:   12595
backup db name:        jydm
backup db magic:       -848310636
backup pemnt magic:    1250320462
backup name:           PARA_BAK
backup type:           full
backup level:          online
backup range:          database
backup description:
compressed level:      0
encrypt_type:          0
encrypt_id:            2052
rac node:              0
page check:            0
rlog encrypt:          0
external cipher id:    0
external hash id:      0
length in char:        0
use new hash:          1
backup time:           2020-08-04 12:10:05
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
charset:               0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
mpp_timestamp:         1596514204
crc_check:             TRUE
parallel type:         1
parallel info len:     1536
backup db fil num:     9
archive flag:          1
backup with log:       Yes
before backup LSN:     32598802
after backup LSN:      32598813


$bak_seq |$file_path                                        |$size(K)       |$used(K)
        1|/dm_home/dmdba/dmdbms/backup/parallel.bak         |       32768.00|          47.50


$file_seq |$type|$ts_name       |$state    |$size(K)  |$seq_in_bak    |$off_in_bak(B) |$len_in_bak(B) |$file_path                                        |$mirror_path
         1|DBF  |SYSTEM         |ONLINE    |     23552|              1|              0|              0|/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF        |
         2|DBF  |ROLL           |ONLINE    |    229376|              1|              0|              0|/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF          |
         3|DBF  |MAIN           |ONLINE    |    305152|              1|              0|              0|/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF          |
         4|DBF  |BOOKSHOP       |ONLINE    |    153600|              1|              0|              0|/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF      |
         5|DBF  |DMHR           |ONLINE    |    131072|              1|              0|              0|/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF          |
         6|DBF  |USERS          |ONLINE    |     51200|              1|              0|              0|/dm_home/dmdba/dmdbms/data/jydm/users01.dbf       |
         7|DBF  |SYSAUX         |ONLINE    |    179200|              1|              0|              0|/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF        |
         8|DBF  |FG_PERSON      |ONLINE    |    131072|              1|              0|              0|/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF     |
         9|LOG  |ARCHLOG        |ONLINE    |         0|              1|          44544|           4096|                                                  |


backup sig:            BA
backup tool version:   12595
backup db name:        jydm
backup db magic:       -848310636
backup pemnt magic:    1250320462
backup name:           PARA_BAK
backup type:           full
backup level:          online
backup range:          database
backup description:
compressed level:      0
encrypt_type:          0
encrypt_id:            2052
rac node:              0
page check:            0
rlog encrypt:          0
external cipher id:    0
external hash id:      0
length in char:        0
use new hash:          1
backup time:           2020-08-04 12:10:05
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
charset:               0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
mpp_timestamp:         1596514204
crc_check:             TRUE
parallel type:         2
parallel info len:     0
backup db fil num:     2
archive flag:          1
backup with log:       Yes
before backup LSN:     32598802
after backup LSN:      0


$bak_seq |$file_path                                        |$size(K)       |$used(K)
        1|/dm_home/dmdba/dmdbms/backup/backup1/DB_jydm_20200804121005000554_1.bak|       32768.00|        1510.00


$file_seq |$type|$ts_name       |$state    |$size(K)  |$seq_in_bak    |$off_in_bak(B) |$len_in_bak(B) |$file_path                                        |$mirror_path
         1|DBF  |DMHR           |ONLINE    |    131072|              1|          14336|         425984|/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF          |
         2|DBF  |USERS          |ONLINE    |     51200|              1|         440320|        1105920|/dm_home/dmdba/dmdbms/data/jydm/users01.dbf       |


backup sig:            BA
backup tool version:   12595
backup db name:        jydm
backup db magic:       -848310636
backup pemnt magic:    1250320462
backup name:           PARA_BAK
backup type:           full
backup level:          online
backup range:          database
backup description:
compressed level:      0
encrypt_type:          0
encrypt_id:            2052
rac node:              0
page check:            0
rlog encrypt:          0
external cipher id:    0
external hash id:      0
length in char:        0
use new hash:          1
backup time:           2020-08-04 12:10:05
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
charset:               0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
mpp_timestamp:         1596514204
crc_check:             TRUE
parallel type:         2
parallel info len:     0
backup db fil num:     1
archive flag:          1
backup with log:       Yes
before backup LSN:     32598802
after backup LSN:      0


$bak_seq |$file_path                                        |$size(K)       |$used(K)
        1|/dm_home/dmdba/dmdbms/backup/backup2/DB_jydm_20200804121005000554_1.bak|       32768.00|          26.00


$file_seq |$type|$ts_name       |$state    |$size(K)  |$seq_in_bak    |$off_in_bak(B) |$len_in_bak(B) |$file_path                                        |$mirror_path
         1|DBF  |FG_PERSON      |ONLINE    |    131072|              1|          10240|          16384|/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF     |


backup sig:            BA
backup tool version:   12595
backup db name:        jydm
backup db magic:       -848310636
backup pemnt magic:    1250320462
backup name:           PARA_BAK
backup type:           full
backup level:          online
backup range:          database
backup description:
compressed level:      0
encrypt_type:          0
encrypt_id:            2052
rac node:              0
page check:            0
rlog encrypt:          0
external cipher id:    0
external hash id:      0
length in char:        0
use new hash:          1
backup time:           2020-08-04 12:10:05
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
charset:               0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
mpp_timestamp:         1596514204
crc_check:             TRUE
parallel type:         2
parallel info len:     0
backup db fil num:     5
archive flag:          1
backup with log:       Yes
before backup LSN:     32598802
after backup LSN:      0


$bak_seq |$file_path                                        |$size(K)       |$used(K)
        1|/dm_home/dmdba/dmdbms/backup/backup3/DB_jydm_20200804121005000554_1.bak|      393216.00|      390418.00


$file_seq |$type|$ts_name       |$state    |$size(K)  |$seq_in_bak    |$off_in_bak(B) |$len_in_bak(B) |$file_path                                        |$mirror_path
         1|DBF  |SYSTEM         |ONLINE    |     23552|              1|          26624|        6766592|/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF        |
         2|DBF  |ROLL           |ONLINE    |    229376|              1|        6793216|       10887168|/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF          |
         3|DBF  |MAIN           |ONLINE    |    305152|              1|       17680384|      270917632|/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF          |
         4|DBF  |BOOKSHOP       |ONLINE    |    153600|              1|      288598016|         933888|/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF      |
         5|DBF  |SYSAUX         |ONLINE    |    179200|              1|      289531904|      110256128|/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF        |

Continue?[Y/N]:Y
restore bak_file: /dm_home/dmdba/dmdbms/backup/parallel.bak ...
start restore database...
start restore database...
start restore database...
start restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON), pages: 2
start restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR), pages: 52
start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM), pages: 826
end restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON)
end restore database data files.

end restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR)
end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS), pages: 135
start restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL), pages: 1329
end restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL)
end restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN), pages: 33071
end restore database data files.

end restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP), pages: 114
end restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX), pages: 13459
end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX)
end restore database data files.

redo tmp arch file: /dm_home/dmdba/dmdbms/backup/RES_TMP_ARCH_20200804121936840_0.log, rpages: 16

Apply archive log LSN from 32598814 to 32598813, time used:0.000s.
restore finished, code = 0!

restore successfully!
restore time used: 9800.081(ms)

启动数据库

[root@shard1 oracle]# service DmServicejydm start
Redirecting to /bin/systemctl start  DmServicejydm.service

SQL> select * from t1;

LINEID     C1          C2
---------- ----------- -----------
1          1           1
2          2           2
3          3           3
4          4           4
5          5           5
6          6           6

6 rows got

used time: 0.427(ms). Execute id is 101.

DM7使用dmrestore执行指定时间点或LSN还原

使用dmrestore执行指定时间点或LSN还原
达梦系统使用归档日志将数据库还原到最新的状态,这一节讨论与归档日志相关的另一个功能:还原到指定的时间点。根据用户需求,可以将数据库还原到指定的时间点。还原到时间点的功能依赖于归档日志,在备份完成时,系统会记录一个备份时间,因此要还原的时间点一定在备份完成时间之后,否则系统会提示报错信息。借助备份文件完成还原后,开始重做归档日志,区别于完全还原将所有可用的归档日志全部重做,若指定还原到时间点,则只重做早于时间点的日志,从而达到将数据库还原到指定时间的状态的目的。需要注意的是,由于表空间只是数据库的一部分,为保证还原后,数据库中的所有数据处于最新状态,还原表空间会重做该表空间所有可用的归档日志,因此还原表空间不支持还原到时间点功能。

比如用户在2020-7-21 19:40:20时对数据库jydm做了一个备份,在2020-7-21 20:34:20想将数据库jydm还原到时间点2020-07-21 20:00:03,若用户保证从备份完成的时间点到指定时间点这段时间的归档日志都完好,则通过如下还原命令就能达到预期效果。

下面举例说明
1.在2020-7-21 19:40:20时对数据库jydm进行备份

SQL> backup database full to full_bak_for_arch_restor bakfile '/dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak';
executed successfully
used time: 00:00:07.697. Execute id is 43.

SQL> select * from t1;

LINEID     C1          C2
---------- ----------- -----------
1          1           1
2          2           2
3          3           3
4          4           4
5          5           5
6          6           6

6 rows got

used time: 0.454(ms). Execute id is 97.
SQL> select sysdate from dual;

LINEID     SYSDATE
---------- ---------------------------
1          2020-07-21 20:00:03.165365

used time: 0.994(ms). Execute id is 337.

使用select file_lsn from v$rlog命令查询此时的LSN为:30043605
SQL> select file_lsn from v$rlog;

LINEID     FILE_LSN
---------- --------------------
1          30043605

used time: 1.344(ms). Execute id is 654.

2.删除表t1中的数据

SQL> delete from t1;
affect rows 6

used time: 1.309(ms). Execute id is 681.
SQL> commit;
executed successfully
used time: 33.649(ms). Execute id is 682.
SQL> select * from t1;
no rows

used time: 18.944(ms). Execute id is 696.

3.将数据库还原到指定时间2020-07-21 20:00:03.165365

[root@shard1 oracle]# service DmServicejydm stop
Redirecting to /bin/systemctl stop  DmServicejydm.service

[dmdba@shard1 backup]$ dmrestore ini_path=/dm_home/dmdba/dmdbms/data/jydm/dm.ini file=/dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak archive_dir=/dm_home/dmdba/dmdbms/data/arch time="2020-07-21 20:00:03.165365";
restore V7.1.6.46-Build(2018.02.08-89107)ENT
file dm.key not found, use default license!


backup sig:            BA
backup tool version:   12595
backup db name:        jydm
backup db magic:       1371967312
backup pemnt magic:    1250320462
backup name:           FULL_BAK_FOR_ARCH_RESTOR
backup type:           full
backup level:          online
backup range:          database
backup description:
compressed level:      0
encrypt_type:          0
encrypt_id:            2052
rac node:              0
page check:            0
rlog encrypt:          0
external cipher id:    0
external hash id:      0
length in char:        0
use new hash:          1
backup time:           2020-07-21 19:52:09
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
charset:               0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
mpp_timestamp:         1595332328
crc_check:             TRUE
parallel type:         0
parallel info len:     0
backup db fil num:     9
archive flag:          1
backup with log:       Yes
before backup LSN:     30040400
after backup LSN:      30040406


$bak_seq |$file_path                                        |$size(K)       |$used(K)
        1|/dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak|      393216.00|      362036.00


$file_seq |$type|$ts_name       |$state    |$size(K)  |$seq_in_bak    |$off_in_bak(B) |$len_in_bak(B) |$file_path                                        |$mirror_path
         1|DBF  |SYSTEM         |ONLINE    |     23552|              1|          43008|        6766592|/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF        |
         2|DBF  |ROLL           |ONLINE    |    229376|              1|        6809600|       10887168|/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF          |
         3|DBF  |MAIN           |ONLINE    |    276480|              1|       17696768|      240287744|/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF          |
         4|DBF  |BOOKSHOP       |ONLINE    |    153600|              1|      257984512|         933888|/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF      |
         5|DBF  |DMHR           |ONLINE    |    131072|              1|      258918400|         425984|/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF          |
         6|DBF  |USERS          |ONLINE    |     51200|              1|      259344384|        1105920|/dm_home/dmdba/dmdbms/data/jydm/users01.dbf       |
         7|DBF  |SYSAUX         |ONLINE    |    179200|              1|      260450304|      110256128|/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF        |
         8|DBF  |FG_PERSON      |ONLINE    |    131072|              1|      370706432|          16384|/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF     |
         9|LOG  |ARCHLOG        |ONLINE    |         0|              1|      370722816|           2048|                                                  |

Continue?[Y/N]:Y
can't find useable archive file when search assigned archive directory
restore bak_file: /dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak ...
start restore database...
start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM), pages: 826
end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL), pages: 1329
end restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN), pages: 29332
end restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP), pages: 114
end restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR), pages: 52
end restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS), pages: 135
end restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX), pages: 13459
end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON), pages: 2
end restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON)
redo tmp arch file: /dm_home/dmdba/dmdbms/backup/RES_TMP_ARCH_20200721200858135_0.log, rpages: 16

end restore database data files.

Apply archive log LSN from 30040407 to 30040406, time used:0.000s.
restore finished, code = 0!

restore successfully!
restore time used: 7652.178(ms)

4.检查表t1的数据是否已经恢复回来了

[root@shard1 oracle]# service DmServicejydm start
Redirecting to /bin/systemctl start  DmServicejydm.service

SQL> select * from t1;

LINEID     C1          C2
---------- ----------- -----------
1          1           1
2          2           2
3          3           3
4          4           4
5          5           5
6          6           6

6 rows got

used time: 0.440(ms). Execute id is 86.

达梦系统使用归档还原,还可以指定还原特定的END_LSN,备份文件中会记录一个备份结束的LSN,如果指定END_LSN,则必须保证该END_LSN大于备份文件中的记录的最后一个LSN,否则会无视该END_LSN,而还原到最新状态,如果同时指定了TIME则会以最早的为标准。

5.上面还原数据库jydm时除了可以指定时间外也可以指定LSN:30043605

[root@shard1 oracle]# service DmServicejydm stop
Redirecting to /bin/systemctl stop  DmServicejydm.service

[dmdba@shard1 backup]$ dmrestore ini_path=/dm_home/dmdba/dmdbms/data/jydm/dm.ini file=/dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak archive_dir=/dm_home/dmdba/dmdbms/data/arch end_lsn=30043605
restore V7.1.6.46-Build(2018.02.08-89107)ENT
file dm.key not found, use default license!


backup sig:            BA
backup tool version:   12595
backup db name:        jydm
backup db magic:       1371967312
backup pemnt magic:    1250320462
backup name:           FULL_BAK_FOR_ARCH_RESTOR
backup type:           full
backup level:          online
backup range:          database
backup description:
compressed level:      0
encrypt_type:          0
encrypt_id:            2052
rac node:              0
page check:            0
rlog encrypt:          0
external cipher id:    0
external hash id:      0
length in char:        0
use new hash:          1
backup time:           2020-07-21 19:52:09
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
charset:               0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
mpp_timestamp:         1595332328
crc_check:             TRUE
parallel type:         0
parallel info len:     0
backup db fil num:     9
archive flag:          1
backup with log:       Yes
before backup LSN:     30040400
after backup LSN:      30040406


$bak_seq |$file_path                                        |$size(K)       |$used(K)
        1|/dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak|      393216.00|      362036.00


$file_seq |$type|$ts_name       |$state    |$size(K)  |$seq_in_bak    |$off_in_bak(B) |$len_in_bak(B) |$file_path                                        |$mirror_path
         1|DBF  |SYSTEM         |ONLINE    |     23552|              1|          43008|        6766592|/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF        |
         2|DBF  |ROLL           |ONLINE    |    229376|              1|        6809600|       10887168|/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF          |
         3|DBF  |MAIN           |ONLINE    |    276480|              1|       17696768|      240287744|/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF          |
         4|DBF  |BOOKSHOP       |ONLINE    |    153600|              1|      257984512|         933888|/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF      |
         5|DBF  |DMHR           |ONLINE    |    131072|              1|      258918400|         425984|/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF          |
         6|DBF  |USERS          |ONLINE    |     51200|              1|      259344384|        1105920|/dm_home/dmdba/dmdbms/data/jydm/users01.dbf       |
         7|DBF  |SYSAUX         |ONLINE    |    179200|              1|      260450304|      110256128|/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF        |
         8|DBF  |FG_PERSON      |ONLINE    |    131072|              1|      370706432|          16384|/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF     |
         9|LOG  |ARCHLOG        |ONLINE    |         0|              1|      370722816|           2048|                                                  |

Continue?[Y/N]:Y
can't find useable archive file when search assigned archive directory
restore bak_file: /dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak ...
start restore database...
start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM), pages: 826
end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL), pages: 1329
end restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN), pages: 29332
end restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP), pages: 114
end restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR), pages: 52
end restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS), pages: 135
end restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX), pages: 13459
end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON), pages: 2
end restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON)
redo tmp arch file: /dm_home/dmdba/dmdbms/backup/RES_TMP_ARCH_20200721201304925_0.log, rpages: 16

end restore database data files.

Apply archive log LSN from 30040407 to 30040406, time used:0.000s.
restore finished, code = 0!

restore successfully!
restore time used: 7764.389(ms)

6.检查表t1的数据是否已经恢复回来了

[root@shard1 oracle]# service DmServicejydm start
Redirecting to /bin/systemctl start  DmServicejydm.service

SQL> select * from t1;

LINEID     C1          C2
---------- ----------- -----------
1          1           1
2          2           2
3          3           3
4          4           4
5          5           5
6          6           6

6 rows got

used time: 0.445(ms). Execute id is 47.

可以看到指定时间或LSN可以达到同样的效果。

DM7使用dmrestore工具利用归档日志还原

使用dmrestore工具利用归档日志还原
利用备份文件,DM可以将数据库、表空间和表还原到备份时的状态。但用户可能更希望将数据还原到最新的状态。这点不用担心,事实上系统足够智能,在利用备份完成还原后,会去归档目录搜索归档日志,并分析归档日志是否与还原的数据库匹配,若存在匹配的归档日志,则系统会重做这部分日志,将数据库还原到最新的状态;若没有可用的归档日志,则只能还原到备份时的状态。

利用指定归档目录下归档日志还原数据库jydm

1.对数据库jydm执行完全备份

SQL> backup database full to full_bak_for_arch_restor bakfile '/dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak';
executed successfully
used time: 00:00:25.113. Execute id is 977781.

SQL> select * from t1;

LINEID     C1          C2
---------- ----------- -----------
1          1           1
2          2           2
3          3           3
4          4           4
5          5           5

used time: 0.744(ms). Execute id is 977816.
SQL> insert into t1 values(6,6);
affect rows 1

used time: 49.901(ms). Execute id is 977842.
SQL> commit;
executed successfully
used time: 21.340(ms). Execute id is 977845.
SQL> select * from t1;

LINEID     C1          C2
---------- ----------- -----------
1          1           1
2          2           2
3          3           3
4          4           4
5          5           5
6          6           6

6 rows got

used time: 25.205(ms). Execute id is 977846.

2.异常终止数据库实例

[root@shard1 oracle]# ps -ef | grep dmserver
dmdba     3129     1  4 19:51 ?        00:00:02 /dm_home/dmdba/dmdbms/bin/dmserver /dm_home/dmdba/dmdbms/data/jydm/dm.ini -noconsole
root      3371 32007  0 19:52 pts/9    00:00:00 grep --color=auto dmserver
[root@shard1 oracle]# kill -9 3129
[root@shard1 oracle]# ps -ef | grep dmserver
root      3532 32007  0 19:53 pts/9    00:00:00 grep --color=auto dmserver

3.执行还原

[dmdba@shard1 backup]$ dmrestore ini_path=/dm_home/dmdba/dmdbms/data/jydm/dm.ini file=/dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak archive_dir=/dm_home/dmdba/dmdbms/data/arch
restore V7.1.6.46-Build(2018.02.08-89107)ENT
file dm.key not found, use default license!


backup sig:            BA
backup tool version:   12595
backup db name:        jydm
backup db magic:       1371967312
backup pemnt magic:    1250320462
backup name:           FULL_BAK_FOR_ARCH_RESTOR
backup type:           full
backup level:          online
backup range:          database
backup description:
compressed level:      0
encrypt_type:          0
encrypt_id:            2052
rac node:              0
page check:            0
rlog encrypt:          0
external cipher id:    0
external hash id:      0
length in char:        0
use new hash:          1
backup time:           2020-07-21 19:52:09
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
charset:               0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
mpp_timestamp:         1595332328
crc_check:             TRUE
parallel type:         0
parallel info len:     0
backup db fil num:     9
archive flag:          1
backup with log:       Yes
before backup LSN:     30040400
after backup LSN:      30040406


$bak_seq |$file_path                                        |$size(K)       |$used(K)
        1|/dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak|      393216.00|      362036.00


$file_seq |$type|$ts_name       |$state    |$size(K)  |$seq_in_bak    |$off_in_bak(B) |$len_in_bak(B) |$file_path                                        |$mirror_path
         1|DBF  |SYSTEM         |ONLINE    |     23552|              1|          43008|        6766592|/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF        |
         2|DBF  |ROLL           |ONLINE    |    229376|              1|        6809600|       10887168|/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF          |
         3|DBF  |MAIN           |ONLINE    |    276480|              1|       17696768|      240287744|/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF          |
         4|DBF  |BOOKSHOP       |ONLINE    |    153600|              1|      257984512|         933888|/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF      |
         5|DBF  |DMHR           |ONLINE    |    131072|              1|      258918400|         425984|/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF          |
         6|DBF  |USERS          |ONLINE    |     51200|              1|      259344384|        1105920|/dm_home/dmdba/dmdbms/data/jydm/users01.dbf       |
         7|DBF  |SYSAUX         |ONLINE    |    179200|              1|      260450304|      110256128|/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF        |
         8|DBF  |FG_PERSON      |ONLINE    |    131072|              1|      370706432|          16384|/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF     |
         9|LOG  |ARCHLOG        |ONLINE    |         0|              1|      370722816|           2048|                                                  |

Continue?[Y/N]:Y
can't find useable archive file when search assigned archive directory
restore bak_file: /dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak ...
start restore database...
start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM), pages: 826
end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL), pages: 1329
end restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN), pages: 29332
end restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP), pages: 114
end restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR), pages: 52
end restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS), pages: 135
end restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX), pages: 13459
end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON), pages: 2
end restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON)
redo tmp arch file: /dm_home/dmdba/dmdbms/backup/RES_TMP_ARCH_20200721195311007_0.log, rpages: 16

end restore database data files.

Apply archive log LSN from 30040407 to 30040406, time used:0.000s.
restore finished, code = 0!

restore successfully!
restore time used: 8601.260(ms)

4.验证数据

SQL> select * from t1;

LINEID     C1          C2
---------- ----------- -----------
1          1           1
2          2           2
3          3           3
4          4           4
5          5           5
6          6           6

6 rows got

used time: 0.454(ms). Execute id is 97.

DM7使用dmrestore工具还原数据库

使用dmrestore工具还原数据库
1. 概述
DM支持利用还原工具对数据库进行还原。根据不同备份类型,包括联机备份、脱机备份、完全备份以及增量备份,还原工具选择不同的还原策略实现恢复用户数据的目的。首先讨论联机备份与脱机备份,脱机备份仅包含数据页文件的内容,而联机备份文件除了包含数据页文件内容以外,可能还包括备份过程中产生的日志文件内容。因此在利用联机备份还原时,除了拷贝数据页至数据库文件以外,可能还需要重做备份的日志文件内容,达到还原数据库的目的。在还原联机库备份且不带日志的备份时,需要用户指定归档目录,由用户保证备份期间的归档日志存在且完好,在还原库时,需要重做该日志。如果日志不存在,则备份文件就无效,报错归档日志错误。

接下来讨论完全备份与增量备份,对于增量备份,还原工具会根据用户提供备份的信息搜集它的基础备份,若基础备份仍然为增量备份,则工具会继续搜集,直至搜集到一个类型为完全备份的基础备份为止。因此在这个过程中,工具会构造一个基础备份链表,备份链表基于备份间的依赖关系组织。比如,备份A是备份B的增量备份,则可以说A依赖于B。若用户首先进行了一次完全备份A,然后在A的基础上做了增量备份B,随后基于增量备份B又做了增量备份C,最后基于增量备份C做了增量备份D。那么此时利用增量备份D还原数据库时,系统搜集到得备份链表如30.1所示,执行还原时,首先利用完全备份恢复A进行还原,然后依次利用增量备份B,C和D还原,最终完成整个还原过程。需要说明的是,若备份类型为B树备份的数据库备份是不存在增量备份的。

脱机库还原支持无备份文件的还原,原理就是利用归档文件,在目标库上执行REDO操作,把库还原到指定的时间点或者LSN。限制条件是,
1)目标库和归档必须是源自同一个库;2)必须保证源库的归档是完整,否则会出现不可预知的错误,即要保证备份之后产生的归档是完整的。要利用归档还原,需要利用备份文件还原一个目标库,修改目标库db_magic和源库中归档文件的db_magic一致。然后就可以执行还原操作了。库db_magic的修改可以使用dmmdf工具。
dmmdf工具的用法如下:

dmmdf KEYWORD=value

在Windows“命令提示符”窗口中输入带参数的dmmdf命令启动该工具,参数说明见

[dmdba@shard1 dmdbms]$ dmmdf help
Format:  ./dmmdf KEYWORD=value

Example: ./dmmdf TYPE=1 FILE=/opt/data/DAMENG/SYSTEM.DBF

Keyword            Explanation
--------------------------------------------------------------------------------
TYPE                type
                    1: for dbf
                    2: for rlog
                    3: for original bak
                    4: for bakset meta
                    5: for bakset bkp
                    6: for bakset
                    7: batch modify db_magic for arch file
                    8: for database degrades
                    9:batch modify crc_check for DB specified by dm.ini.
                    10:batch modify crc_check for archive log in archive directory.
FILE                file path
DCR_INI             dmdcr.ini path
DB_MAGIC_SRC        db_magic_src,for TYPE=7 and 10
DB_MAGIC_DST        db_magic_dst,for TYPE=7
CRC_CHECK           crc_check,for TYPE=9 and 10
HELP                show this help info

--------------------------------------------------
Example: ./dmmdf TYPE=1 FILE=/opt/data/DAMENG/SYSTEM.dbf
         ./dmmdf TYPE=2 FILE=/opt/data/DAMENG/DAMENG01.log
         ./dmmdf TYPE=3 FILE=/opt/data/DAMENG/bak/dmdb.bak
         ./dmmdf TYPE=4 FILE=/opt/data/DAMENG/bak/bset/nbak.meta
         ./dmmdf TYPE=5 FILE=/opt/data/DAMENG/bak/bset/nbak.bak
         ./dmmdf TYPE=6 FILE=/opt/data/DAMENG/bak/bset
         ./dmmdf TYPE=7 FILE=/opt/data/DAMENG/arch DB_MAGIC_SRC=4734373 DB_MAGIC_DST=4734366
         ./dmmdf TYPE=8 FILE=/opt/data/DAMENG/dm.ctl
         ./dmmdf TYPE=9 FILE=/opt/data/DAMENG/dm.ini,CRC_CHECK=1
         ./dmmdf TYPE=10 FILE=/opt/data/DAMENG/arch,CRC_CHECK=0,DB_MAGIC_SRC=4734373

使用说明:
dmmdf工具可以修改TYPE中指定的文件中的信息,例如db_magic。
DMRESTORE还原工具的用法如下:

DMRESTORE KEYWORD=value 或KEYWORD=(value1,value2,...,valueN)

确认DM数据库服务器已停止后,在Windows“命令提示符”窗口中输入带参数的DMRESTORE命令启动该工具。

[dmdba@shard1 dmdbms]$ dmrestore help
Format: DMRESTORE  KEYWORD=value or KEYWORD=(value1,value2,...,valueN)

Eg: DMRESTORE  INI_PATH=/opt/dm7data/dameng/dm.ini FILE=/opt/dm7data/backup/test.bak

Imperative Argument: FILE

Keyword             explain(default value)
--------------------------------------------------------------------------------
INI_PATH            the path of the dmserver's dm.ini file
FILE                backup file
MAPPED_FIL              the path of mapped file, when res_type assign 4.
TIME                the timestamp of be going to recover
ARCHIVE_DIR         the directory at backup, Format (dir1,dir2,dir3,...)
BACKUP_DIR          the stored path of backup file, be used to search backup file, Format (dir1,dir2,dir3,...)
DATAFIL_PATH        the file path at the recovery, Format (id1,path1,id2,path2,id3,path3,...)
MIRROR_PATH         the mirror file path at the recovery, Format (id1,path1,id2,path2,id3,path3,...)
PARALLEL_DIR        the full path of parallel mapping file
RES_TYPE            restore type(0,1,2,3,4), 0: bakfil restore, 1: bakfil show, 2: archfil restore, 3: step increment restore, 4:output mapped file default(0)
END_LSN             restore to end_lsn
LOG                 restore output log file
DUMMY               quiet mode, {(Y)es,(N)o} default:No
PASSWORD            restore with password
ENCRYPT_NAME        restore decrypt with encrypt name
HELP                output help info

INI_PATH:配置文件路径,最大长度为256字节,可选参数

FILE:用于还原的备份文件完整路径,必选参数

MAPPED_FIL:当指定res_type为4时,输出备份文件的映射信息到该文件;如果指定res_type为0或3时,则还原时,会采用MAPPED_FIL文件中的data_path和mirror_path路径为准(如果用户希望使用相对路径策略还原,请删除相关的组,同时修改要修改的data_path和mirror_path)。此外,如果指定MAPPED_FIL参数,则本工具中datafil_path和mirror_path参数会失效;反之,则生效,可选参数

TIME:指定还原的时间点和指定还原的LSN,需要配合ARCHIVE_DIR使用,若指定了ARCHIVE_DIR,既没有指定TIME和END_LSN则会重做所有的归档;如果指定了某一个则会还原到指定的TIME或者LSN;如果都指定了,则会还原到早的一个时间点(或者LSN);如果指定END_LSN为1,则表示还原到备份的时候,不会redo归档,可选参数

END_LSN:指定还原的时间点和指定还原的LSN,需要配合ARCHIVE_DIR使用,若指定了ARCHIVE_DIR,既没有指定TIME和END_LSN则会重做所有的归档;如果指定了某一个则会还原到指定的TIME或者LSN;如果都指定了,则会还原到早的一个时间点(或者LSN);如果指定END_LSN为1,则表示还原到备份的时候,不会redo归档,可选参数。

BACKUP_DIR:备份文件存放路径,用于搜索备份文件(默认会搜索备份文件所在的目录,以及库的默认备份目录),可选参数

ARCHIVE_DIR:归档日志存放的目录,可以指定1~8个。在还原联机库备份且不带日志(WITHOUT LOG)的备份文件时,ARCHIVE_DIR为必选参数,可选参数。

DATAFIL_PATH:指定还原后的新文件路径([编号,路径],……,[编号,路径])。编号与路径成对出现,最多可以指定16个。编号为大于0的整数。MAPPED_FIL优先,可选参数。

PARALLEL_DIR:并行映射文件存放路径,用于搜索映射文件,可选参数

SHOW_BAK_INFO:可选值(0,1,2)0:表示利用备份还原;1:仅显示备份信息,不进行还原;2:表示使用归档日志进行还原;默认值为0。该参数已被RES_TYPE取代,为兼容之前版本,暂时保留。如果同时指定RES_TYPE和SHOW_BAK_INFO,则RES_TYPE有效,SHOW_BAK_INFO无效,可选参数。

RES_TYPE:可选值(0,1,2,3,4)0:表示利用备份还原;1:仅显示备份信息,不进行还原;2:表示使用归档日志进行还原;3:仅还原单个完全备份或者增量备份;4:仅仅输出备份文件映射信息到文件。默认值为0,可选参数。

MIRROR_PATH:指定备份库中的镜像文件路径在还原时的映射路径。([编号,路径],……,[编号,路径])。编号与路径成对出现,最多可以指定16个。编号为大于0的整数,映射路径绝对路径。MAPPED_FIL优先,可选参数。

LOG:指定一个文件,还原时日志会写入该文件,可选参数。

DUMMY:静默模式,可以指定{(Y)es,(N)o}。默认No。交互信息处理: 打印(P)。Y:打印所有交互信息。N:不打印交互信息。可选参数。

PASSWORD:还原时,指定备份时的加密密码

ENCRYPT_NAME:还原时用来解密的算法名。缺省算法为AES256_CFB

HELP:打印帮助信息

若设置SHOW_BAK_INFO参数为1,则不需要利用备份进行还原操作,可以不指定INI_PATH;指定了BACKUP_DIR参数时,则会收集备份目录下的所有的备份,并分组输出;如果指定了FILE,且该备份文件是增量备份,则会收集增量备份相关的所有备份输出。

数据库还原时,如果需要重做的日志量较大,将INI参数BUFFER适当设大,可以提高还原的性能。

2. 使用备份文件还原
例如,利用备份文件/dm_home/dmdba/dmdbms/data/jydm/bak/DB_jydm_20200711192046000434.bak还原数据库

[dmdba@shard1 backup]$ dmrestore ini_path=/dm_home/dmdba/dmdbms/data/jydm/dm.ini file=/dm_home/dmdba/dmdbms/data/jydm/bak/DB_jydm_20200711192046000434.bak
restore V7.1.6.46-Build(2018.02.08-89107)ENT
file dm.key not found, use default license!


backup sig:            BA
backup tool version:   12595
backup db name:        jydm
backup db magic:       -82313077
backup pemnt magic:    1250320462
backup name:           jydm
backup type:           full
backup level:          offline
backup range:          database
backup description:
compressed level:      0
encrypt_type:          0
encrypt_id:            2052
rac node:              0
page check:            0
rlog encrypt:          0
external cipher id:    0
external hash id:      0
length in char:        0
use new hash:          1
backup time:           2020-07-11 19:20:46
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
charset:               0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
mpp_timestamp:         0
crc_check:             TRUE
parallel type:         0
parallel info len:     0
backup db fil num:     8
archive flag:          1
after backup LSN:      27830642


$bak_seq |$file_path                                        |$size(K)       |$used(K)
        1|/dm_home/dmdba/dmdbms/data/jydm/bak/DB_jydm_20200711192046000434.bak|      294912.00|      284866.00


$file_seq |$type|$ts_name       |$state    |$size(K)  |$seq_in_bak    |$off_in_bak(B) |$len_in_bak(B) |$file_path                                        |$mirror_path
         1|DBF  |SYSTEM         |ONLINE    |     23552|              1|          43008|        6766592|/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF        |
         2|DBF  |ROLL           |ONLINE    |    229376|              1|        6809600|         401408|/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF          |
         3|DBF  |MAIN           |ONLINE    |    210944|              1|        7211008|      171753472|/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF          |
         4|DBF  |BOOKSHOP       |ONLINE    |    153600|              1|      178964480|         933888|/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF      |
         5|DBF  |DMHR           |ONLINE    |    131072|              1|      179898368|         425984|/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF          |
         6|DBF  |USERS          |ONLINE    |     51200|              1|      180324352|        1105920|/dm_home/dmdba/dmdbms/data/jydm/users01.dbf       |
         7|DBF  |SYSAUX         |ONLINE    |    179200|              1|      181430272|      110256128|/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF        |
         8|DBF  |FG_PERSON      |ONLINE    |    131072|              1|      291686400|          16384|/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF     |

Continue?[Y/N]:Y
restore bak_file: /dm_home/dmdba/dmdbms/data/jydm/bak/DB_jydm_20200711192046000434.bak ...
start restore database...
start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM), pages: 826
end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL), pages: 49
end restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN), pages: 20966
end restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP), pages: 114
end restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR), pages: 52
end restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS), pages: 135
end restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX), pages: 13459
end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX)
start restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON), pages: 2
end restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON)
end restore database data files.

Apply archive log LSN from 27830643 to 27830642, time used:0.000s.
restore finished, code = 0!

restore successfully!
restore time used: 7144.214(ms)



例如,利用归档文件/dm_home/dmdbms/backup/arch还原数据库,这里将使用备份文件还原新的目标库
1.先将原备份库的备份文件和归档文件复制到新还原库的主机上

[dmdba@shard1 backup]$ scp  -r /dm_home/dmdba/dmdbms/data/jydm/bak/DB_jydm_20200711192046000434.bak  dmdba@10.138.130.187:/dm_home/dmdbms/backup/
dmdba@10.138.130.187's password:
DB_jydm_20200711192046000434.bak                                                                                                                                                                          100%  288MB  96.0MB/s   00:03
[dmdba@shard1 backup]$ scp  -r /dm_home/dmdba/dmdbms/data/arch  dmdba@10.138.130.187:/dm_home/dmdbms/backup/
dmdba@10.138.130.187's password:
ARCHIVE_LOCAL1_20200603195207512_0.log                                                                                                                                                                    100%   84MB  21.0MB/s   00:04
ARCHIVE_LOCAL1_20200606020009584_0.log                                                                                                                                                                    100% 6588KB   6.4MB/s   00:00
ARCHIVE_LOCAL1_20200606061513930_0.log                                                                                                                                                                    100%   24KB  24.0KB/s   00:00
ARCHIVE_LOCAL1_20200606062617837_0.log                                                                                                                                                                    100% 7168     7.0KB/s   00:00
ARCHIVE_LOCAL1_20200606062943852_0.log                                                                                                                                                                    100%  300MB 100.0MB/s   00:03
ARCHIVE_LOCAL1_20200606142842948_0.log                                                                                                                                                                    100%  300MB 100.0MB/s   00:03
ARCHIVE_LOCAL1_20200606142846352_0.log                                                                                                                                                                    100%  300MB 100.0MB/s   00:03
ARCHIVE_LOCAL1_20200606142902741_0.log                                                                                                                                                                    100%  300MB  33.3MB/s   00:09
ARCHIVE_LOCAL1_20200606142909259_0.log                                                                                                                                                                    100%  300MB 150.0MB/s   00:02
ARCHIVE_LOCAL1_20200606220653158_0.log                                                                                                                                                                    100%  300MB  50.0MB/s   00:06
ARCHIVE_LOCAL1_20200613210000757_0.log                                                                                                                                                                    100%  300MB  14.3MB/s   00:21
ARCHIVE_LOCAL1_20200617093523748_0.log                                                                                                                                                                    100%   32MB   7.9MB/s   00:04
ARCHIVE_LOCAL1_20200617161801000_0.log                                                                                                                                                                    100% 3926KB   3.8MB/s   00:00
ARCHIVE_LOCAL1_20200617170101954_0.log                                                                                                                                                                    100% 1464KB   1.4MB/s   00:00
ARCHIVE_LOCAL1_20200617173005734_0.log                                                                                                                                                                    100% 8583KB   8.4MB/s   00:01
ARCHIVE_LOCAL1_20200617190859140_0.log                                                                                                                                                                    100%   20MB  20.1MB/s   00:01
ARCHIVE_LOCAL1_20200622160035411_0.log                                                                                                                                                                    100%  220KB 220.0KB/s   00:00
ARCHIVE_LOCAL1_20200623172303743_0.log                                                                                                                                                                    100%  300MB  11.1MB/s   00:27
ARCHIVE_LOCAL1_20200624180051432_0.log                                                                                                                                                                    100%  300MB  10.7MB/s   00:28
ARCHIVE_LOCAL1_20200626193023317_0.log                                                                                                                                                                    100%  300MB  10.7MB/s   00:28
ARCHIVE_LOCAL1_20200630024319628_0.log                                                                                                                                                                    100%   47MB   9.5MB/s   00:05
ARCHIVE_LOCAL1_20200630173436447_0.log                                                                                                                                                                    100%   39MB   9.6MB/s   00:04
ARCHIVE_LOCAL1_20200706091427214_0.log                                                                                                                                                                    100%  300MB   9.7MB/s   00:31
ARCHIVE_LOCAL1_20200710110030273_0.log                                                                                                                                                                    100%  113MB   8.7MB/s   00:13
ARCHIVE_LOCAL1_20200606062454805_0.log                                                                                                                                                                    100% 7680     7.5KB/s   00:00
ARCHIVE_LOCAL1_20200606062942967_0.log                                                                                                                                                                    100% 7680     7.5KB/s   00:00
ARCHIVE_LOCAL1_20200606064235117_0.log                                                                                                                                                                    100%   16KB  15.5KB/s   00:00
ARCHIVE_LOCAL1_20200606142853068_0.log                                                                                                                                                                    100%  300MB  10.0MB/s   00:30
ARCHIVE_LOCAL1_20200606142906087_0.log                                                                                                                                                                    100%  300MB  23.1MB/s   00:13
ARCHIVE_LOCAL1_20200606142912805_0.log                                                                                                                                                                    100% 5120     5.0KB/s   00:00
ARCHIVE_LOCAL1_20200617193955110_0.log                                                                                                                                                                    100%   83MB  10.4MB/s   00:08
ARCHIVE_LOCAL1_20200622160200765_0.log                                                                                                                                                                    100%  234KB 234.0KB/s   00:00
ARCHIVE_LOCAL1_20200711193829081_0.log                                                                                                                                                                    100%  300MB  13.6MB/s   00:22
[dmdba@shard1 backup]$

[dmdba@dmks backup]$ ls -lrt

drwxr-xr-x. 2 dmdba dinstall      4096 7月  11 19:47 arch
-rw-r--r--. 1 dmdba dinstall  33554432 7月  11 19:50 DB_dmks_FULL_2020_07_11_19_50_30.bak

2.使用原备份库还原新库

[dmdba@dmks backup]$ dmrestore ini_path=/dm_home/dmdbms/data/dameng_for_recover/dm.ini file=/dm_home/dmdbms/backup/DB_jydm_20200711192046000434.bak
restore V7.1.6.46-Build(2018.02.08-89107)ENT
file dm.key not found, use default license!


backup sig:            BA
backup tool version:   12595
backup db name:        jydm
backup db magic:       -82313077
backup pemnt magic:    1250320462
backup name:           jydm
backup type:           full
backup level:          offline
backup range:          database
backup description:
compressed level:      0
encrypt_type:          0
encrypt_id:            2052
rac node:              0
page check:            0
rlog encrypt:          0
external cipher id:    0
external hash id:      0
length in char:        0
use new hash:          1
backup time:           2020-07-11 19:20:46
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
charset:               0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
mpp_timestamp:         0
crc_check:             TRUE
parallel type:         0
parallel info len:     0
backup db fil num:     8
archive flag:          1
after backup LSN:      27830642


$bak_seq |$file_path                                        |$size(K)       |$used(K)
        1|/dm_home/dmdbms/backup/DB_jydm_20200711192046000434.bak|      294912.00|      284866.00


$file_seq |$type|$ts_name       |$state    |$size(K)  |$seq_in_bak    |$off_in_bak(B) |$len_in_bak(B) |$file_path                                        |$mirror_path
         1|DBF  |SYSTEM         |ONLINE    |     23552|              1|          43008|        6766592|/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF        |
         2|DBF  |ROLL           |ONLINE    |    229376|              1|        6809600|         401408|/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF          |
         3|DBF  |MAIN           |ONLINE    |    210944|              1|        7211008|      171753472|/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF          |
         4|DBF  |BOOKSHOP       |ONLINE    |    153600|              1|      178964480|         933888|/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF      |
         5|DBF  |DMHR           |ONLINE    |    131072|              1|      179898368|         425984|/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF          |
         6|DBF  |USERS          |ONLINE    |     51200|              1|      180324352|        1105920|/dm_home/dmdba/dmdbms/data/jydm/users01.dbf       |
         7|DBF  |SYSAUX         |ONLINE    |    179200|              1|      181430272|      110256128|/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF        |
         8|DBF  |FG_PERSON      |ONLINE    |    131072|              1|      291686400|          16384|/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF     |

Continue?[Y/N]:Y
Warning: Backup file may has been modified !

Continue?[Y/N]:Y
restore bak_file: /dm_home/dmdbms/backup/DB_jydm_20200711192046000434.bak ...
start restore database...
start restore file: /dm_home/dmdbms/data/dameng_for_recover/SYSTEM.DBF(SYSTEM), pages: 826
end restore file: /dm_home/dmdbms/data/dameng_for_recover/SYSTEM.DBF(SYSTEM)
start restore file: /dm_home/dmdbms/data/dameng_for_recover/ROLL.DBF(ROLL), pages: 49
end restore file: /dm_home/dmdbms/data/dameng_for_recover/ROLL.DBF(ROLL)
start restore file: /dm_home/dmdbms/data/dameng_for_recover/MAIN.DBF(MAIN), pages: 20966
end restore file: /dm_home/dmdbms/data/dameng_for_recover/MAIN.DBF(MAIN)
start restore file: /dm_home/dmdbms/data/dameng_for_recover/BOOKSHOP.DBF(BOOKSHOP), pages: 114
end restore file: /dm_home/dmdbms/data/dameng_for_recover/BOOKSHOP.DBF(BOOKSHOP)
start restore file: /dm_home/dmdbms/data/dameng_for_recover/DMHR.DBF(DMHR), pages: 52
end restore file: /dm_home/dmdbms/data/dameng_for_recover/DMHR.DBF(DMHR)
start restore file: /dm_home/dmdbms/data/dameng_for_recover/users01.dbf(USERS), pages: 135
end restore file: /dm_home/dmdbms/data/dameng_for_recover/users01.dbf(USERS)
start restore file: /dm_home/dmdbms/data/dameng_for_recover/SYSAWR.DBF(SYSAUX), pages: 13459
end restore file: /dm_home/dmdbms/data/dameng_for_recover/SYSAWR.DBF(SYSAUX)
start restore file: /dm_home/dmdbms/data/dameng_for_recover/FG_PERSON.DBF(FG_PERSON), pages: 2
end restore file: /dm_home/dmdbms/data/dameng_for_recover/FG_PERSON.DBF(FG_PERSON)
end restore database data files.

Apply archive log LSN from 27830643 to 27830642, time used:0.000s.
restore finished, code = 0!

restore successfully!
restore time used: 44867.245(ms)

使用备份文件还原数据库归档日志LSN为27830643
3.使用dmmdbf工具查看原备份库中的db_magic为1371967312

[dmdba@shard1 backup]$ dmmdf type=1 file=/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF
dmmdf V7.1.6.46-Build(2018.02.08-89107)ENT
**********************************************************
1 db_magic=1371967312
2 next_trxid=3377415
3 pemnt_magic=1250320462
**********************************************************
Please input which parameter you want to change(1-3), q to quit: q

4.使用dmmdf工具查看目标库的system.dbf的db_magic并进行修改1371967312

[dmdba@dmks dameng_for_recover]$ dmmdf type=1 file=/dm_home/dmdbms/data/dameng_for_recover/SYSTEM.DBF
dmmdf V7.1.6.46-Build(2018.02.08-89107)ENT
**********************************************************
1 db_magic=-82313077
2 next_trxid=3377415
3 pemnt_magic=1250320462
**********************************************************
Please input which parameter you want to change(1-3), q to quit: 1
Please input new value: 1371967312
**********************************************************
1 db_magic=1371967312
2 next_trxid=3377415
3 pemnt_magic=1250320462
**********************************************************
Do you want to save the change to file (y/n): y
Save to file success!

5.使用dmmdf工具查看目标库的dameng_for_recover01.log和dameng_for_recover02.log的db_magic并进行修改-82313077

[dmdba@dmks dameng_for_recover]$ dmmdf type=2 file=/dm_home/dmdbms/data/dameng_for_recover/dameng_for_recover01.log
dmmdf V7.1.6.46-Build(2018.02.08-89107)ENT
**********************************************************
1 sig = DMRLOG
2 ver = 7004
3 chksum = 0
4 dbversion = 0x7000a
5 sta = 0
6 n_magic = 35
7 db_magic = -82313077
8 clsn_fil = 0
10 next_seq = 304
11 arch_seq = 0
12 len = 268435456
13 free = 4096
14 clsn = 27830642
15 clsn_off = 4096
16 arch_lsn = 0
17 pemnt_magic = 1250320462
18 fil_id = 0
19 crc_check = 1
**********************************************************
You can only reset sta(5) or db_magic (7) or clsn (14) or pemnt_magic(17) or fil_id(18).
Please input the num which one you want to change, q to quit: 7
Input the new value: 1371967312
**********************************************************
1 sig = DMRLOG
2 ver = 7004
3 chksum = 0
4 dbversion = 0x7000a
5 sta = 0
6 n_magic = 35
7 db_magic = 1371967312
8 clsn_fil = 0
10 next_seq = 304
11 arch_seq = 0
12 len = 268435456
13 free = 4096
14 clsn = 27830642
15 clsn_off = 4096
16 arch_lsn = 0
17 pemnt_magic = 1250320462
18 fil_id = 0
19 crc_check = 1
**********************************************************
Do you want to quit and save the change to file (y/n): y
Save to file success!
[dmdba@dmks dameng_for_recover]$ dmmdf type=2 file=/dm_home/dmdbms/data/dameng_for_recover/dameng_for_recover02.log
dmmdf V7.1.6.46-Build(2018.02.08-89107)ENT
**********************************************************
1 sig = DMRLOG
2 ver = 7004
3 chksum = 0
4 dbversion = 0x7000a
5 sta = 0
6 n_magic = 35
7 db_magic = -82313077
8 clsn_fil = 0
10 next_seq = 0
11 arch_seq = 0
12 len = 268435456
13 free = 4096
14 clsn = 0
15 clsn_off = 0
16 arch_lsn = 0
17 pemnt_magic = 1250320462
18 fil_id = 1
19 crc_check = 1
**********************************************************
You can only reset sta(5) or db_magic (7) or clsn (14) or pemnt_magic(17) or fil_id(18).
Please input the num which one you want to change, q to quit: 7
Input the new value: 1371967312
**********************************************************
1 sig = DMRLOG
2 ver = 7004
3 chksum = 0
4 dbversion = 0x7000a
5 sta = 0
6 n_magic = 35
7 db_magic = 1371967312
8 clsn_fil = 0
10 next_seq = 0
11 arch_seq = 0
12 len = 268435456
13 free = 4096
14 clsn = 0
15 clsn_off = 0
16 arch_lsn = 0
17 pemnt_magic = 1250320462
18 fil_id = 1
19 crc_check = 1
**********************************************************
Do you want to quit and save the change to file (y/n): y
Save to file success!

6.使用归档文件还原数据库

[dmdba@dmks backup]$ dmrestore ini_path=/dm_home/dmdbms/data/dameng_for_recover/dm.ini archive_dir=(/dm_home/dmdbms/backup/arch) show_bak_info=2
-bash: syntax error near unexpected token `('

[dmdba@dmks backup]$ dmrestore ini_path=/dm_home/dmdbms/data/dameng_for_recover/dm.ini archive_dir=\(/dm_home/dmdbms/backup/arch\) show_bak_info=2
restore V7.1.6.46-Build(2018.02.08-89107)ENT
file dm.key not found, use default license!

Continue?[Y/N]:Y
try to apply archive log from LSN: 27830642 to LSN: 9223372036854775807.

Apply archive log LSN from 27830643 to 27832982, time used:2.811s.

restore successfully!
restore time used: 3840.401(ms)
[dmdba@dmks backup]$

使用归档文件还原数据库归档日志LSN从27830643(因为使用数据库备份文件还原数据库时LSN27830643)为应用到了27832982。

7.启动恢复目标库

[root@dmks init.d]# service DmServicedmrc start
Starting DmServicedmrc: [ OK ]

[dmdba@dmks dameng_for_recover]$ cat dm.ini | grep PORT_NUM
                PORT_NUM                        =  5336                 #Port number on which the database server will listen
                DCP_PORT_NUM                    =  5237                 #Port number on which DCP will listen
[dmdba@dmks dameng_for_recover]$ disql sysdba/xxzx7817600@localhost:5336

Server[localhost:5336]:mode is normal, state is open
login used time: 19.135(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46
SQL> select * from t1;

LINEID     C1          C2
---------- ----------- -----------
1          1           1
2          2           2
3          3           3
4          4           4
5          5           5

used time: 1.767(ms). Execute id is 4.
SQL> select * from t1;

LINEID     C1          C2
---------- ----------- -----------
1          1           1
2          2           2
3          3           3
4          4           4
5          5           5

used time: 16.368(ms). Execute id is 4733.

原库

SQL> select * from t1;

LINEID     C1          C2
---------- ----------- -----------
1          1           1
2          2           2
3          3           3
4          4           4
5          5           5

used time: 16.368(ms). Execute id is 4733.
Proudly powered by WordPress | Indrajeet by Sus Hill.