在Oracle Database 12.1 中異機遷移恢復數據庫【實戰】

平臺環境:
源OS:Oracle Linux 7.3
源DB:Oracle Database 12.1.0.2

目標OS:Oracle Linux 7.3
目標DB:Oracle Database 12.1.0.2

一、準備工作
1、查詢當前SCN

col current_scn form 99999999999999
SQL> select current_scn from v$database;
    CURRENT_SCN
---------------
  5965538762695


 
2、顯示當前DBID和DBName
 
 

SQL> select dbid,name from v$database;
      DBID NAME
 ---------- ---------
  357998902 PROD


 
3、對當前重做日誌進行歸檔

ALTER SYSTEM ARCHIVE LOG CURRENT;



注:ALTER SYSTEM ARCHIVE LOG CURRENT; 可以保證數據的一致性,而Alter system switch logfile;不能保證數據一致性。


4、準備備份數據

(1)0級備份,1級增量備份,備份時產生的FRA文件
(2)備份ARCHIVELOG 文件
(3)備份參數文件,命令:backup spfile format '/backup/rman_backup/spfile%d_%s_%p_%u.%'

mkdir -p /mnt/data/backup/PBF/archive



注:(1)的文件傳輸到/mnt/data/backup/PBF
(2)的文件傳輸到/mnt/data/backup/PBF/archive


二、異機恢復步驟
1、創建密碼文件
 

orapwd file=/mnt/data/PBF/db/12.1.0/dbs/orapwPROD password=oracle entrie=5 format=12

 

2、準備環境和initPROD.ora

export ORACLE_SID=PROD
echo $ORACLE_SID
vi initPROD.ora
db_name = PROD



3、將數據庫啓動到nomount狀態

sqlplus / as sysdba
startup nomount pfile=/mnt/data/PBF/db/12.1.0/dbs/initPROD.ora;
or
startup nomount;



4、恢復參數文件並修改參數文件

rman target /
restore spfile to pfile '/mnt/data/PBF/db/12.1.0/dbs/initPROD2.ora' from '/mnt/data/backup/PBF/spfilePROD_2402_1_b2stkm1i';



(1)創建路徑:

mkdir -p /mnt/data/PBF/db/archive
mkdir -p /mnt/data/PBF/db/db_recovery_dest


(2)修改pfile中的以下參數:

control_files
diagnostic_dest
db_recovery_file_dest



(3)重新啓動

shutdown abort;
startup nomount;



5、恢復控制文件,修改數據庫到mount狀態,並交叉檢查備份集

rman target /
restore controlfile from '/mnt/data/backup/PBF/cntrl_20180312.ctl';
alter database mount;
crosscheck backupset;




6、註冊備份集文件和FRA中的文件,交叉檢查備份集,並刪除過期的備份集

catalog start with '/mnt/data/backup/PBF/';
crosscheck backupset;
delete noprompt expired backupset;



7、註冊archivelog

CATALOG archivelog '/mnt/data/backup/PBF/archive/1_2213_946160568.dbf','/mnt/data/backup/PBF/archive/1_2214_946160568.dbf','/mnt/data/backup/PBF/archive/1_2215_946160568.dbf','/mnt/data/backup/PBF/archive/1_2216_946160568.dbf','/mnt/data/backup/PBF/archive/1_2217_946160568.dbf','/mnt/data/backup/PBF/archive/1_2218_946160568.dbf','/mnt/data/backup/PBF/archive/1_2219_946160568.dbf','/mnt/data/backup/PBF/archive/1_2220_946160568.dbf','/mnt/data/backup/PBF/archive/1_2221_946160568.dbf','/mnt/data/backup/PBF/archive/1_2222_946160568.dbf';



8、由於路徑不一樣,使用以下語句批量生成

