無處不在的Oracle資料庫控制檔案備份

尛樣兒發表於2012-05-03
        Oracle資料庫控制檔案的存在對於Oracle資料庫恢復來說是很重要的,基於此Oracle控制檔案的備份是無處不在的。下面我們來詳細討論Oracle控制檔案存在的備份:

1.RMAN自動備份控制檔案。

1).啟用控制檔案自動備份:

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

2).控制檔案自動備份:
RMAN> backup device type disk format '/tmp/%U' datafile 4;

Starting backup at 2012-01-13 09:50:40
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA1/ractest/datafile/users.259.769378773
channel ORA_DISK_1: starting piece 1 at 2012-01-13 09:50:40
channel ORA_DISK_1: finished piece 1 at 2012-01-13 09:50:41
piece handle=/tmp/0bn0lb3g_1_1 tag=TAG20120113T095040 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2012-01-13 09:50:41

Starting Control File and SPFILE Autobackup at 2012-01-13 09:50:41
piece handle=/u01/app/oracle/product/11.2.0/db_1/dbs/c-3297696735-20120113-01 comment=NONE
Finished Control File and SPFILE Autobackup at 2012-01-13 09:50:48

        c-3297696735-20120113-01檔案是RMAN自動備份的控制檔案,該檔案位於$ORACLE_HOME/dbs目錄下,存放在該目錄下能夠避免儲存的損壞帶來的所有備份控制檔案的丟失。該檔案的名稱中c是control的縮寫,3297696735是DBID,20120113是日期,01是序號:
SQL> select dbid from v$database;

      DBID
----------
3297696735

SQL> select to_char(sysdate,'yyyymmdd') from dual;

TO_CHAR(
--------
20120113

        控制檔案的備份是非常小的,開啟RMAN對控制檔案的自動備份基本不會帶來問題。

2.控制檔案快照。
1).執行備份操作:
RMAN> backup device type disk format '/tmp/%U' datafile 4;

Starting backup at 2012-01-13 10:21:52
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA1/ractest/datafile/users.259.769378773
channel ORA_DISK_1: starting piece 1 at 2012-01-13 10:21:53
channel ORA_DISK_1: finished piece 1 at 2012-01-13 10:21:54
piece handle=/tmp/0kn0lcu0_1_1 tag=TAG20120113T102152 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2012-01-13 10:21:54

Starting Control File and SPFILE Autobackup at 2012-01-13 10:21:54
piece handle=/u01/app/oracle/product/11.2.0/db_1/dbs/c-3297696735-20120113-03 comment=NONE
Finished Control File and SPFILE Autobackup at 2012-01-13 10:22:01

2).檢視控制檔案快照的生成時間:
[oracle@rhel1 dbs]$ ls sna* --full-time|awk '{print $6,$7}'
2012-01-13 10:21:57.000000000
       
        從上面的輸出可以看出在控制檔案和SPFILE備份的時候會產生一個新的控制檔案快照,控制檔案快照同樣可用於資料庫的恢復。


3.無處不在的控制檔案快照。
       
        下面的操作是在關閉了RMAN控制檔案自動備份的情況下執行的。

1).使用RMAN執行備份操作:
RMAN> backup device type disk format '/tmp/%U' database skip offline;

Starting backup at 2012-01-13 10:11:56
using channel ORA_DISK_1
skipping offline file 7
RMAN-06060: WARNING: skipping datafile compromises tablespace TEST recoverability
RMAN-06060: WARNING: skipping datafile compromises tablespace TEST recoverability
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA1/ractest/datafile/system.256.769378761
input datafile file number=00002 name=+DATA1/ractest/datafile/sysaux.257.769378769
input datafile file number=00003 name=+DATA1/ractest/datafile/undotbs1.258.769378771
input datafile file number=00005 name=+DATA1/ractest/datafile/undotbs2.264.769379825
input datafile file number=00004 name=+DATA1/ractest/datafile/users.259.769378773
input datafile file number=00006 name=+OCR_DATA2/ractest/datafile/test.256.771175117
channel ORA_DISK_1: starting piece 1 at 2012-01-13 10:11:57
channel ORA_DISK_1: finished piece 1 at 2012-01-13 10:14:30
piece handle=/tmp/0hn0lcbd_1_1 tag=TAG20120113T101156 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:33
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2012-01-13 10:14:33
channel ORA_DISK_1: finished piece 1 at 2012-01-13 10:14:34
piece handle=/tmp/0in0lcg6_1_1 tag=TAG20120113T101156 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2012-01-13 10:14:34

2).檢視控制檔案快照生成的時間:
[oracle@rhel1 dbs]$ ls sna* --full-time|awk '{print $6,$7}'
2012-01-13 10:14:33.000000000

       在對database執行備份的時候,即使沒有開啟RMAN對控制檔案的自動備份,RMAN也會自動備份控制檔案和SPFILE到備份片,但是該備份片與備份存放在一起,而非存放在$ORACLE_HOME/dbs目錄下,且在備份控制檔案和SPFILE檔案前會新生成一個控制檔案快照。
         
         請注意,如果開啟了RMAN對控制檔案的自動備份,那麼在對database執行備份的時候就不會再像上面那樣自動備份控制檔案和SPFILE檔案到備份片。


總結:
        從上面的例子可以看出,Oracle控制檔案真是無處不在,丟失控制檔案的情況可以說很難發生,即使丟失我們也可以透過其他方法來恢復資料庫,請參考文章:http://space.itpub.net/23135684/viewspace-711883。另外,在資料結構發生變化或備份指令碼中使用ALTER DATABASE BACKUP CONTROLFILE命令備份控制檔案也是可以考慮的方法。

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

相關文章