DM7 RAC資料庫恢復成單機資料庫

eric0435發表於2020-07-05

DM7 RAC資料庫恢復成單機資料庫
1) 啟動RMAN備份資料庫,保證伺服器處於離線狀態。

RMAN> backup database '/dm7/data/rac0_config/dm.ini' full backupset '/dm7/backup/db_rac_full_bak_recover_dbmagic';
backup database '/dm7/data/rac0_config/dm.ini' full backupset '/dm7/backup/db_rac_full_bak_recover_dbmagic';
file dm.key not found, use default license!
checking if the RAC database under system path [+DMDATA/data/rac] is running....
EP [0] is checking....
EP [1] is checking....
EP[0] max_lsn: 76986
EP[0] adjust cur_lsn from [76986] to [77001]
BACKUP DATABASE [rac], execute......
CMD CHECK LSN......
BACKUP DATABASE [rac], collect dbf......
CMD CHECK ......
DBF BACKUP SUBS......
total 1 packages processed...
total 2 packages processed...
total 3 packages processed...
total 4 packages processed...
total 5 packages processed...
DBF BACKUP MAIN......
BACKUPSET [/dm7/backup/db_rac_full_bak_recover_dbmagic] END, CODE [0]......
META GENERATING......
total 9 packages processed...
total 9 packages processed!
CMD END.CODE:[0]
backup successfully!
time used: 3887.714(ms)
RMAN> show backupset '/dm7/backup/db_rac_full_bak_recover_dbmagic';
show backupset '/dm7/backup/db_rac_full_bak_recover_dbmagic';
system path:           +DMDATA/data/rac
db magic:              -1632052820
permanent magic:       450923536
rac node:              2
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:         rac
backup name:           DB_FULL_rac_20200616_154323_000689
backupset description:
backupset ID :         1145407476
parent backupset ID:     -1
META file size :       74240
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1592293401
ddl_clone:             FALSE
mpp_flag:              FALSE
backup level:          offline
backup type:           full
without log:           FALSE
START_LSN:             76987
START_SEQ:             309
END_LSN:               77001
END_SEQ:               308
base START_LSN:        -1
base END_LSN:          -1
base name:
base backupset:
backup time:           2020-06-16 15:43:25
min trx start lsn:     76987
min exec ver:          0x0701060C
pkg size:              0x02000000
RAC EP:            0
RAC status:          OK
RAC begin lsn:       76987
RAC begin seq:       309
RAC end lsn:         77001
RAC end seq:         308
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1
RAC EP:            1
RAC status:          OK
RAC begin lsn:       77002
RAC begin seq:       308
RAC end lsn:         77001
RAC end seq:         307
RAC base begin lsn:  -1
RAC base begin seq:  -1
RAC base end lsn:    -1
RAC base end seq:    -1
backupset directory: /dm7/backup/db_rac_full_bak_recover_dbmagic
backupset name:        db_rac_full_bak_recover_dbmagic
backup data file num:  5
backup piece num:      1
$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |26103     |db_rac_full_bak_recover_dbmagic.bak                     |DATA
$file_seq |$group_id |$group_name                      |$file_id  |$file_path                       |$mirror_path                     |$file_len
1         |0         |SYSTEM                           |0         |+DMDATA/data/rac/system.dbf      |                                 |134217728
2         |1         |ROLL                             |0         |+DMDATA/data/rac/roll.dbf        |                                 |134217728
3         |4         |MAIN                             |0         |+DMDATA/data/rac/main.dbf        |                                 |134217728
4         |5         |TS_FOR_DBF                       |0         |+DMDATA/data/rac/ts_for_dbf_01.dbf|                                 |134217728
5         |5         |TS_FOR_DBF                       |1         |+DMDATA/data/rac/ts_for_dbf_02.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: 10.655(ms)

2) 準備目標庫,可以使用備份庫,也可以重新生成庫。這裡是在別一臺伺服器上建立新庫,重新生成庫操作如下:

[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          -1238913195
used time: 0.793(ms). Execute id is 809.
SQL> select db_magic from v$rlog;
LINEID     DB_MAGIC
---------- -----------
1          1319824724
used time: 0.984(ms). Execute id is 810.

3)將備份集和歸檔日誌檔案複製到目標庫所在主機上

[dmdba@dmrac1 backup]$ scp -r db_rac_full_bak_recover_dbmagic dmdba@10.10.10.187:/dm_home/dmdbms/backup/
The authenticity of host '10.10.10.187 (10.10.10.187)' can't be established.
RSA key fingerprint is 34:9a:d7:67:6d:be:20:45:21:ce:96:82:23:e5:e9:11.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.187' (RSA) to the list of known hosts.
dmdba@10.10.10.187's password:
db_rac_full_bak_recover_dbmagic.meta 100% 73KB 72.5KB/s 00:00
db_rac_full_bak_recover_dbmagic.bak 100% 25MB 25.5MB/s 00:00

