我的oracle的異機不完全恢復-路徑不一致恢復筆記,轉載請註明出處

e71hao發表於2016-09-25
oracle的異機不完全恢復-路徑不一致恢復:
1.恢復要點:異機恢復的作業系統,資料庫版本一致,精確到小版本。
2.恢復要點:恢復控制檔案用RMAN>restore controlfile  from '/home/oracle/orcl_recover_0922/ncsnf0_tag20160907t110022_0.615.921927741';
3.恢復要點:將備份集重新註冊到控制檔案。
4.恢復要點:修改資料檔案和日誌檔案路徑可用下面語句:
set newname for datafile 1 to '/u01/app/oracle/oradata/orcl/system.dbf';
 alter database rename file '+DG_DATAFILEORCL/orcl/onlinelog/group_1.262.910013385' to  '/u01/app/oracle/oradata/orcl/group1B.log';
 
5.特別注意恢復時候的版本。我上次做異機恢復實驗.原機是centos6.5+oracle11.2.0.3.0,目標機是:redhat6.5+oracle11.2.0.4.0, 結果恢復出來,
在alter database open resetlogs,這最後一步,出現了很多意外的問題,跟目標機的環境有很大的關係。
 
6.以下是恢復過程,中間有不必要的程式碼會省略。
【1】把要恢復的備份片,複製到目標機。
 ncsnf0_tag20160907t110022_0.615.921927741   包括引數檔案,控制檔案
 nnndf0_tag20160907t110022_0.294.921927625   包括資料檔案
 
 
 thread_1_seq_1123.339.921956079
 thread_1_seq_1124.338.921967313
 那怎麼確定,我需要複製哪些歸檔日誌呢?這要看需求恢復到哪個時間?提供如下兩個函式


select * from nls_session_parameters; 
select timestamp_to_scn('21-Sep-16 10.00.00') from dual; 
select scn_to_timestamp(17982985) from dual; 
 
 
【2】恢復引數檔案
[oracle@oracleIns ~]$ export ORACLE_SID=orcl
[oracle@oracleIns ~]$ rman target /
RMAN> set dbid=1437794116
executing command: SET DBID
RMAN>startup nomount    
這裡注意的是,rman命令使用了預設的隱含引數。
RMAN>restore spfile from '/home/oracle/app/flash_recovery_area/ORCL/autobackup/2015_06_06/o1_mf_s_881702383_bq5x0wq0_.bkp';
RMAN>shutdown immediate
SQL>create pfile='/path/orcl.ora' from spfile;
修改pfile配置檔案,這裡修改控制檔案路徑,sga,memory_target等引數,讓它適應目標機。
SQL>create spfile from pfile='/path/orcl.ora';
RMAN>startup nomount


這樣就恢復了引數檔案。


【3】恢復控制檔案
RMAN>restore controlfile  from '/home/oracle/orcl_recover_0922/ncsnf0_tag20160907t110022_0.615.921927741';
RMAN>alter database mount;


【4】修改重做日誌檔案路徑:
SQL> alter database rename file '+DG_DATAFILEORCL/orcl/onlinelog/group_1.263.910013389' to  '/u01/app/oracle/oradata/orcl/group1.log';
SQL>alter database rename file '+DG_DATAFILEORCL/orcl/onlinelog/group_1.262.910013385' to  '/u01/app/oracle/oradata/orcl/group1B.log';
SQL> alter database rename file '+DG_DATAFILEORCL/orcl/onlinelog/group_2.265.910013397' to  '/u01/app/oracle/oradata/orcl/group2.log';
SQL> alter database rename file '+DG_DATAFILEORCL/orcl/onlinelog/group_2.264.910013393' to  '/u01/app/oracle/oradata/orcl/group2B.log';
SQL> alter database rename file '+DG_DATAFILEORCL/orcl/onlinelog/group_3.267.910013405' to  '/u01/app/oracle/oradata/orcl/group3.log';
SQL> alter database rename file '+DG_DATAFILEORCL/orcl/onlinelog/group_3.266.910013401' to  '/u01/app/oracle/oradata/orcl/group3B.log';


