oracle11gR2_64之ASM到檔案系統的rman異機恢復完整案例

dbhelper發表於2015-03-01

=========================================================================================================================
                                                  oracle11gR2_64之ASM到檔案系統的rman異機恢復完整案例
=========================================================================================================================
  Rman的異機恢復的作用很多,比如資料庫遷移,資料庫恢復,基於資料庫架構調整的還原恢復(比如從RAC--&gt>單例項,ASM--&gt>檔案系統),有時候搭建測試環境也會用到,不過,這種情況下相信選擇資料庫複製方式比較方便。

    這次做的是做基於ASM儲存的生產庫rman備份到普通檔案系統的還原恢復測試,我們原來的資料庫架構是基於普通檔案系統的單例項,後來改為基於ASM的單例項,所以這次的測試重要性不言而喻:一是測試備份的有效性,二是如果生產庫異常崩潰,且恢復時間不確定,又不希望影響業務太多時,可以將生產庫的備份還原恢復到以前的檔案系統庫上,i當然這屬於不完全恢復,有資料丟失,當然概率也很小.

下面是異機還原恢復完整案例:

      FS->FS的異機rman恢復請參見我的另外一篇博文:http://blog.itpub.net/29119536/viewspace-1171894/

(1)環境明細:

 

源庫

目標庫

作業系統

Redhat5 64

Redhat5 64

主機名

Rac01

recover.com

IP

192.168.11.112

192.168.11.113

資料庫版本

oracle 11.2.0.1.0

oracle 11.2.0.1.0

儲存方式

ASM

檔案系統

ORACLE_HOME

/u01/app/oracle/product/11.2.0/db_1

/u01/app/oracle/product/11.2.0/db_1

ORACLE_SID

bus

bus




(2)源庫備份明細:

------&gt>

備份週期為3天的rman0級備份指令碼如下:

----------------------------------&gt>

$RMAN nocatalog target /  log $RMAN_LOG_FILE append <

RUN { 

allocate channel c1 type disk;

allocate channel c2 type disk;

 

backup incremental level 0 DATABASE FORMAT '/archive/backup/rman_bus_dest/db_level_0_%U_%T' skip inaccessible    TAG='inc_level_0'; 

 

sql 'alter system archive log current';

 

backup FORMAT '/archive/backup/rman_bus_dest/arch_%U_%T' skip inaccessible  ARCHIVELOG ALL tag='bus_arch' DELETE ALL INPUT;  

backup current controlfile tag='bus_ctl' format='/archive/backup/rman_bus_dest/ctl_%U_%T';

backup spfile tag='bus_spfile' format='/archive/backup/rman_bus_dest/spfile_%U_%T';

 

release channel c2;

release channel c1;

}

report obsolete; 

delete noprompt obsolete; 

crosscheck backup; 

delete noprompt expired backup;

list backup summary;

EOF

--------&gt>備份出的檔案列表:

 

這裡選用的是20140522晚上2點開始的rman0級備份,pfile是通過spfile生成,然後scp到本地的,沒有通過restore pfile from ‘’方式進行.

(3)還原恢復過程:

-------&gt>修改scp過來的pfile檔案(這裡應該注意,源庫可能空間較大,關於sga,pga等酌情根據目標庫修改)然後startup nomount狀態,restorecontrolfile,

接著通過rman>catalog start with ‘’轉換備份目錄:

[oracle@recover admin]$ cat initbus.ora

bus.__db_cache_size=276824064

bus.__java_pool_size=4194304

bus.__large_pool_size=4194304

bus.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment

bus.__pga_aggregate_target=339738624

bus.__sga_target=503316480

bus.__shared_io_pool_size=0

bus.__shared_pool_size=209715200

bus.__streams_pool_size=0

*.aq_tm_processes=1

*.audit_file_dest='/u01/app/oracle/admin/bus/adump'

*.audit_trail='db'

*.compatible='11.2.0.0.0'

*.control_file_record_keep_time=14

