DM7使用DMRAMN执行更新DB_MAGIC恢复

使用DMRAMN执行更新DB_MAGIC恢复
使用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恢复、从备份集恢复和从归档恢复,

更新DB_MAGIC恢复
当备份集为脱机备份即备份过程中无日志生成,那么此时还原后的数据库中数据与备份时数据状态一致。在不需要重做归档日志恢复数据的情况下,可以直接更新DB_MAGIC完成数据库恢复。完整的示例如下:

1) 启动RMAN备份数据库,保证服务器处于脱机状态。

RMAN> backup database '/dm_home/dmdba/dmdbms/data/jydm/dm.ini' full backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic';
backup database '/dm_home/dmdba/dmdbms/data/jydm/dm.ini' full backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic';
file dm.key not found, use default license!
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[4].
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[3].
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[2].
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[1].
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[0].
checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running, write dmrman info.
EP[0] max_lsn: 19945240
BACKUP DATABASE [jydm], execute......
CMD CHECK LSN......
BACKUP DATABASE [jydm], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 7 packages processed...
total 13 packages processed...
total 14 packages processed...
total 15 packages processed...
total 16 packages processed...
total 21 packages processed...
total 22 packages processed...
DBF BACKUP MAIN......
BACKUPSET [/dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic] END, CODE [0]......
META GENERATING......
total 26 packages processed...
total 26 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 15113.537(ms)

RMAN> show backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic';
show backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic';




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_192816_000091
backupset description:
backupset ID :         -1041017958
parent backupset ID:     -1
META file size :       86528
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1592393290
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          offline
backup type:           full
without log:           FALSE
START_LSN:             19945241
START_SEQ:             7798402
END_LSN:               19945240
END_SEQ:               7798401
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-06-17 19:28:25
min trx start lsn:     19945241
min exec ver:          0x0701060C
pkg size:              0x02000000


backupset directory: /dm_home/dmdba/dmdbms/data/jydm/bak/db_full_bak_recover_dbmagic
backupset name:        db_full_bak_recover_dbmagic
backup data file num:  8
backup piece num:      1


$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |205431    |db_full_bak_recover_dbmagic.bak                         |DATA


$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|                                 |176160768
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


show backupsets successfully.
time used: 3.792(ms)

将源库的数据库备份集传输到目标主机上

[dmdba@shard1 bak]$ scp -r db_full_bak_recover_dbmagic/ dmdba@10.13.13.187:/dm_home/dmdbms/backup/
dmdba@10.13.13.187's password:
db_full_bak_recover_dbmagic.bak                                                                                                                                                                           100%  201MB 100.3MB/s   00:02
db_full_bak_recover_dbmagic.meta                                                                                                                                                                          100%   85KB  84.5KB/s   00:00
[dmdba@shard1 bak]$

2) 准备目标库,可以使用备份库,也可以重新生成库。这里是在别一台服务器上创建新库,重新生成库操作如下:

./dminit path=/opt/dmdbms/data db_name=DAMENG_FOR_RESTORE auto_overwrite=1

但我这里目标库就是源库

3) 校验备份。

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

4) 还原数据库。

RMAN> restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_full_bak_recover_dbmagic';
restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_full_bak_recover_dbmagic';
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_full_bak_recover_dbmagic] 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 24 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 49968.844(ms)

5) 恢复数据库。

RMAN> recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' update db_magic;
recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' update db_magic;
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: 19945240
recover successfully!
time used: 7041.721(ms)

6)检查db_magic值,可以确定在没有指定update db_magic选项时其实也是更新了db_maigc值。db_maigc值从708657636变成了-616506144

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

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

Server[localhost:5336]:mode is normal, state is open
login used time: 11.667(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          1250320462

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

LINEID     DB_MAGIC
---------- -----------
1          -616506144

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

发表评论

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