Oracle 利用RMAN 完成資料遷移

dbasdk發表於2014-08-18
整體流程:對A機的資料庫來一個熱備,並且是一個全備,然後透過scp命令把備份傳到B機,然後把A庫停掉(注意關庫不會觸發歸檔),之後再把歸檔日誌和redo日誌傳給B機,最後再在B庫上 restore 和recover
資料檔案,控制檔案,引數檔案  的恢復過程:根據資料庫的啟動流程,可以知道最先讀取資料檔案,所以應該先還原引數檔案,然後會讀控制檔案,所以你要再修復控制檔案,最後再修復資料檔案,
具體操作流程:
一:對A庫做一個熱全備,
RMAN> backup as backupset database include current controlfile plus archivelog format '/u01/app/oracle/arch_%U.rmn' delete all input;
省列。。。。
Finished backup at 14-AUG-14
二:把所做的備份用scp傳給B機。 如紅色命令會把A機的ENMOEDU接到B機的Oracle/下,,即Oracle/ENMOEDU
[oracle@ENMOEDU ENMOEDU]$ scp -r /u01/app/oracle/fast_recovery_area/ENMOEDU     oracle@192.168.80.11:/u01/app/oracle/ 
The authenticity of host '192.168.80.11 (192.168.80.11)' can't be established. 
RSA key fingerprint is 54:78:71:4c:93:51:01:f4:e3:83:b5:35:8f:9f:d5:b1. 
Are you sure you want to continue connecting (yes/no)? y 
Please type 'yes' or 'no': yes 
Warning: Permanently added '192.168.80.11' (RSA) to the list of known hosts. 
oracle@192.168.80.11's password: 
o1_mf_nnndf_SECTION_DF1_9srh9o7k_.bkp 100% 148MB 36.9MB/s 00:04 
o1_mf_ncnnf_SECTION_DF1_9srh9ws3_.bkp 100% 9568KB 9.3MB/s 00:01 
o1_mf_nnndf_SECTION_DF1_9srh9n9o_.bkp 100% 97MB 24.2MB/s 00:04 
o1_mf_nnsnf_SECTION_DF1_9srh9nml_.bkp 100% 96KB 96.0KB/s 00:00 
o1_mf_nnndf_SECTION_DF1_9srh9o26_.bkp 100% 140MB 28.0MB/s 00:05 
o1_mf_nnndf_SECTION_DF1_9srh9v71_.bkp 100% 145MB 29.0MB/s 00:05 
o1_mf_nnndf_SECTION_DF1_9srhb0dh_.bkp 100% 81MB 27.0MB/s 00:03 
o1_mf_ncsnf_TAG20140814T203309_9ysc8x14_.bkp 100% 9600KB 4.7MB/s 00:02 
o1_mf_nnndf_TAG20140814T203309_9ysc46go_.bkp 100% 1140MB 24.3MB/s 00:47 
control02.ctl                                                            100% 9520KB 9.3MB/s 00:01 
三:把A庫資料庫關閉,把歸檔和redo傳給B機,(因為你備份的時候沒有關閉資料庫,難免會再產生新的歸檔和redo,為保證一致性,還有必要進行這步)
1.SYS@ENMOEDU> select * from v$log;                      #顯示第三組  正在被使用,所以只傳它就行(因為別的已經被歸檔,)

GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC 
---------- ---------- ---------- ---------- ---------- ---------- --- 
STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME 
---------------- ------------- --------- ------------ --------- 
1 1 100 52428800 512 1 YES 
INACTIVE 1365811 14-AUG-14 1365876 14-AUG-14 

2 1 101 52428800 512 1 YES 
INACTIVE 1365876 14-AUG-14 1365981 14-AUG-14 

3 1 102 52428800 512 1 NO 
CURRENT 1365981 14-AUG-14 2.8147E+14 


2.SYS@ENMOEDU> select * from v$logfile;     #檢視日誌的具體位置

