DM7使用DMRAMN执行归档恢复

使用DMRAMN执行归档恢复
使用RECOVER命令完成数据库恢复工作,可以是基于备份集的恢复工作,也可以是使用本地归档日志的恢复工作。如果还原后,数据已经处于一致性状态了,则可以使用更新DB_MAGIC方式恢复,前提是不需要重做日志。语法如下:

RECOVER DATABASE '' []
[USE DB_MAGIC ] [UNTIL TIME '< 时间串>'] [UNTIL LSN ]; |
RECOVER DATABASE '' FROM BACKUPSET '< 备份集目录>'[DEVICE TYPE DISK|TAPE[PARMS '< 介质参数>']] [IDENTIFIED BY
< 密码> [ENCRYPT WITH < 加密算法>]]
; |
RECOVER DATABASE '' UPDATE DB_MAGIC;
 ::=
WITH ARCHIVEDIR '< 归档日志目录>'{,'< 归档日志目录>'}

DATABASE:指定还原库目标的dm.ini文件路径。
USE DB_MAGIC:指定本地归档日志对应数据库的DB_MAGIC,若不指定,则默认使用目标恢复数据库的DB_MAGIC。
UNTIL TIME:恢复数据库到指定的时间点。
UNTIL LSN:恢复数据库到指定的LSN。
BACKUPSET:指定用于还原目标数据库的备份集目录。
DEVICE TYPE:指存储备份集的介质类型,支持DISK和TAPE,默认为DISK。DISK表示存储备份集到磁盘,TAPE表示存储到磁带。
PARMS:介质参数,供第三方存储介质(TAPE类型)管理使用。
IDENTIFIED BY:指定备份时使用的加密密码,供还原过程解密使用。
ENCRYPT WITH:指定备份时使用的加密算法,供还原过程解密使用,若未指定,则使用默认算法。
WITH ARCHIVEDIR:本地归档日志搜索目录,若未指定,则仅使用目标库配置本地归档目录,RAC环境还会取REMOTE归档目录。

数据库恢复有三种方式:更新DB_MAGIC恢复、从备份集恢复和从归档恢复。

从归档恢复
从归档恢复是利用重做本地归档日志来恢复数据的过程。从归档恢复允许恢复到指定的时间点及指定的LSN值。若同时指定了时间点和LSN,则以较早的为结束点。

由于从本地归档恢复允许使用USE DB_MAGIC指定待收集归档的DB_MAGIC,那么就会存在跨库恢复情况,所以,归档日志的正确使用完全由用户保证。因此,为了保证用户能正确使用从归档恢复,除了下文这两种情况,其他情况(可能导致数据被破坏)不建议用户使用从本地归档恢复。

可以使用从归档恢复的情况:
1、执行过从备份集还原,以及执行过从备份集还原恢复的库,本地归档日志属于备份集备份时的库,本地归档日志的DB_MAGIC与备份集中记录DB_MAGIC值;
2、未执行过还原的库,但恢复目标库与本地归档日志来源于同一个库,且目标库与原来的库分离后没有再单独执行过操作或者故障重启过。比如一个数据库A因故障关闭后,拷贝一份作为数据库B,此时数据库A和B完全相同。此后,数据库A故障重启,并正常执行其他操作,生成了新的本地归档日志。如果想利用A的本地归档日志去将B恢复到A的状态,那么可以利用DMRMAN工具执行从本地归档恢复。若中间B启动过或者执行过其他操作,则均不能再使用A的归档日志进行恢复操作。

利用归档恢复数据库至最新状态的完整示例如下:

1) 启动DIsql联机备份数据库,以及备份到检查点结束为止的本地归档日志。
查看动态视图V$RLOG中的CKPT_LSN列,可以得出当前检查点LSN。

SQL> select * from t1;

LINEID     C1          C2
---------- ----------- -----------
1          1           1
2          2           2
3          3           3

used time: 83.467(ms). Execute id is 866393.
SQL> select ckpt_lsn from v$rlog;

LINEID     CKPT_LSN
---------- --------------------
1          19738189