[dmdba@dmrac1 data]$ scp -r local_arch dmdba@10.10.10.187:/dm_home/dmdbms/backup/
dmdba@10.10.10.187's password:
ARCHIVE_LOCAL1_20200528171255857_0.log 100% 157KB 156.5KB/s 00:00
[dmdba@dmrac1 data]$ scp -r rac0_arch dmdba@10.10.10.187:/dm_home/dmdbms/backup/
dmdba@10.10.10.187's password:
ARCHIVE_LOCAL1_20200615164953273_0.log 100% 160KB 160.0KB/s 00:00
ARCHIVE_LOCAL1_20200615165648166_0.log 100% 157KB 157.0KB/s 00:00
ARCHIVE_LOCAL1_20200528202150715_0.log 100% 277KB 277.0KB/s 00:00
ARCHIVE_LOCAL1_20200608151836879_0.log 100% 158KB 157.5KB/s 00:00
ARCHIVE_LOCAL1_20200609150852829_0.log 100% 157KB 157.0KB/s 00:00
ARCHIVE_LOCAL1_20200608152638617_0.log 100% 159KB 158.5KB/s 00:00
ARCHIVE_LOCAL1_20200609170732487_0.log 100% 161KB 160.5KB/s 00:00
ARCHIVE_LOCAL1_20200615172117341_0.log 100% 159KB 158.5KB/s 00:00
ARCHIVE_LOCAL1_20200615171042444_0.log 100% 159KB 159.0KB/s 00:00
ARCHIVE_LOCAL1_20200605154214367_0.log 100% 157KB 157.0KB/s 00:00
[dmdba@dmrac1 data]$ scp -r rac1_arch dmdba@10.10.10.187:/dm_home/dmdbms/backup/
dmdba@10.10.10.187's password:
ARCH_REMOTE1_20200608152641970_1.log 100% 158KB 158.0KB/s 00:00
ARCH_REMOTE1_20200609170737070_1.log 100% 159KB 159.0KB/s 00:00
ARCH_REMOTE1_20200609150857056_1.log 100% 158KB 158.0KB/s 00:00
ARCH_REMOTE1_20200615172121038_1.log 100% 158KB 158.0KB/s 00:00
ARCH_REMOTE1_20200608151838201_1.log 100% 5632 5.5KB/s 00:00
ARCH_REMOTE1_20200528202146001_1.log 100% 158KB 158.0KB/s 00:00
ARCH_REMOTE1_20200615164957743_1.log 100% 158KB 158.0KB/s 00:00
ARCH_REMOTE1_20200605154211189_1.log 100% 159KB 159.0KB/s 00:00
ARCH_REMOTE1_20200615165652504_1.log 100% 158KB 158.0KB/s 00:00
ARCH_REMOTE1_20200615171046600_1.log 100% 158KB 158.0KB/s 00:00
[dmdba@dmrac1 data]$

4)檢驗備份

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

5)還原資料庫

RMAN> restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_rac_full_bak_recover_dbmagic';
restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_rac_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_rac_full_bak_recover_dbmagic] START......
total 5 packages processed...
RESTORE DATABASE , UPDATE ctl file......
RESTORE DATABASE , REBUILD key file......
RESTORE DATABASE , CHECK db info......
RESTORE DATABASE , UPDATE db info......
total 7 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 16226.253(ms)

6)恢復資料庫

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: 76986
[-8308]:forbid updating database magic, need redo log

這裡使用update db_magic選項出錯了,提示需要重做日誌檔案。下面去掉update db_magic選項,因為每次還原恢復時也是一定會更新db_magic值。

RMAN> recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' with archivedir '/dm_home/dmdbms/backup/rac0_arch','/dm_home/dmdbms/backup/rac1_arch';
recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' with archivedir '/dm_home/dmdbms/backup/rac0_arch' , '/dm_home/dmdbms/backup/rac1_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.
EP[0] max_lsn: 76986
min_ckpt_lsn =
The RAC recover total redo 0 ptx
EP(0) slot ctl page(1, 0, 16) trxid = 9986
EP(1) slot ctl page(1, 0, 17) trxid = 8457
EP[0] Recover LSN from 76987 to 77001.
EP[1] Recover LSN from 77002 to 77001.
Recover from archive log finished, time used:0.006s.
recover successfully!
time used: 7027.075(ms)

7)檢查資料,查詢表t1的資料可以驗證資料恢復成功

[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> desc t1;
LINEID     NAME TYPE$       NULLABLE
---------- ---- ----------- --------
1          ID   INTEGER     Y
2          NAME VARCHAR(20) Y
used time: 20.311(ms). Execute id is 3.
SQL> select * from t1;
LINEID     ID          NAME
---------- ----------- ----
1          1           jy
2          2           hy
used time: 1.138(ms). Execute id is 4.

8)檢查db_magic,還原恢復後db_magic從-1632052820變成了1009602608,

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.


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-2702573/,如需轉載,請註明出處,否則將追究法律責任。

相關文章