GROUP# STATUS TYPE 
---------- ------- ------- 
MEMBER 
-------------------------------------------------------------------------------- 
IS_ 
--- 
1 ONLINE 
/u01/app/oracle/oradata/ENMOEDU/redo01.log 
NO 

2 ONLINE 
/u01/app/oracle/oradata/ENMOEDU/redo02.log 
NO 

GROUP# STATUS TYPE 
---------- ------- ------- 
MEMBER 
-------------------------------------------------------------------------------- 
IS_ 
--- 

3 ONLINE 
/u01/app/oracle/oradata/ENMOEDU/redo03.log 
NO
[oracle@ENMOEDU ENMOEDU]$ scp /u01/app/oracle/oradata/ENMOEDU/redo03.log oracle@192.168.80.11:/u01/app/oracle 
oracle@192.168.80.11's password: 
redo03.log 100% 50MB 50.0MB/s 00:01   
至於歸檔嘛  我在測試的時候沒有切換日誌,也不存在日誌組寫滿的情況,所以沒有產生歸檔,又因為我在備份的時候加上了delete all input 所以會把已經備份的歸檔刪掉,所以你不會看到新的歸檔  也就不用傳了  呵呵
四:在B機操作
1,開啟偽例項,注意可不要把B機的資料庫例項給開啟了  因為我的測試B機也有資料庫。
[oracle@ENMOEDU ~]$ set DBID=87396644               #設成A機的資料庫編號
RMAN> startup                #啟動偽例項   

[oracle@ENMOEDU ENMOEDU]$ rman target / 
RMAN> restore spfile from '/u01/app/oracle/ENMOEDU/backupset/2014_08_14/o1_mf_ncsnf_TAG20140814T203309_9ysc8x14_.bkp'; 

Starting restore at 15-AUG-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/ENMOEDU/backupset/2014_08_14/o1_mf_ncsnf_TAG20140814T203309_9ysc8x14_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 15-AUG-14
[oracle@ENMOEDU dbs]$ ls                  #恢復的引數檔案在$ORACLE_HOME/dbs  下
hc_ENMOEDU2.dat    lkDUMMY   orapwENMOEDU    spfileENMOEDU2.ora
RMAN> shutdown immediate                           #關偽例項

Oracle instance shut down
2.然後再起真正的例項,恢復控制檔案(要注意,他原來就有,你這樣起,把B機的所有檔案包括  資料檔案 ,控制檔案,引數檔案,日誌檔案都刪掉
SQL> startup
ORACLE instance started.

Total System Global Area 422670336 bytes
Fixed Size 1345380 bytes
Variable Size 260049052 bytes
Database Buffers 155189248 bytes
Redo Buffers 6086656 bytes
ORA-00205: error in identifying control file, check alert log for more info
RMAN> restore controlfile from '/u01/app/oracle/ENMOEDU/backupset/2014_08_14/o1_mf_ncsnf_TAG20140814T203309_9ysc8x14_.bkp';

Starting restore at 15-AUG-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/ENMOEDU/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/ENMOEDU/control02.ctl
Finished restore at 15-AUG-14
3.把資料庫開到mount狀態,以便修復資料檔案。
RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1
RMAN> restore database;                    #恢復資料檔案   發現報錯,很可能是備份已經過期已經,

Starting restore at 15-AUG-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK

creating datafile file number=1 name=/u01/app/oracle/oradata/ENMOEDU/system01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 08/15/2014 23:21:00
ORA-01180: can not create datafile 1
ORA-01110: data file 1: '/u01/app/oracle/oradata/ENMOEDU/system01.dbf'
RMAN> list backup;          #檢視備份資訊    發現確實過期
10 13.85M DISK 00:00:02 14-AUG-14
        BP Key: 14 Status: EXPIRED Compressed: NO Tag: TAG20140814T203306
        Piece Name: /u01/app/oracle/arch_50pfv1g2_1_1.rmn
然後再去A機  再來一個整體備份  再傳給B機  不在贅述,再恢復控制檔案,然後再恢復資料檔案,  
再啟動到open即可。


















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

相關文章