used time: 0.817(ms). Execute id is 866466.
SQL> backup archivelog until lsn 19738189 backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/arch_bak_lsn_to_19738189';
executed successfully
used time: 00:00:43.255. Execute id is 866619.
SQL> backup database full backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_bak_recover_arch';
executed successfully
used time: 00:00:12.873. Execute id is 866805.

2) 准备目标库,可以使用备份库,也可以重新生成库。
如果使用原备份库,且备份库故障,需要先执行目标库归档修复:

RMAN>REPAIR ARCHIVELOG DATABASE 'opt/dmdbms/data/dm.ini';

如果使用新生成的库,生成之后需要先重启一下服务器,才可以被还原。重新生成的库不需要执行归档修复(repair)操作。重新生成库操作如下:

[dmdba@dmks ~]$ dminit path=/dm_home/dmdbms/data db_name=dameng_for_recover auto_overwrite=1 port_num=5336
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-06-30

 log file path: /dm_home/dmdbms/data/dameng_for_recover/dameng_for_recover01.log


 log file path: /dm_home/dmdbms/data/dameng_for_recover/dameng_for_recover02.log

write to dir [/dm_home/dmdbms/data/dameng_for_recover].
create dm database success. 2020-06-16 16:03:18


[root@dmks root]# ./dm_service_installer.sh  -i /dm_home/dmdbms/data/dameng_for_recover/dm.ini -p dmrc -t dmserver
Move the service script file(/dm_home/dmdbms/bin/DmServicedmrc to /etc/rc.d/init.d/DmServicedmrc)
Finished to create the service (DmServicedmrc)

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


[dmdba@dmks ~]$ disql SYSDBA/SYSDBA@localhost:5336

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

LINEID     PERMANENT_MAGIC
---------- ---------------
1          450923536

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

LINEID     DB_MAGIC
---------- -----------
1          1009602608

used time: 1.332(ms). Execute id is 6.
3) 启动RMAN,校验备份。
RMAN> check backupset '/dm_home/dmdbms/backup/db_bak_recover_arch';
check backupset '/dm_home/dmdbms/backup/db_bak_recover_arch';
CMD END.CODE:[0]
check backupset successfully.
time used: 5.986(ms)
RMAN> check backupset '/dm_home/dmdbms/backup/arch_bak';
check backupset '/dm_home/dmdbms/backup/arch_bak';
CMD END.CODE:[0]
check backupset successfully.
time used: 7.154(ms)

4) 还原数据库。

RMAN> restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_bak_recover_arch';
restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_bak_recover_arch';
file dm.key not found, use default license!
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[4].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[3].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[2].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[1].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[0].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running, write dmrman info.
RESTORE DATABASE  CHECK......
RESTORE DATABASE , dbf collect......
RESTORE DATABASE , dbf refresh ......
RESTORE BACKUPSET [/dm_home/dmdbms/backup/db_bak_recover_arch] START......
total 22 packages processed...
RESTORE DATABASE , UPDATE ctl file......
RESTORE DATABASE , REBUILD key file......
RESTORE DATABASE , CHECK db info......
RESTORE DATABASE , UPDATE db info......
total 26 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 68070.231(ms)

5)还原归档日志

RMAN> restore archive log from backupset '/dm_home/dmdbms/backup/arch_bak'to archivedir '/dm_home/dmdbms/backup/arch';
restore archive log from backupset '/dm_home/dmdbms/backup/arch_bak' to archivedir '/dm_home/dmdbms/backup/arch';
RESTORE ARCHIVE CHECK......
RESTORE ARCHIVE, dbf collect......
RESTORE ARCHIVE, dbf refresh ......
RESTORE BACKUPSET [/dm_home/dmdbms/backup/arch_bak] START......
total 60 packages processed...
total 61 packages processed...
total 62 packages processed!
CMD END.CODE:[0]

restore successfully.
time used: 38325.097(ms)

6)查看备份集的数据库信息,获取源库的DB_MAGIC。

RMAN> show backupset '/dm_home/dmdbms/backup/db_bak_recover_arch';
show backupset '/dm_home/dmdbms/backup/db_bak_recover_arch';