select 'set newname for datafile '|| file_id || ' to ''/mnt/data/PBF/db/proddata/' ||
        substr(name,
               instr(name,'/', -1) + 1) || ''';'
   from v$datafile
  order by file#;


9、在rman中執行以下腳本

run
{
allocate channel ch1 device type disk;
allocate channel ch2 device type disk;
allocate channel ch3 device type disk;
set newname for datafile 1 to '/mnt/data/PBF/db/proddata/system01.dbf';
set newname for datafile 2 to '/mnt/data/PBF/db/proddata/system02.dbf';
set newname for datafile 3 to '/mnt/data/PBF/db/proddata/system03.dbf';
set newname for datafile 4 to '/mnt/data/PBF/db/proddata/system04.dbf';
set newname for datafile 5 to '/mnt/data/PBF/db/proddata/system05.dbf';
set newname for datafile 6 to '/mnt/data/PBF/db/proddata/ctxd01.dbf';
set newname for datafile 7 to '/mnt/data/PBF/db/proddata/owad01.dbf';
set newname for datafile 8 to '/mnt/data/PBF/db/proddata/a_queue02.dbf';
set newname for datafile 9 to '/mnt/data/PBF/db/proddata/odm.dbf';
set newname for datafile 10 to '/mnt/data/PBF/db/proddata/olap.dbf';
set newname for datafile 11 to '/mnt/data/PBF/db/proddata/sysaux01.dbf';
set newname for datafile 12 to '/mnt/data/PBF/db/proddata/apps_ts_tools01.dbf';
set newname for datafile 13 to '/mnt/data/PBF/db/proddata/system12.dbf';
set newname for datafile 14 to '/mnt/data/PBF/db/proddata/a_txn_data04.dbf';
set newname for datafile 15 to '/mnt/data/PBF/db/proddata/a_txn_ind06.dbf';
set newname for datafile 16 to '/mnt/data/PBF/db/proddata/a_ref03.dbf';
set newname for datafile 17 to '/mnt/data/PBF/db/proddata/a_int02.dbf';
set newname for datafile 18 to '/mnt/data/PBF/db/proddata/sysaux02.dbf';
set newname for datafile 19 to '/mnt/data/PBF/db/proddata/system13.dbf';
set newname for datafile 20 to '/mnt/data/PBF/db/proddata/system14.dbf';
set newname for datafile 21 to '/mnt/data/PBF/db/proddata/system15.dbf';
set newname for datafile 22 to '/mnt/data/PBF/db/proddata/system16.dbf';
set newname for datafile 23 to '/mnt/data/PBF/db/proddata/system17.dbf';
set newname for datafile 24 to '/mnt/data/PBF/db/proddata/system18.dbf';
set newname for datafile 25 to '/mnt/data/PBF/db/proddata/system19.dbf';
set newname for datafile 26 to '/mnt/data/PBF/db/proddata/system20.dbf';
set newname for datafile 27 to '/mnt/data/PBF/db/proddata/system21.dbf';
set newname for datafile 28 to '/mnt/data/PBF/db/proddata/system22.dbf';
set newname for datafile 29 to '/mnt/data/PBF/db/proddata/system23.dbf';
set newname for datafile 30 to '/mnt/data/PBF/db/proddata/system24.dbf';
set newname for datafile 31 to '/mnt/data/PBF/db/proddata/system25.dbf';
set newname for datafile 32 to '/mnt/data/PBF/db/proddata/a_ref04.dbf';
set newname for datafile 33 to '/mnt/data/PBF/db/proddata/a_ref05.dbf';
set newname for datafile 34 to '/mnt/data/PBF/db/proddata/a_ref06.dbf';
set newname for datafile 35 to '/mnt/data/PBF/db/proddata/undo02.dbf';
set newname for datafile 36 to '/mnt/data/PBF/db/proddata/cux_data01.dbf';
set newname for datafile 37 to '/mnt/data/PBF/db/proddata/cux_ind01.dbf';
set newname for datafile 38 to '/mnt/data/PBF/db/proddata/undo03.dbf';
set newname for datafile 39 to '/mnt/data/PBF/db/proddata/undo04.dbf';
set newname for datafile 40 to '/mnt/data/PBF/db/proddata/undo05.dbf';
set newname for datafile 41 to '/mnt/data/PBF/db/proddata/a_media02.dbf';
set newname for datafile 42 to '/mnt/data/PBF/db/proddata/a_media03.dbf';
set newname for datafile 43 to '/mnt/data/PBF/db/proddata/a_media04.dbf';
set newname for datafile 44 to '/mnt/data/PBF/db/proddata/sysaux03.dbf';
set newname for datafile 45 to '/mnt/data/PBF/db/proddata/a_media05.dbf';
set newname for datafile 46 to '/mnt/data/PBF/db/proddata/a_txn_ind07.dbf';
set newname for datafile 47 to '/mnt/data/PBF/db/proddata/a_txn_ind08.dbf';
set newname for datafile 48 to '/mnt/data/PBF/db/proddata/a_txn_data05.dbf';
set newname for datafile 49 to '/mnt/data/PBF/db/proddata/a_txn_data06.dbf';
set newname for datafile 50 to '/mnt/data/PBF/db/proddata/a_queue03.dbf';
set newname for datafile 51 to '/mnt/data/PBF/db/proddata/ctxd02';
set newname for datafile 52 to '/mnt/data/PBF/db/proddata/a_media06.dbf';
set newname for datafile 53 to '/mnt/data/PBF/db/proddata/a_media07.dbf';
set newname for datafile 54 to '/mnt/data/PBF/db/proddata/sysaux04.dbf';
set newname for datafile 55 to '/mnt/data/PBF/db/proddata/a_media08.dbf';
set newname for datafile 56 to '/mnt/data/PBF/db/proddata/a_media09.dbf';
set newname for datafile 57 to '/mnt/data/PBF/db/proddata/sysaux05.dbf';
set newname for datafile 58 to '/mnt/data/PBF/db/proddata/a_txn_ind09.dbf';
set newname for datafile 59 to '/mnt/data/PBF/db/proddata/a_txn_data07.dbf';
set newname for datafile 60 to '/mnt/data/PBF/db/proddata/a_media10.dbf';
set newname for datafile 61 to '/mnt/data/PBF/db/proddata/a_media11.dbf';
set newname for datafile 62 to '/mnt/data/PBF/db/proddata/a_media12.dbf';
set newname for datafile 63 to '/mnt/data/PBF/db/proddata/a_media13.dbf';
set newname for datafile 64 to '/mnt/data/PBF/db/proddata/a_media14.dbf';
set newname for datafile 65 to '/mnt/data/PBF/db/proddata/a_media15.dbf';
set newname for datafile 66 to '/mnt/data/PBF/db/proddata/a_media16.dbf';
set newname for datafile 67 to '/mnt/data/PBF/db/proddata/a_media17.dbf';
set newname for datafile 68 to '/mnt/data/PBF/db/proddata/a_media18.dbf';
set newname for datafile 69 to '/mnt/data/PBF/db/proddata/a_queue04.dbf';
set newname for datafile 70 to '/mnt/data/PBF/db/proddata/a_media19.dbf';
set newname for datafile 71 to '/mnt/data/PBF/db/proddata/a_media20.dbf';
set newname for datafile 72 to '/mnt/data/PBF/db/proddata/a_media21.dbf';
set newname for datafile 288 to '/mnt/data/PBF/db/proddata/system10.dbf';
set newname for datafile 295 to '/mnt/data/PBF/db/proddata/system06.dbf';
set newname for datafile 314 to '/mnt/data/PBF/db/proddata/portal01.dbf';
set newname for datafile 351 to '/mnt/data/PBF/db/proddata/system07.dbf';
set newname for datafile 352 to '/mnt/data/PBF/db/proddata/system09.dbf';
set newname for datafile 353 to '/mnt/data/PBF/db/proddata/system08.dbf';
set newname for datafile 354 to '/mnt/data/PBF/db/proddata/system11.dbf';
set newname for datafile 379 to '/mnt/data/PBF/db/proddata/undo01.dbf';
set newname for datafile 392 to '/mnt/data/PBF/db/proddata/a_txn_data01.dbf';
set newname for datafile 393 to '/mnt/data/PBF/db/proddata/a_txn_ind01.dbf';
set newname for datafile 394 to '/mnt/data/PBF/db/proddata/a_ref01.dbf';
set newname for datafile 395 to '/mnt/data/PBF/db/proddata/a_int01.dbf';
set newname for datafile 396 to '/mnt/data/PBF/db/proddata/a_summ01.dbf';
set newname for datafile 397 to '/mnt/data/PBF/db/proddata/a_nolog01.dbf';
set newname for datafile 398 to '/mnt/data/PBF/db/proddata/a_archive01.dbf';
set newname for datafile 399 to '/mnt/data/PBF/db/proddata/a_queue01.dbf';
set newname for datafile 400 to '/mnt/data/PBF/db/proddata/a_media01.dbf';
set newname for datafile 401 to '/mnt/data/PBF/db/proddata/a_txn_data02.dbf';
set newname for datafile 402 to '/mnt/data/PBF/db/proddata/a_txn_data03.dbf';
set newname for datafile 403 to '/mnt/data/PBF/db/proddata/a_txn_ind02.dbf';
set newname for datafile 404 to '/mnt/data/PBF/db/proddata/a_txn_ind03.dbf';
set newname for datafile 405 to '/mnt/data/PBF/db/proddata/a_txn_ind04.dbf';
set newname for datafile 406 to '/mnt/data/PBF/db/proddata/a_txn_ind05.dbf';
set newname for datafile 407 to '/mnt/data/PBF/db/proddata/a_ref02.dbf';
restore database;
restore archivelog from logseq 2213 until logseq 2222;
switch datafile all;
recover database until scn 5965538762695;
release channel ch1;
release channel ch2;
release channel ch3;
}





10、聯機在線日誌的處理
(1)生成處理腳本查詢:

set linesize 180 pagesize 100
select 'alter database rename file '''||member||''' to ''/mnt/data/PBF/db/proddata/redoXXX.log'';' from v\$logfile;



(2)處理腳本:

alter database rename file '/data/prod/proddata/log02a.dbf' to '/mnt/data/PBF/db/proddata/redo02a.log';
alter database rename file '/data/prod/proddata/log02b.dbf' to '/mnt/data/PBF/db/proddata/redo02b.log';
alter database rename file '/data/prod/proddata/log01a.dbf' to '/mnt/data/PBF/db/proddata/redo01a.log';
alter database rename file '/data/prod/proddata/log01b.dbf' to '/mnt/data/PBF/db/proddata/redo01b.log';
alter database rename file '/data/prod/proddata/log03a.dbf' to '/mnt/data/PBF/db/proddata/redo03a.log';
alter database rename file '/data/prod/proddata/log04a.dbf' to '/mnt/data/PBF/db/proddata/redo04a.log';
alter database rename file '/data/prod/proddata/log05a.dbf' to '/mnt/data/PBF/db/proddata/redo05a.log';
alter database rename file '/data/prod/proddata/log03b.dbf' to '/mnt/data/PBF/db/proddata/redo03b.log';
alter database rename file '/data/prod/proddata/log04b.dbf' to '/mnt/data/PBF/db/proddata/redo04b.log';
alter database rename file '/data/prod/proddata/log05b.dbf' to '/mnt/data/PBF/db/proddata/redo05b.log';


11、臨時表空間文件的處理

(1)生成處理腳本查詢:

set linesize 180 pagesize 100
select 'alter database rename file '''||name||''' to ''/mnt/data/PBF/db/proddata/tempXXX.dbf'';' from v$tempfile;

(2)處理腳本:

alter database rename file '/data/prod/proddata/temp11.dbf' to '/mnt/data/PBF/db/proddata/temp11.dbf';
alter database rename file '/data/prod/proddata/temp21.dbf' to '/mnt/data/PBF/db/proddata/temp21.dbf';
alter database rename file '/data/prod/proddata/temp12.dbf' to '/mnt/data/PBF/db/proddata/temp12.dbf';
alter database rename file '/data/prod/proddata/temp22.dbf' to '/mnt/data/PBF/db/proddata/temp22.dbf';
alter database rename file '/data/prod/proddata/temp32.dbf' to '/mnt/data/PBF/db/proddata/temp32.dbf';
alter database rename file '/data/prod/proddata/temp42.dbf' to '/mnt/data/PBF/db/proddata/temp42.dbf';
alter database rename file '/data/prod/proddata/temp13.dbf' to '/mnt/data/PBF/db/proddata/temp13.dbf';
alter database rename file '/data/prod/proddata/temp33.dbf' to '/mnt/data/PBF/db/proddata/temp33.dbf';
alter database rename file '/data/prod/proddata/temp43.dbf' to '/mnt/data/PBF/db/proddata/temp43.dbf';
alter database rename file '/data/prod/proddata/temp31.dbf' to '/mnt/data/PBF/db/proddata/temp31.dbf';
alter database rename file '/data/prod/proddata/temp41.dbf' to '/mnt/data/PBF/db/proddata/temp41.dbf';

12、處理 redolog重建時出現的 ORA-00312錯誤
 

SQL> alter database open resetlogs;
alter database open resetlogs *
ERROR at line 1:
ORA-00392: log 4 of thread 1 is being cleared, operation not allowed
ORA-00312: online log 4 thread 1: '/mnt/data/PBF/db/proddata/redo04a.log'
ORA-00312: online log 4 thread 1: '/mnt/data/PBF/db/proddata/redo04b.log'

 
(1)查詢redolog文件及其狀態
 

col group# form 99
 col bytes form 99999999999
 col status form a20
select group#,bytes/1024/1024||'M',status from v$log;

(2)修改redolog文件的狀態

 alter database clear logfile group 1;
 alter database clear logfile group 2;
 alter database clear logfile group 3;
 alter database clear logfile group 4;
 alter database clear logfile group 5;



(3)再次確認其狀態

 select group#,bytes/1024/1024||'M',status from v$log;



 13、使用resetlogs方式打開
 

SQL> alter database open resetlogs;


 
 14、創建新的spfile文件

create spfile from pfile;



 15、重新啓動並備份數據庫

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章