2014年3月23日 星期日

[Rman]將備份檔還原到異機

        假設要將QA1的Rman備份還原到QA2,首先在QA1用Rman完整備份,記得archivelog與controlfile都要備份,命令如下

RMAN>run { allocate channel t1 type disk; allocate channel t2 type disk; CROSSCHECK ARCHIVELOG ALL; DELETE NOPROMPT EXPIRED ARCHIVELOG ALL ; backup full format '/home/oracle/rman_backup/db_%T_%u_%s_%p' database include current controlfile; sql 'alter system archive log current'; backup format '/home/oracle/rman_backup/archive_%T_%u_%s_%p' archivelog all delete input; delete noprompt obsolete; crosscheck backup; Release Channel t1; Release Channel t2; }

        QA1備份完成後,將備份檔傳送到QA2,此例是兩台目錄結構都一樣的喔,命令如下,我有先設定ssh免密碼登入喔,所以可以不用敲帳密

QA1:/home/oracle/rman_backup>scp * 10.10.1.9:/home/oracle/rman_backup

        在QA2上,記得將來自QA1的備份檔變更擁有者,要讓Oracle有權限喔,要不然還原spfile時就會出錯了

QA2:/home/oracle/rman_backup>chown -R oracle:dba *

        如果此時QA2是乾淨未安裝起始資料庫的話,這步驟可以忽略,如果有安裝過資料庫的話,建議先刪掉資料庫相關檔案吧,下面的命令是先shutdown後,再刪除spfile與pfile及datafile,供參考囉

QA2:/home/oracle/112/dbs>sqlplus / as sysdba
23:48:08 sys:ORCL>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

23:48:27 sys:ORCL>exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

QA2:/home/oracle/112/dbs>rm initORCL.ora
QA2:/home/oracle/112/dbs>rm spfileORCL.ora
QA2:/home/oracle/DBSpace>rm -rf *


        接著就在QA2上開始進行還原囉,先初始環境變數,再用Rman啟動但不掛載

QA2:/home/oracle>export ORACLE_SID=ORCL
QA2:/home/oracle/112/dbs>export ORA_RMAN_SGA_TARGET=350

QA2:/home/oracle>rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Fri Mar 21 16:43:16 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> startup nomount

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/home/oracle/112/dbs/initORCL.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area     367439872 bytes

Fixed Size                     2228464 bytes
Variable Size                247467792 bytes
Database Buffers             109051904 bytes
Redo Buffers                   8691712 bytes

        首先還原spfile,備份檔名自行更改

RMAN> restore spfile from '/home/oracle/rman_backup/c-1404216946-20140321-02';        

Starting restore at 20140321165704
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1345 device type=DISK

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /tmp/rman_backup/c-1404216946-20140319-07
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 20140321165706

        這邊我看有人是可以直接還原controlfile的,但我試過發現會還原到不同的位置,而且還要自行拷貝出另外幾個檔,太麻煩,自己試了發現先shutdown,再啟動吃剛還原好的spfile就ok了

RMAN> shutdown immediate

Oracle instance shut down

RMAN> exit

Recovery Manager complete.

QA2:/home/oracle>rman target /         

Recovery Manager: Release 11.2.0.3.0 - Production on Sat Mar 22 00:36:55 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> startup nomount

Oracle instance started

Total System Global Area   10689474560 bytes

Fixed Size                     2237776 bytes
Variable Size               1610615472 bytes
Database Buffers            9059696640 bytes
Redo Buffers                  16924672 bytes

        這邊就可以還原controlfile的囉,注意還原的位置喔,應該要跟原來的一樣

RMAN> restore controlfile from '/home/oracle/rman_backup/c-1404216946-20140321-02';

Starting restore at 20140322003735
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1345 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/oracle/DBSpace/control01.ctl
output file name=/home/oracle/DBSpace/control02.ctl
output file name=/home/oracle/DBSpace/control03.ctl

Finished restore at 20140322003737

        接著強制啟動並掛載

RMAN> startup force mount

Oracle instance started
database mounted

Total System Global Area   10689474560 bytes

Fixed Size                     2237776 bytes
Variable Size               1610615472 bytes
Database Buffers            9059696640 bytes
Redo Buffers                  16924672 bytes

        接著還原database,下面的log我有做刪減,注意有沒有error喔

RMAN> restore database;

Starting restore at 20140321172659
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1345 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /home/oracle/DBSpace/system01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /home/oracle/DBSpace/undo01.dbf
...
channel ORA_DISK_1: reading from backup piece /home/oracle/rman_backup/db_20140327_2tp48074_93_1
channel ORA_DISK_1: piece handle=/home/oracle/rman_backup/db_20140327_2tp48074_93_1 tag=TAG20140327T145116
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:03:35
Finished restore at 27-MAR-14

        接著恢復database,最下面有錯誤是正常的

RMAN> recover database;

Starting recover at 20140321173554
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=40
channel ORA_DISK_1: reading from backup piece /home/oracle/rman_backup/archive_20140319_1ep3j1u3_46_1
channel ORA_DISK_1: errors found reading piece handle=/home/oracle/rman_backup/archive_20140319_1ep3j1u3_46_1
channel ORA_DISK_1: failover to piece handle=/tmp/rman_backup/archive_20140319_1ep3j1u3_46_1 tag=TAG20140319T161147
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/home/oracle/DBSpace/ARCHarch_1_40_830652082.arc thread=1 sequence=40
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=41
channel ORA_DISK_1: reading from backup piece /home/oracle/rman_backup/archive_20140319_1fp3j1u5_47_1
channel ORA_DISK_1: errors found reading piece handle=/home/oracle/rman_backup/archive_20140319_1fp3j1u5_47_1
channel ORA_DISK_1: failover to piece handle=/tmp/rman_backup/archive_20140319_1fp3j1u5_47_1 tag=TAG20140319T161147
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/home/oracle/DBSpace/ARCHarch_1_41_830652082.arc thread=1 sequence=41
unable to find archived log
archived log thread=1 sequence=42
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 03/21/2014 17:35:58
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 42 and starting SCN of 5610662

        開啟資料庫吧

RMAN> alter database open resetlogs;


database opened

        看到database opened就表示還原完成囉

0 意見:

張貼留言