system path:           /dm_home/dmdba/dmdbms/data/jydm
db magic:              708657636
permanent magic:       1250320462
rac node:              1
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         jydm
backup name:           DB_FULL_jydm_20200617_172643_000246
backupset description:
backupset ID :         1563647712
parent backupset ID:     -1
META file size :       94720
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1592386003
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
START_LSN:             19751828
START_SEQ:             7739639
END_LSN:               19752212
END_SEQ:               7739836
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-06-17 17:26:55
min trx start lsn:     16553039
min exec ver:          0x0701060C
pkg size:              0x02000000


backupset directory: /dm_home/dmdbms/backup/db_bak_recover_arch
backupset name:        db_bak_recover_arch
backup data file num:  9
backup piece num:      2


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |407807    |db_bak_recover_arch.bak                                 |DATA
1         |104       |db_bak_recover_arch_1.bak                               |LOG


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
1         |0         |SYSTEM                           |0         |/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF|                                 |24117248
2         |1         |ROLL                             |0         |/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF|                                 |208666624
3         |4         |MAIN                             |0         |/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF|                                 |197132288
4         |5         |BOOKSHOP                         |0         |/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF|                                 |157286400
5         |6         |DMHR                             |0         |/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF|                                 |134217728
6         |7         |USERS                            |0         |/dm_home/dmdba/dmdbms/data/jydm/users01.dbf|                                 |52428800
7         |9         |SYSAUX                           |0         |/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF|                                 |175112192
8         |10        |FG_PERSON                        |0         |/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF|                                 |134217728


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time
9         |                                 |101376              |19751827            |7739639             |8                   |19752212            |7739836             |0000-00-00 00:00:00 |0000-00-00 00:00:00


show backupsets successfully.
time used: 5.320(ms)

RMAN> show backupset '/dm_home/dmdbms/backup/arch_bak';
show backupset '/dm_home/dmdbms/backup/arch_bak';




system path:           /dm_home/dmdba/dmdbms/data/jydm
db magic:              708657636
permanent magic:       1250320462
rac node:              1
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         jydm
backup name:           ARCH_20200617_173005_000673
backupset description:
backupset ID :         -99299676
parent backupset ID:     -1
META file size :       135680
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          archivelog
mpp_timestamp:         1592386205
arch start lsn:        13775970
arch end lsn:          19752806
backup level:          online
backup type:           archive
without log:           TRUE
START_LSN:             19752785
START_SEQ:             7740126
END_LSN:               19752968
END_SEQ:               7740221
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-06-17 17:30:45
min trx start lsn:     16553039
min exec ver:          0x0701060C
pkg size:              0x02000000