*.control_files='/u01/app/oracle/oradata/bus/control01.ctl'

*.db_block_size=8192

*.db_create_file_dest='/u01/app/oracle/oradata/bus/'

*.db_domain=''

*.db_files=5000

*.db_name='bus'

*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'

*.db_recovery_file_dest_size=4070572032

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=busXDB)'

*.log_archive_format='%t_%s_%r.dbf'

*.memory_target=842006528

*.open_cursors=300

*.processes=500

*.remote_login_passwordfile='EXCLUSIVE'

*.sessions=555

*.undo_tablespace='UNDOTBS1'

----------&gt>startup nomount狀態:

SQL>startup nomount;

 

> rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Sun Nov 2 14:22:39 2008

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: bus(not mounted)
--恢復controlfile
RMAN> restore controlfile from '/home/oracle/back_dest/archbak/ctl_sqp8u854_1_1_20140522';

Starting restore at 02-NOV-08
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:05
output filename=/u01/app/oracle/oradata/bus/control01.ctl
Finished restore at 02-NOV-08

RMAN> sql 'alter database mount';
sql statement: alter database mount
released channel: ORA_DISK_1

[oracle@recover ~]$ rman target /

 

Recovery Manager: Release 11.2.0.1.0 - Production on Fri May 23 18:58:06 2014

 

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

 

connected to target database: BUS (DBID=3983926832, not open)

 

RMAN> catalog start with '/home/oracle/back_dest/archbak/';

 

 

using target database control file instead of recovery catalog

searching for all files that match the pattern /home/oracle/back_dest/archbak/

 

 

List of Files Unknown to the Database

=====================================

File Name: /home/oracle/back_dest/archbak/db_level_0_shp8ssd6_1_1_20140522

File Name: /home/oracle/back_dest/archbak/spfile_ssp8u85k_1_1_20140522

File Name: /home/oracle/back_dest/archbak/arch_smp8st1o_1_1_20140522

File Name: /home/oracle/back_dest/archbak/db_level_0_sip8ssdb_1_1_20140522

File Name: /home/oracle/back_dest/archbak/ctl_sqp8u854_1_1_20140522

 

 

Do you really want to catalog the above files (enter YES or NO)? yes

cataloging files...

cataloging done

 

 

List of Cataloged Files

=======================

File Name: /home/oracle/back_dest/archbak/db_level_0_shp8ssd6_1_1_20140522

File Name: /home/oracle/back_dest/archbak/spfile_ssp8u85k_1_1_20140522

File Name: /home/oracle/back_dest/archbak/arch_smp8st1o_1_1_20140522

File Name: /home/oracle/back_dest/archbak/db_level_0_sip8ssdb_1_1_20140522

File Name: /home/oracle/back_dest/archbak/ctl_sqp8u854_1_1_20140522

 

 

RMAN> run{

2> set  newname for datafile 1 to '/u01/app/oracle/oradata/bus/system.503.843163915';

3> set  newname for datafile 2 to '/u01/app/oracle/oradata/bus/sysaux.504.843163917';

4> set  newname for datafile 3 to '/u01/app/oracle/oradata/bus/undotbs1.505.843163917';

5> set  newname for datafile 4 to '/u01/app/oracle/oradata/bus/users.506.843163917';

6> set  newname for datafile 5 to '/u01/app/oracle/oradata/bus/example.263.843164031';

......

set  newname for datafile 68 to '/u01/app/oracle/oradata/bus/flt_report_data_201410.dbf';

set  newname for datafile 69 to '/u01/app/oracle/oradata/bus/flt_report_data_201411.dbf';

set  newname for datafile 70 to '/u01/app/oracle/oradata/bus/flt_report_data_201412.dbf';

restore database;

switch datafile all;

Recover database;

67> 68> 69> 70> 71> 72> 73> 74> recover database;

75> }

 

 

executing command: SET NEWNAME

......

executing command: SET NEWNAME

 

 

