控制檔案損壞重建實驗(下)

realkid4發表於2013-02-21

在上篇中,我們討論並且演示瞭如何利用Trace檔案恢復控制檔案。但是我們的控制檔案中包括的備份資訊,卻不能儲存在Trace檔案的create control file語句裡面。

 

那麼,我們有什麼方法儲存住備份資訊呢?具體有兩個方法,使用catalogbackup set載入。下面我們分別進行演示。

 

4Catalog備份資訊保留

 

預設情況下,RMAN將備份資訊儲存在target資料庫的control file中。如果發生我們所實驗的情況,備份資訊將全部消失。另外一種RMAN推薦的方法是將這些備份資訊儲存在另外資料庫異地儲存,就是catalog

 

如果我們能夠在catalog中備份一份關於target資料庫備份資料庫的備份資訊,就可以實現Backup資訊的留存。

 

首先,我們在實驗環境上建立資料庫備份。

 

 

RMAN> backup database plus archivelog delete all input;

 

Starting backup at 20-FEB-13

current log archived

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=142 devtype=DISK

(篇幅原因,省略部分內容……

handle=/u01/app/oracle/flash_recovery_area/ORA10GL/backupset/2013_02_20/o1_mf_annnn_TAG20130220T152242_8l8yg3jb_.bkp tag=TAG20130220T152242 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: deleting archive log(s)

archive log filename=/u01/app/oracle/flash_recovery_area/ORA10GL/archivelog/2013_02_20/o1_mf_1_9_8l8yg1bc_.arc recid=5 stamp=807895362

Finished backup at 20-FEB-13

 

Starting Control File and SPFILE Autobackup at 20-FEB-13

piece handle=/u01/app/oracle/flash_recovery_area/ORA10GL/autobackup/2013_02_20/o1_mf_s_807895365_8l8ygb77_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 20-FEB-13

 

RMAN>

 

 

 

我們在另一臺資料庫建立catalog,其中包括使用者建立、專用表空間建立和許可權賦值。

 

 

 

SQL> create tablespace rman_bk datafile size 500M autoextend on extent management local uniform. size 1m segment space management auto;

Tablespace created

 

SQL> CREATE USER rman IDENTIFIED BY rman

  2         DEFAULT TABLESPACE RMAN_bk

  3         TEMPORARY TABLESPACE temp;

User created

 

SQL> GRANT CONNECT, RESOURCE, RECOVERY_CATALOG_OWNER TO rman;

Grant succeeded

 

 

之後,登入RMAN建立出catalog目錄。

 

 

RMAN> create catalog;

恢復目錄已建立

 

 

登入target資料庫,注意使用catalog連線,之後進行註冊。

 

 

[oracle@bspdev ~]$ rman target / catalog rman/rman@ora11gw

 

Recovery Manager: Release 10.2.0.1.0 - Production on Wed Feb 20 16:16:30 2013

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

 

connected to target database: ORA10GL (DBID=4006742303)

connected to recovery catalog database

 

RMAN> register database;

 

database registered in recovery catalog

starting full resync of recovery catalog

full resync complete

 

 

下面,我們開始嘗試刪除控制檔案實驗,並且恢復。首先需要進行一次完全的關閉過程。

 

 

SQL> conn / as sysdba

Connected.

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

 

 

刪除原有的控制檔案。

 

 

[oracle@bspdev controlfile]$ ls -l

total 14136

-rw-r----- 1 oracle oinstall 7389184 Feb 20 16:18 control01.ctl

-rw-r----- 1 oracle oinstall 7061504 Feb 20 14:47 o1_mf_8brvwzwc_.ctl.bk

[oracle@bspdev controlfile]$ mv control01.ctl control01.ctl.bk

[oracle@bspdev controlfile]$ ls -l

total 14136

-rw-r----- 1 oracle oinstall 7389184 Feb 20 16:18 control01.ctl.bk

-rw-r----- 1 oracle oinstall 7061504 Feb 20 14:47 o1_mf_8brvwzwc_.ctl.bk

 

 

啟動資料庫,進行恢復。

 

 

SQL> startup nomount

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             109053520 bytes

Database Buffers          171966464 bytes

Redo Buffers                2973696 bytes

SQL>

SQL> CREATE CONTROLFILE REUSE DATABASE "ORA10GL" NORESETLOGS  ARCHIVELOG

  2      MAXLOGFILES 16

  3      MAXLOGMEMBERS 3

  4      MAXDATAFILES 100

  5      MAXINSTANCES 8

  6      MAXLOGHISTORY 292

  7  LOGFILE

  8    GROUP 1 (

  9      '/u01/app/oracle/oradata/ORA10GL/onlinelog/o1_mf_1_8brvx1mo_.log',

 10      '/u01/app/oracle/flash_recovery_area/ORA10GL/onlinelog/o1_mf_1_8brvx3s1_.log'

 11    ) SIZE 50M,

 12    GROUP 2 (

 13      '/u01/app/oracle/oradata/ORA10GL/onlinelog/o1_mf_2_8brvx94v_.log',

 14      '/u01/app/oracle/flash_recovery_area/ORA10GL/onlinelog/o1_mf_2_8brvxc8g_.log'

 15    ) SIZE 50M,

 16    GROUP 3 (

 17      '/u01/app/oracle/oradata/ORA10GL/onlinelog/o1_mf_3_8brvxfk5_.log',

 18      '/u01/app/oracle/flash_recovery_area/ORA10GL/onlinelog/o1_mf_3_8brvxhkc_.log'

 19    ) SIZE 50M

 20  -- STANDBY LOGFILE

 21  DATAFILE

 22    '/u01/app/oracle/oradata/ORA10GL/datafile/o1_mf_system_8brvr0gf_.dbf',

 23    '/u01/app/oracle/oradata/ORA10GL/datafile/o1_mf_undotbs1_8brvr10h_.dbf',

 24    '/u01/app/oracle/oradata/ORA10GL/datafile/o1_mf_sysaux_8brvr0j3_.dbf',

 25    '/u01/app/oracle/oradata/ORA10GL/datafile/o1_mf_users_8brvr12n_.dbf'

 26  CHARACTER SET AL32UTF8

 27  ;

 

Control file created.

 

SQL>

 

 

後續恢復動作。

 

 

SQL> VARIABLE RECNO NUMBER;

SQL> EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');

 

PL/SQL procedure successfully completed.

 

SQL> recover database;

ORA-00283: recovery session canceled due to errors

ORA-00264: no recovery required

 

SQL> ALTER SYSTEM ARCHIVE LOG ALL;

System altered.

 

SQL> ALTER DATABASE OPEN;

Database altered.

 

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/ORA10GL/datafile/o1_mf_temp_8brvy20c_.tmp'

  2       SIZE 20971520  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;

Tablespace altered.

 

 

 

此時,僅檢視控制檔案中的備份資訊如下。

 

 

RMAN> list backup;

 

RMAN>

 

原有的備份內容消失不見。

 

當我們連入catalog的時候,還是可以看到catalog中儲存的資訊。

 

 

[oracle@bspdev ~]$ rman target / catalog rman/rman@ora11gw

 

Recovery Manager: Release 10.2.0.1.0 - Production on Wed Feb 20 16:26:22 2013

 

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

 

connected to target database: ORA10GL (DBID=4006742303)

connected to recovery catalog database

 

RMAN> list backup

2> ;

 

starting full resync of recovery catalog

full resync complete

 

List of Backup Sets

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

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

27      Full    7.11M      DISK        00:00:07     20-FEB-13     

        BP Key: 33   Status: AVAILABLE  Compressed: NO  Tag: TAG20130220T150218

        Piece Name: /u01/app/oracle/flash_recovery_area/ORA10GL/autobackup/2013_02_20/o1_mf_s_807894138_8l8x7y1j_.bkp

  Control File Included: Ckp SCN: 545929       Ckp time: 20-FEB-13

  SPFILE Included: Modification time: 20-FEB-13

(篇幅原因,省略部分內容……

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

31      Full    7.11M      DISK        00:00:09     20-FEB-13     

        BP Key: 37   Status: AVAILABLE  Compressed: NO  Tag: TAG20130220T152245

        Piece Name: /u01/app/oracle/flash_recovery_area/ORA10GL/autobackup/2013_02_20/o1_mf_s_807895365_8l8ygb77_.bkp

  Control File Included: Ckp SCN: 546755       Ckp time: 20-FEB-13

  SPFILE Included: Modification time: 20-FEB-13

 

 

注意,此時即使嘗試手工同步。我們也沒能將catalog資訊同步到控制檔案上。

 

 

RMAN> resync catalog;

 

starting full resync of recovery catalog

full resync complete

 

[oracle@bspdev ~]$ rman nocatalog

 

Recovery Manager: Release 10.2.0.1.0 - Production on Wed Feb 20 16:39:58 2013

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

 

RMAN> connect target /

 

connected to target database: ORA10GL (DBID=4006742303)

using target database control file instead of recovery catalog

 

RMAN> list backup;

 

 

說明,使用Catalog可以實現控制檔案備份資訊的保留。

 

5RMAN命令進行強制註冊

 

另外一種方法是在恢復結束之後,手工將備份集合檔案註冊上。這種方法選擇性較強,也比較簡單。

 

首先,我們確定控制檔案中應有的備份集合不再其中。

 

[oracle@bspdev ~]$ rman nocatalog

 

Recovery Manager: Release 10.2.0.1.0 - Production on Thu Feb 21 15:53:14 2013

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

 

RMAN> connect target /

 

connected to target database: ORA10GL (DBID=4006742303)

using target database control file instead of recovery catalog

 

RMAN> list backup;

 

List of Backup Sets

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

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

1       Full    7.11M      DISK        00:00:05     20-FEB-13     

        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20130220T170340

        Piece Name: /u01/app/oracle/flash_recovery_area/ORA10GL/autobackup/2013_02_20/o1_mf_s_807901420_8l94cgs9_.bkp

  Control File Included: Ckp SCN: 551107       Ckp time: 20-FEB-13

  SPFILE Included: Modification time: 20-FEB-13

 

RMAN>

 

 

備份集合全部儲存在recovery area中。

 

 

SQL> show parameter recovery

 

NAME                                 TYPE        VALUE

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

db_recovery_file_dest                string      /u01/app/oracle/flash_recovery_area

db_recovery_file_dest_size           big integer 5000M

recovery_parallelism                 integer     0

 

 

確定目錄下有檔案。

 

 

[oracle@bspdev ORA10GL]$ pwd

/u01/app/oracle/flash_recovery_area/ORA10GL

[oracle@bspdev ORA10GL]$ ls -l

total 20

drwxr-x--- 5 oracle oinstall 4096 Feb 21 15:45 archivelog

drwxr-x--- 4 oracle oinstall 4096 Feb 20 15:02 autobackup

drwxr-x--- 3 oracle oinstall 4096 Feb 20 15:22 backupset

drwxr-x--- 2 oracle oinstall 4096 Feb 20 14:49 controlfile

drwxr-x--- 2 oracle oinstall 4096 Nov 21 14:07 onlinelog

 

 

登入RMAN,使用catalog命令將備份檔案註冊上。當備份都在同一目錄結構時,可以使用start with “”命令,讓RMAN自己定位。

 

 

RMAN> catalog start with '/u01/app/oracle/flash_recovery_area/ORA10GL';

 

searching for all files that match the pattern /u01/app/oracle/flash_recovery_area/ORA10GL

 

List of Files Unknown to the Database

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

File Name: /u01/app/oracle/flash_recovery_area/ORA10GL/archivelog/2012_11_26/o1_mf_1_5_8c5gxrwf_.arc

File Name:

(篇幅原因,有省略……

_8l8ygb77_.bkp

File Name: /u01/app/oracle/flash_recovery_area/ORA10GL/controlfile/o1_mf_8brvx088_.ctl.bk

 

--確定是否真正的載入註冊。

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

cataloging files...

cataloging done

 

List of Cataloged Files

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

File Name: /u01/app/oracle/flash_recovery_area/ORA10GL/archivelog/2012_11_26/o1_mf_1_5_8c5gxrwf_.arc

(篇幅原因,有省略……

List of Files Which Where Not Cataloged

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

File Name: /u01/app/oracle/flash_recovery_area/ORA10GL/controlfile/o1_mf_8brvx088_.ctl.bk

  RMAN-07519: Reason: Error while cataloging. See alert.log.

 

RMAN>

 

 

最後有一個之前使用的控制檔案沒有被識別,是正常現象。下面我們判斷結果。

 

 

RMAN> list backup;

 

List of Backup Sets

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

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

1       Full    7.11M      DISK        00:00:05     20-FEB-13     

        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20130220T170340

        Piece Name: /u01/app/oracle/flash_recovery_area/ORA10GL/autobackup/2013_02_20/o1_mf_s_807901420_8l94cgs9_.bkp

  Control File Included: Ckp SCN: 551107       Ckp time: 20-FEB-13

  SPFILE Included: Modification time: 20-FEB-13

(篇幅原因,有省略……

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

7       Full    7.11M      DISK        00:00:00     20-FEB-13     

        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20130220T152245

        Piece Name: /u01/app/oracle/flash_recovery_area/ORA10GL/autobackup/2013_02_20/o1_mf_s_807895365_8l8ygb77_.bkp

  Control File Included: Ckp SCN: 546755       Ckp time: 20-FEB-13

  SPFILE Included: Modification time: 20-FEB-13

 

RMAN>

 

 

載入成功,注意此處backup set的相當於重新編號。除了使用start with命令進行特定目錄的全載入,還有catalog autobackup等命令直接有目的的載入特定的備份檔案集。

 

6、總結

 

Control File是整個資料庫的心臟,關係重大。本篇演示瞭如何進行控制檔案的重建,以及之後的相關處理。權當記錄,供有需要的朋友不時之需。

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

相關文章