backupset directory: /dm_home/dmdbms/backup/arch_bak
backupset name:        arch_bak
backup data file num:  20
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |1501420   |arch_bak.bak                                            |LOG


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time
1         |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200526003546144_0.log|314496512           |13775970            |4737535             |8                   |14461220            |0                   |2020-05-26 00:35:46 |2020-05-26 00:36:31
2         |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200526003632028_0.log|271943680           |14461221            |5351778             |8                   |14942037            |0                   |2020-05-26 00:36:31 |2020-05-28 23:07:46
3         |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200528230749046_0.log|18832384            |14942037            |5882910             |8                   |15088441            |0                   |2020-05-28 23:07:46 |2020-05-29 18:43:51
4         |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200529184351533_0.log|444416              |15088442            |5919684             |8                   |15092081            |0                   |2020-05-29 18:43:51 |2020-05-29 19:37:55
5         |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200529193755551_0.log|5632                |15092082            |5920544             |8                   |15092086            |0                   |2020-05-29 19:37:55 |2020-05-29 19:39:25
6         |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200529193925775_0.log|16965120            |15092086            |5920547             |8                   |15220690            |0                   |2020-05-29 19:39:25 |2020-05-30 14:28:56
7         |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200530142857037_0.log|152148480           |15220691            |5953674             |8                   |16361831            |0                   |2020-05-30 14:28:56 |2020-06-03 19:51:50
8         |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200603195207512_0.log|88146944            |16361832            |6250831             |8                   |17046028            |0                   |2020-06-03 19:51:50 |2020-06-06 02:00:09
9         |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200606020009584_0.log|6746112             |17046029            |6422985             |8                   |17088792            |0                   |2020-06-06 02:00:09 |2020-06-06 06:13:36
10        |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200606061513930_0.log|24576               |17088793            |6436153             |8                   |17088875            |0                   |2020-06-06 06:13:36 |2020-06-06 06:24:48
11        |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200606062454805_0.log|7680                |17088876            |6436193             |8                   |17088886            |0                   |2020-06-06 06:24:48 |2020-06-06 06:26:17
12        |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200606062617837_0.log|7168                |17088886            |6436200             |8                   |17088896            |0                   |2020-06-06 06:26:17 |2020-06-06 06:27:51
13        |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200606062942967_0.log|7680                |17088896            |6436206             |8                   |17088905            |0                   |2020-06-06 06:27:51 |2020-06-06 06:29:43
14        |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200606064235117_0.log|15872               |17088906            |6436213             |8                   |17088950            |0                   |2020-06-06 06:29:43 |2020-06-06 13:11:01
15        |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200606142912805_0.log|5120                |17088951            |6436236             |8                   |17088956            |0                   |2020-06-06 13:11:01 |2020-06-06 14:29:13
16        |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200606220653158_0.log|314339328           |17088957            |6436238             |8                   |18425990            |0                   |2020-06-06 14:29:13 |2020-06-13 21:00:00
17        |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200613210000757_0.log|314571264           |18425991            |7050174             |8                   |19599505            |0                   |2020-06-13 21:00:00 |2020-06-17 09:35:23
18        |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200617093523748_0.log|33190912            |19599505            |7664563             |8                   |19731163            |0                   |2020-06-17 09:35:23 |2020-06-17 16:18:01
19        |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200617161801000_0.log|4020224             |19731163            |7729381             |8                   |19747260            |0                   |2020-06-17 16:18:01 |2020-06-17 17:01:01
20        |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200617170101954_0.log|1499136             |19747260            |7737225             |8                   |19752806            |0                   |2020-06-17 17:01:01 |2020-06-17 17:30:05


show backupsets successfully.
time used: 25.316(ms)

若还原后,立即执行执行恢复,可以不用获取源库DB_MAGIC。因为DMRMAN执行库级备份集还原后,会将备份集中的DB_MAGIC刷入还原后的库中。

7>利用归档恢复数据库。由步骤6显示的备份集信息可知,源库的DB_MAGIC值为1447060265。

RMAN> recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' with archivedir '/dm_home/dmdbms/backup/arch' use db_magic 708657636;
recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' with archivedir '/dm_home/dmdbms/backup/arch' use db_magic 708657636;
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[4].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[3].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[2].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[1].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[0].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running, write dmrman info.
EP[0] max_lsn: 19751827

EP[0] Recover LSN from 19751828 to 19752806.
Recover from archive log finished, time used:0.165s.
recover successfully!
time used: 7051.292(ms)

8)检查目标库中的表t1确认数据与源数据库一致。

SQL> select * from t1;

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

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

9)在源数据库的t1表中插入一行数据

SQL> select * from t1;

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

used time: 0.779(ms). Execute id is 879030.
SQL> insert into t1 values(5,5);
affect rows 1

used time: 1.188(ms). Execute id is 879204.
SQL> commit;
executed successfully
used time: 13.572(ms). Execute id is 879210.
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.590(ms). Execute id is 879218.

10)在源数据库中备份归档日志,从lsn为19752806开始进行备份,因为之前备份的归档日志最大lsn为19752806,将将备份文件传到目标数据库上

SQL> backup archivelog from lsn 19752806 backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/arch_bak_from_19752806';
executed successfully
used time: 00:00:01.850. Execute id is 879461.


[dmdba@shard1 bak]$ scp -r arch_bak_from_19752806 dmdba@10.138.130.187:/dm_home/dmdbms/backup/
dmdba@10.138.130.187's password:
arch_bak_from_19752806.bak                                                                                                                                                                                100%   10MB   9.8MB/s   00:00
arch_bak_from_19752806.meta                                                                                                                                                                               100%   61KB  60.5KB/s   00:00
[dmdba@shard1 bak]$