Starting restore at 23-MAY-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=19 device type=DISK

allocated channel: ORA_DISK_2

channel ORA_DISK_2: SID=21 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_2: restoring datafile 00070 to /u01/app/oracle/oradata/bus/flt_report_data_201412.dbf

channel ORA_DISK_2: reading from backup piece /archive/backup/rman_bus_dest/db_level_0_shp8ssd6_1_1_20140522

channel ORA_DISK_1: piece handle=/archive/backup/rman_bus_dest/db_level_0_sip8ssdb_1_1_20140522 tag=INC_LEVEL_0

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:13:29

channel ORA_DISK_2: piece handle=/archive/backup/rman_bus_dest/db_level_0_shp8ssd6_1_1_20140522 tag=INC_LEVEL_0

channel ORA_DISK_2: restored backup piece 1

channel ORA_DISK_2: restore complete, elapsed time: 00:19:41

Finished restore at 23-MAY-14

 

 

datafile 1 switched to datafile copy

input datafile copy RECID=72 STAMP=848344761 file name=/u01/app/oracle/oradata/bus/system.503.843163915

datafile 2 switched to datafile copy

input datafile copy RECID=73 STAMP=848344762 file name=/u01/app/oracle/oradata/bus/sysaux.504.843163917

datafile 3 switched to datafile copy

input datafile copy RECID=74 STAMP=848344762 file name=/u01/app/oracle/oradata/bus/undotbs1.505.843163917

......

datafile 69 switched to datafile copy

input datafile copy RECID=140 STAMP=848344772 file name=/u01/app/oracle/oradata/bus/flt_report_data_201411.dbf

datafile 70 switched to datafile copy

input datafile copy RECID=141 STAMP=848344772 file name=/u01/app/oracle/oradata/bus/flt_report_data_201412.dbf

 

 

Starting recover at 23-MAY-14

using channel ORA_DISK_1

using channel ORA_DISK_2

 

 

starting media recovery

 

 

Oracle Error: 

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below

ORA-01194: file 2 needs more recovery to be consistent

ORA-01110: data file 2: '/u01/app/oracle/oradata/bus/sysaux.504.843163917'

 

 

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 05/23/2014 19:19:38

RMAN-06053: unable to perform media recovery because of missing log

RMAN-06025: no backup of archived log for thread 1 with sequence 17274 and starting SCN of 1110262216 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17273 and starting SCN of 1110253282 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17272 and starting SCN of 1110247467 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17271 and starting SCN of 1110088491 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17270 and starting SCN of 1109910387 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17269 and starting SCN of 1109902919 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17268 and starting SCN of 1109895456 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17267 and starting SCN of 1109887730 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17266 and starting SCN of 1109751780 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17265 and starting SCN of 1109621814 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17264 and starting SCN of 1109617341 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17263 and starting SCN of 1109614193 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17262 and starting SCN of 1109608876 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17261 and starting SCN of 1109470180 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17260 and starting SCN of 1109384256 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17259 and starting SCN of 1109379300 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17258 and starting SCN of 1109374673 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17257 and starting SCN of 1109370814 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17256 and starting SCN of 1109299231 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17255 and starting SCN of 1109214476 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17254 and starting SCN of 1109208769 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17253 and starting SCN of 1109204568 found to restore

RMAN-06025: no backup of archived log for thread 1 with sequence 17252 and starting SCN of 1109199506 found to restore

RMAN> 

------&gt>此時資料庫啟動到mount狀態,但由於controlfile裡日誌路徑還是源庫基於ASM的設定,所以恢復找不到路徑,這裡通過重建controlfile來處理。注:源庫沒有catalog輔助庫,rman設定及備份資訊都是儲存在controlfile裡面,為了減少出錯概率,這裡忽略了rman的設定,其實意義也不大,畢竟相關目錄存在差異.

--------------&gt>recreate ctl:

CREATE CONTROLFILE REUSE DATABASE "BUS" RESETLOGS  ARCHIVELOG

    MAXLOGFILES 16

    MAXLOGMEMBERS 3

    MAXDATAFILES 100

    MAXINSTANCES 8

    MAXLOGHISTORY 3804

LOGFILE

  GROUP 1 (

     '/u01/app/oracle/oradata/bus/redo0101',

     '/u01/app/oracle/oradata/bus/redo0102'

  ) SIZE 50M BLOCKSIZE 512,

  GROUP 2 (

     '/u01/app/oracle/oradata/bus/redo0201',

    '/u01/app/oracle/oradata/bus/redo0202'

  ) SIZE 50M BLOCKSIZE 512,

  GROUP 3 (

     '/u01/app/oracle/oradata/bus/redo0301',

     '/u01/app/oracle/oradata/bus/redo0302'

  ) SIZE 50M BLOCKSIZE 512,

  GROUP 4 (

      '/u01/app/oracle/oradata/bus/redo0401',

      '/u01/app/oracle/oradata/bus/redo0402'

  ) SIZE 50M BLOCKSIZE 512,

  GROUP 5 (

    '/u01/app/oracle/oradata/bus/redo0501',

    '/u01/app/oracle/oradata/bus/redo0502'

  ) SIZE 50M BLOCKSIZE 512

-- STANDBY LOGFILE

DATAFILE

  '/u01/app/oracle/oradata/bus/system.dbf',

  '/u01/app/oracle/oradata/bus/sysaux.dbf',

  '/u01/app/oracle/oradata/bus/undotbs1.dbf',

  '/u01/app/oracle/oradata/bus/users.dbf',

  '/u01/app/oracle/oradata/bus/example.dbf',

  '/u01/app/oracle/oradata/bus/flt.dbf',

  '/u01/app/oracle/oradata/bus/fltidx.dbf',

  '/u01/app/oracle/oradata/bus/flt_data.dbf',

 ......

  '/u01/app/oracle/oradata/bus/flt_report_data_201410.dbf',

  '/u01/app/oracle/oradata/bus/flt_report_data_201411.dbf',

  '/u01/app/oracle/oradata/bus/flt_report_data_201412.dbf'

CHARACTER SET ZHS16GBK

;

----------------------&gt>recover database

RMAN> recover database;

 

Starting recover at 27-MAY-14

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=17250

channel ORA_DISK_1: restoring archived log

archived log thread=1 sequence=17251

channel ORA_DISK_1: reading from backup piece /home/oracle/back_dest/archbak/arch_smp8st1o_1_1_20140522

channel ORA_DISK_1: piece handle=/home/oracle/back_dest/archbak/arch_smp8st1o_1_1_20140522 tag=BUS_ARCH

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:15

archived log file name=/u01/app/oracle/oradata/arch/1_17250_843164019.dbf thread=1 sequence=17250

archived log file name=/u01/app/oracle/oradata/arch/1_17251_843164019.dbf thread=1 sequence=17251

unable to find archived log

archived log thread=1 sequence=17252

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 05/27/2014 10:18:51

RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 17252 and starting SCN of 1109199506

-----------------&gt>open resetlogs

[oracle@recover ~]$ rman target /

 

Recovery Manager: Release 11.2.0.1.0 - Production on Tue May 27 10:27:12 2014

 

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

 

connected to target database: BUS (DBID=3983926832, not open)

 

RMAN> alter database open resetlogs;

 

using target database control file instead of recovery catalog

database opened

 

RMAN> 

-----&gt>temp,undo表空間處理,收集統計資訊:

SQL> show parameters undo;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

undo_management                      string      AUTO

undo_retention                       integer     900

undo_tablespace                      string      UNDOTBS1

SQL> select tablespace_name from dba_tablespaces where contents='UNDO';

 

TABLESPACE_NAME

------------------------------

UNDOTBS1

 

SQL> select tablespace_name from dba_tablespaces where contents='TEMPORARY';

 

TABLESPACE_NAME