【5】重新將備份片backupset,歸檔日誌註冊到控制檔案:
 將備份集重新註冊到控制檔案
 方法一:註冊單個備份片
  RMAN> CATALOG BACKUPPIECE '/u01/bak/arch_0no76njh_1_1_20130416','/u01/bak/ctl_file_0oo76njm_1_1_20130416'
方法二:註冊整個目錄
  ---ASM:
  CATALOG START WITH '+disk'; # catalog allfiles from an ASM disk group
  --本地目錄:最後一定要加/
  CATALOG START WITH '/fs1/datafiles/'; #catalog all files in directory
  --有多個目錄,註冊多次:
  RMAN> catalog start with'/data01/'; 
RMAN>catalog start with '/data02/'; 
RMAN>catalog start with '/data03/';




【6】同時清理控制檔案中不存在的備份片,歸檔日誌,為接下來資料檔案恢復做準備:
RMAN>crosscheck backupset;
RMAN>crosscheck copy;
RMAN>delete expired backupset;
RMAN>delete expired copy;


【7】資料檔案恢復,這裡注意指令碼是怎麼修改資料檔案日誌的:


RUN{
set newname for datafile 1 to '/u01/app/oracle/oradata/orcl/system.dbf';
set newname for datafile 2 to '/u01/app/oracle/oradata/orcl/sysaux01.dbf';
set newname for datafile 3 to '/u01/app/oracle/oradata/orcl/undotbs1.dbf';
set newname for datafile 4 to '/u01/app/oracle/oradata/orcl/users.dbf';
set newname for datafile 5 to '/u01/app/oracle/oradata/orcl/lyk.dbf';
set newname for datafile 6 to '/u01/app/oracle/oradata/orcl/posjk.dbf';
set newname for datafile  7 to '/u01/app/oracle/oradata/orcl/bcard.dbf';
set newname for datafile 8 to '/u01/app/oracle/oradata/orcl/channel.dbf';
set newname for datafile 9 to '/u01/app/oracle/oradata/orcl/cp.dbf';
set newname for datafile 10 to '/u01/app/oracle/oradata/orcl/njcs.dbf';
set newname for datafile 11 to '/u01/app/oracle/oradata/orcl/njsmk.dbf';
set newname for datafile 12 to '/u01/app/oracle/oradata/orcl/posjk1.dbf';
set newname for datafile 13 to '/u01/app/oracle/oradata/orcl/posjk2.dbf';
set newname for datafile 14 to '/u01/app/oracle/oradata/orcl/vas.dbf';
set newname for datafile 15 to '/u01/app/oracle/oradata/orcl/fin.dbf';
set newname for datafile 16 to '/u01/app/oracle/oradata/orcl/njcs1.dbf';
set newname for datafile 17 to '/u01/app/oracle/oradata/orcl/posjk3.dbf';
set newname for datafile 18 to '/u01/app/oracle/oradata/orcl/njcc.dbf';
restore database;
switch datafile all;
recover database;
}
這個步驟花時間是最多的。
在執行recover database;時候會報錯:
RMAN-06025: no backup of archived log for thread 1 with sequence *** and starting SCN of ********* found to restore
因為找不到更多的歸檔日誌了嘛。其實這正是我們要的目標,恢復到某個時間點:
接著再來不完全恢復:
recover database until time "to_date('2015-04-20 08:13:50','yyyy-mm-dd hh24:mi:ss')";
recover database until sequence 123 thread 1;
recover database until scn 888;






【8】開啟資料庫。這個步驟會出現很多錯誤,如果你異機恢復的作業系統,資料庫版本不一致。
alter database open resetlogs;

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

相關文章