11)检查备份的归档日志

RMAN> check backupset '/dm_home/dmdbms/backup/arch_bak_from_19752806';
check backupset '/dm_home/dmdbms/backup/arch_bak_from_19752806';
CMD END.CODE:[0]
check backupset successfully.
time used: 7.121(ms)

12)查看备份集信息,获取源库的DB_MAGIC

RMAN> show backupset '/dm_home/dmdbms/backup/arch_bak_from_19752806';
show backupset '/dm_home/dmdbms/backup/arch_bak_from_19752806';




system path:           /dm_home/dmdba/dmdbms/data/jydm
db magic:              708657636
permanent magic:       1250320462
rac node:              1
page check:            0
rlog encrypt:          0
external cipher[id/name]:  0/
external hash[id/name]:  0/
length in char:        0
use new hash:          1
page size:             8 KB
extent size:           16
case sensitive:        1
log page size:         512 B
unicode_flag/charset:  0
data version:          0x7000A
sys version:           V7.1.6.46-Build(2018.02.08-89107)ENT
enable policy:         0
archive flag:          1
blank_pad_mode:        0
crc_check:             TRUE


backupset sig:         BA
backupset version:     4009
database name:         jydm
backup name:           ARCH_20200617_190859_000032
backupset description:
backupset ID :         -1402072600
parent backupset ID:     -1
META file size :       61952
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          archivelog
mpp_timestamp:         1592392139
arch start lsn:        19747260
arch end lsn:          19787571
backup level:          online
backup type:           archive
without log:           TRUE
START_LSN:             19786788
START_SEQ:             7756899
END_LSN:               19787571
END_SEQ:               7757301
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-06-17 19:09:00
min trx start lsn:     16553039
min exec ver:          0x0701060C
pkg size:              0x02000000


backupset directory: /dm_home/dmdbms/backup/arch_bak_from_19752806
backupset name:        arch_bak_from_19752806
backup data file num:  2
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |10052     |arch_bak_from_19752806.bak                              |LOG


$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len


$file_seq |$file_path                       |$file_len           |$begin_lsn          |$begin_seqno        |$begin_rpag_off     |$end_lsn            |$end_seqno          |$create_time        |$close_time
1         |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200617170101954_0.log|1499136             |19747260            |7737225             |8                   |19752806            |0                   |2020-06-17 17:01:01 |2020-06-17 17:30:05
2         |/dm_home/dmdba/dmdbms/data/arch/ARCHIVE_LOCAL1_20200617173005734_0.log|8788480             |19752806            |7740145             |8                   |19787571            |0                   |2020-06-17 17:30:05 |2020-06-17 19:08:59


show backupsets successfully.
time used: 6.440(ms)

13)还原最新生成的备份归档日志

RMAN> restore archive log from backupset '/dm_home/dmdbms/backup/arch_bak_from_19752806' to archivedir '/dm_home/dmdbms/backup/arch';
restore archive log from backupset '/dm_home/dmdbms/backup/arch_bak_from_19752806' to archivedir '/dm_home/dmdbms/backup/arch';
RESTORE ARCHIVE CHECK......
RESTORE ARCHIVE, dbf collect......
RESTORE ARCHIVE, dbf refresh ......
RESTORE BACKUPSET [/dm_home/dmdbms/backup/arch_bak_from_19752806] START......
total 1 packages processed...
total 2 packages processed!
CMD END.CODE:[0]

restore successfully.
time used: 317.745(ms)

14)使用之前的数据库备份集还原目标数据库

RMAN> restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_bak_recover_arch';
restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_bak_recover_arch';
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[4].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[3].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[2].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[1].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[0].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running, write dmrman info.
RESTORE DATABASE  CHECK......
RESTORE DATABASE , dbf collect......
RESTORE DATABASE , dbf refresh ......
RESTORE BACKUPSET [/dm_home/dmdbms/backup/db_bak_recover_arch] START......
total 22 packages processed...
RESTORE DATABASE , UPDATE ctl file......
RESTORE DATABASE , REBUILD key file......
RESTORE DATABASE , CHECK db info......
RESTORE DATABASE , UPDATE db info......
total 26 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 29783.391(ms)