------------------------------

TEMP

SQL> create temporary tablespace TEMP1  tempfile '/u01/app/oracle/oradata/bus/temp01.dbf'  size 500M autoextend off;

 

Tablespace created.

 

SQL> alter database default temporary tablespace TEMP1;

 

Database altered.

 

SQL> drop tablespace TEMP including contents and datafiles;

 

Tablespace dropped.

 

SQL> select tablespace_name from dba_tablespaces where contents='TEMPORARY';

 

TABLESPACE_NAME

------------------------------

TEMP1

 

SQL> begin

  2  dbms_stats.gather_schema_stats(ownname => 'FLT',

  3                                 estimate_percent => dbms_stats.auto_sample_size,

  4                                 method_opt => 'for all columns size repeat',

  5                                 degree => 7);

  6  end;

  7  /

 

PL/SQL procedure successfully completed.

 

SQL> 

-------&gt>修改listener.ora,tnsnames.ora

[oracle@recover admin]$ more listener.ora

# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora

# Generated by Oracle configuration tools.

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.11.113)(PORT = 1521))

    )

  )

 

 

 

ADR_BASE_LISTENER = /u01/app/oracle

 

[oracle@recover admin]$ more tnsnames.ora

# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

 

BUS =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.11.113)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = bus)

    )

  )

(4)驗證恢復庫資料有效性:

--------&gt>資料結構物件對比:

----------  源庫-------------------   ----------目標恢復庫---------

SQL> select t.object_type,count(object_name) from user_objects t group by t.object_

                                                                                   

OBJECT_TYPE         COUNT(OBJECT_NAME)      OBJECT_TYPE         COUNT(OBJECT_NAME) 

------------------- ------------------       ------------------- ------------------

CLUSTER                              3       CLUSTER                              3

DATABASE LINK                        1       DATABASE LINK                        1

FUNCTION                             7       FUNCTION                             7

INDEX                              119       INDEX                              119

INDEX PARTITION                     72       INDEX PARTITION                     72

PACKAGE                             15       PACKAGE                             15

PACKAGE BODY                        15       PACKAGE BODY                        15

PROCEDURE                            1       PROCEDURE                            1

SEQUENCE                            47       SEQUENCE                            47

SYNONYM                             40       SYNONYM                             40

TABLE                              143       TABLE                              143

TABLE PARTITION                     98       TABLE PARTITION                     98

TABLE SUBPARTITION                 850       TABLE SUBPARTITION                 850

TRIGGER                             38       TRIGGER                             38

TYPE                                 3       TYPE                                 3

VIEW                                13       VIEW                                13

--------------------&gt>通過last_gps_position表資料驗證資料的有效性,因為備份是有522號晚上2點進行,所以該表中資料插入日期應該在5222點左右:

select TO_CHAR(t1.GATHER_DATE, 'YYYY-MM-DD hh24:mi:ss') from last_gps_position t1 

where t1.GATHER_DATE>TO_DATE('2014-05-22 00:00:00','YYYY-MM-DD hh24:mi:ss')

order by 1;

-------&gt>

 

(5)遇到問題及解決方法:

A1.由於源庫recovery_area_usage較大(5G),測試庫空間不足,recovery_area_usage設定較小,導致在做RMAN> catalog start with '/home/oracle/back_dest/archbak/'時進行到中終,異常退出,最後通過在pfile中註釋掉db_recovery_file_dest db_recovery_file_dest_size才得以通過.

A2.restore databaseVirtualBox中目標庫空間不足,異常退出,最後通過新增虛擬硬碟,重新restore database完成還原操作;

A3.在做recover database時由於儲存方式不同,導致不能應用到archivelog進行recovery,所以通過recreate controlfile來進行解決.
(6)鳴謝,最後真誠感謝cuug-王楠的幫助,那傢伙很厲害!當然,這案例中相信有很多不足和值得優化的地方,希望感興趣的朋友多多交流溝通,謝謝!

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

相關文章