15)使用归档日志执行恢复

RMAN> recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' with archivedir '/dm_home/dmdbms/backup/arch' use db_magic 708657636;
recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' with archivedir '/dm_home/dmdbms/backup/arch' use db_magic 708657636;
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[4].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[3].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[2].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[1].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[0].
checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running, write dmrman info.
EP[0] max_lsn: 19751827

total redo pages:2920


EP[0] Recover LSN from 19751828 to 19787571.
Recover from archive log finished, time used:1.503s.
recover successfully!
time used: 8275.787(ms)
RMAN>

16)启动数据数据库检查表t1的数据

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

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.662(ms). Execute id is 5.

17) 若执行后归档恢复过程中,出现归档不足的错误,则利用归档校验工具dmrachk,查看归档目录中归档连续性情况,然后再利用备份的
本地归档日志,还原到归档目录后,再次执行恢复操作

[dmdba@dmks backup]$ dmrachk arch_path=/dm_home/dmdbms/backup/arch
rachk V7.1.6.46-Build(2018.02.08-89107)ENT
the database db_magic: 708657636
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200526003546144_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 614243
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 13775970
arch_seq       : 4737535
clsn           : 14461220
next_seq       : 5351777
file len       : 314496512
file free      : 314496512
create time    : 2020-05-26 00:35:46
close time     : 2020-05-26 00:36:31
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200526003632028_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 531132
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 14461221
arch_seq       : 5351778
clsn           : 14942037
next_seq       : 5882909
file len       : 271943680
file free      : 271943680
create time    : 2020-05-26 00:36:31
close time     : 2020-05-28 23:07:46
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200528230749046_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 36774
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 14942037
arch_seq       : 5882910
clsn           : 15088441
next_seq       : 5919683
file len       : 18832384
file free      : 18832384
create time    : 2020-05-28 23:07:46
close time     : 2020-05-29 18:43:51
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200529184351533_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 860
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 15088442
arch_seq       : 5919684
clsn           : 15092081
next_seq       : 5920543
file len       : 444416
file free      : 444416
create time    : 2020-05-29 18:43:51
close time     : 2020-05-29 19:37:55
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200529193755551_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 3
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 15092082
arch_seq       : 5920544
clsn           : 15092086
next_seq       : 5920546
file len       : 5632
file free      : 5632
create time    : 2020-05-29 19:37:55
close time     : 2020-05-29 19:39:25
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200529193925775_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 33127
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 15092086
arch_seq       : 5920547
clsn           : 15220690
next_seq       : 5953673
file len       : 16965120
file free      : 16965120
create time    : 2020-05-29 19:39:25
close time     : 2020-05-30 14:28:56
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200530142857037_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 297157
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 15220691
arch_seq       : 5953674
clsn           : 16361831
next_seq       : 6250830
file len       : 152148480
file free      : 152148480
create time    : 2020-05-30 14:28:56
close time     : 2020-06-03 19:51:50
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200603195207512_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 172154
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 16361832
arch_seq       : 6250831
clsn           : 17046028
next_seq       : 6422984
file len       : 88146944
file free      : 88146944
create time    : 2020-06-03 19:51:50
close time     : 2020-06-06 02:00:09
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200606020009584_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 13168
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 17046029
arch_seq       : 6422985
clsn           : 17088792
next_seq       : 6436152
file len       : 6746112
file free      : 6746112
create time    : 2020-06-06 02:00:09
close time     : 2020-06-06 06:13:36
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200606061513930_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 40
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 17088793
arch_seq       : 6436153
clsn           : 17088875
next_seq       : 6436192
file len       : 24576
file free      : 24576
create time    : 2020-06-06 06:13:36
close time     : 2020-06-06 06:24:48
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200606062454805_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 7
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 17088876
arch_seq       : 6436193
clsn           : 17088886
next_seq       : 6436199
file len       : 7680
file free      : 7680
create time    : 2020-06-06 06:24:48
close time     : 2020-06-06 06:26:17
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200606062617837_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 6
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 17088886
arch_seq       : 6436200
clsn           : 17088896
next_seq       : 6436205
file len       : 7168
file free      : 7168
create time    : 2020-06-06 06:26:17
close time     : 2020-06-06 06:27:51
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200606062942967_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 7
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 17088896
arch_seq       : 6436206
clsn           : 17088905
next_seq       : 6436212
file len       : 7680
file free      : 7680
create time    : 2020-06-06 06:27:51
close time     : 2020-06-06 06:29:43
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200606064235117_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 23
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 17088906
arch_seq       : 6436213
clsn           : 17088950
next_seq       : 6436235
file len       : 15872
file free      : 15872
create time    : 2020-06-06 06:29:43
close time     : 2020-06-06 13:11:01
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200606142912805_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 2
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 17088951
arch_seq       : 6436236
clsn           : 17088956
next_seq       : 6436237
file len       : 5120
file free      : 5120
create time    : 2020-06-06 13:11:01
close time     : 2020-06-06 14:29:13
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200606220653158_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 613936
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 17088957
arch_seq       : 6436238
clsn           : 18425990
next_seq       : 7050173
file len       : 314339328
file free      : 314339328
create time    : 2020-06-06 14:29:13
close time     : 2020-06-13 21:00:00
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200613210000757_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 614389
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 18425991
arch_seq       : 7050174
clsn           : 19599505
next_seq       : 7664562
file len       : 314571264
file free      : 314571264
create time    : 2020-06-13 21:00:00
close time     : 2020-06-17 09:35:23
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200617093523748_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 64818
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 19599505
arch_seq       : 7664563
clsn           : 19731163
next_seq       : 7729380
file len       : 33190912
file free      : 33190912
create time    : 2020-06-17 09:35:23
close time     : 2020-06-17 16:18:01
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200617161801000_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 7844
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 19731163
arch_seq       : 7729381
clsn           : 19747260
next_seq       : 7737224
file len       : 4020224
file free      : 4020224
create time    : 2020-06-17 16:18:01
close time     : 2020-06-17 17:01:01
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200617170101954_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 2920
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 19747260
arch_seq       : 7737225
clsn           : 19752806
next_seq       : 7740144
file len       : 1499136
file free      : 1499136
create time    : 2020-06-17 17:01:01
close time     : 2020-06-17 17:30:05
crc_check      : TRUE
/*******************************************************************/
/*******************************************************************/
archive file /dm_home/dmdbms/backup/arch/ARCHIVE_LOCAL1_20200617173005734_0.log itemize.
version        : 0x7004
status         : INACTIVE
n_rpags        : 17157
db_magic       : 708657636
pemnt_magic    : 1250320462
arch_lsn       : 19752806
arch_seq       : 7740145
clsn           : 19787571
next_seq       : 7757301
file len       : 8788480
file free      : 8788480
create time    : 2020-06-17 17:30:05
close time     : 2020-06-17 19:08:59
crc_check      : TRUE
/*******************************************************************/

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

the rachk tool running cost 5.413 ms
[dmdba@dmks backup]$

DMRMAN查看归档备份的范围:

RMAN> show backupset '/dm_home/dmdbms/backup/arch_bak' info meta;
show backupset '/dm_home/dmdbms/backup/arch_bak' info meta;




backupset sig:         BA
backupset version:     4009
database name:         jydm
backup name:           ARCH_20200617_173005_000673
backupset description:
backupset ID :         -99299676
parent backupset ID:     -1
META file size :       135680
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          archivelog
mpp_timestamp:         1592386205
arch start lsn:        13775970
arch end lsn:          19752806
backup level:          online
backup type:           archive
without log:           TRUE
START_LSN:             19752785
START_SEQ:             7740126
END_LSN:               19752968
END_SEQ:               7740221
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-06-17 17:30:45
min trx start lsn:     16553039
min exec ver:          0x0701060C
pkg size:              0x02000000


show backupsets successfully.
time used: 7.527(ms)

如果有丢失部分归档日志可以执行归档还原后,再次执行利用本地归档恢复操作。

RMAN>restore archive log from backupset '/dm_home/dmdbms/backup/arch_bak' ALL TO ARCHIVEDIR '/dm_home/dmdbms/backup/arch';

发表评论

电子邮件地址不会被公开。