11gR2 RMAN歸檔日誌刪除策略

kunlunzhiying發表於2017-03-08

從11gR2開始,RMAN引入了歸檔刪除策略的配置,下面我們透過簡單的例子來討論這個功能:
資料庫版本:
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production

1.檢視RMAN配置:
RMAN> show all;

RMAN configuration parameters for database with db_unique_name RACTEST are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 1 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_ractest.f'; # default
預設歸檔刪除策略沒有啟用。

2.啟用歸檔刪除策略:
RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;

new RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;
new RMAN configuration parameters are successfully stored
配置歸檔刪除策略,只要求歸檔備份一次到磁碟,之後歸檔就允許被刪除。

3.歸檔刪除策略測試1:
當前的歸檔日誌:
SQL> !ls -al /u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13
total 20
drwxr-x--- 2 oracle oinstall 4096 Sep 13 02:37 .
drwxr-x--- 4 oracle oinstall 4096 Sep 13 01:24 ..
-rw-r----- 1 oracle oinstall 1536 Sep 13 02:37 o1_mf_1_20_76wnbnfk_.arc
-rw-r----- 1 oracle oinstall 1536 Sep 13 02:37 o1_mf_1_21_76wnbrt0_.arc
-rw-r----- 1 oracle oinstall 1024 Sep 13 02:37 o1_mf_1_22_76wnbrv9_.arc

RMAN>  backup archivelog all delete all input;

Starting backup at 2011-09-13 02:37:42
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=20 RECID=16 STAMP=761711828
input archived log thread=1 sequence=21 RECID=17 STAMP=761711832
input archived log thread=1 sequence=22 RECID=18 STAMP=761711832
input archived log thread=1 sequence=23 RECID=19 STAMP=761711862
channel ORA_DISK_1: starting piece 1 at 2011-09-13 02:37:42
channel ORA_DISK_1: finished piece 1 at 2011-09-13 02:37:43
piece handle=/u01/app/oracle/fast_recovery_area/RACTEST/backupset/2011_09_13/o1_mf_annnn_TAG20110913T023742_76wncpk6_.bkp tag=TAG20110913T023742 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13/o1_mf_1_20_76wnbnfk_.arc RECID=16 STAMP=761711828
archived log file name=/u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13/o1_mf_1_21_76wnbrt0_.arc RECID=17 STAMP=761711832
archived log file name=/u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13/o1_mf_1_22_76wnbrv9_.arc RECID=18 STAMP=761711832
archived log file name=/u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13/o1_mf_1_23_76wncpd1_.arc RECID=19 STAMP=761711862
Finished backup at 2011-09-13 02:37:43
備份歸檔的同時刪除所有輸入的歸檔日誌檔案。

再次檢視歸檔日誌檔案,發現已經被刪除。
SQL> !ls -al /u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13
total 8
drwxr-x--- 2 oracle oinstall 4096 Sep 13 02:37 .
drwxr-x--- 4 oracle oinstall 4096 Sep 13 01:24 ..

4.歸檔刪除策略測試2:
修改歸檔日誌刪除策略,要求備份到磁碟的歸檔日誌有兩份才可以刪除:
RMAN>
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK
2> ;

old RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;
new RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK;
new RMAN configuration parameters are successfully stored

檢視當前的歸檔日誌:
SQL>  !ls -al /u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13
total 60
drwxr-x--- 2 oracle oinstall  4096 Sep 13 02:40 .
drwxr-x--- 4 oracle oinstall  4096 Sep 13 01:24 ..
-rw-r----- 1 oracle oinstall 47104 Sep 13 02:40 o1_mf_1_24_76wnkpn2_.arc
-rw-r----- 1 oracle oinstall  1024 Sep 13 02:40 o1_mf_1_25_76wnkt2l_.arc

執行歸檔備份和刪除:
RMAN> backup archivelog all delete all input;

Starting backup at 2011-09-13 02:41:25
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=24 RECID=20 STAMP=761712054
input archived log thread=1 sequence=25 RECID=21 STAMP=761712058
input archived log thread=1 sequence=26 RECID=22 STAMP=761712087
channel ORA_DISK_1: starting piece 1 at 2011-09-13 02:41:28
channel ORA_DISK_1: finished piece 1 at 2011-09-13 02:41:29
piece handle=/u01/app/oracle/fast_recovery_area/RACTEST/backupset/2011_09_13/o1_mf_annnn_TAG20110913T024128_76wnlr48_.bkp tag=TAG20110913T024128 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
RMAN-08138:
WARNING: archived log not deleted - must create more backups
archived log file
name=/u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13/o1_mf_1_24_76wnkpn2_.arc thread=1 sequence=24
RMAN-08138:
WARNING: archived log not deleted - must create more backups
archived log file
name=/u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13/o1_mf_1_25_76wnkt2l_.arc thread=1 sequence=25
RMAN-08138:
WARNING: archived log not deleted - must create more backups
archived log file
name=/u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13/o1_mf_1_26_76wnlqxq_.arc thread=1 sequence=26
Finished backup at 2011-09-13 02:41:29
執行同樣的備份歸檔同時刪除歸檔的命令,但是從返回的日誌中可以看出,歸檔日誌並沒有被刪除,這是由於我們將歸檔刪除策略修改為了至少備份兩份到磁碟。

SQL> !ls -al /u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13
total 64
drwxr-x--- 2 oracle oinstall  4096 Sep 13 02:41 .
drwxr-x--- 4 oracle oinstall  4096 Sep 13 01:24 ..
-rw-r----- 1 oracle oinstall 47104 Sep 13 02:40 o1_mf_1_24_76wnkpn2_.arc
-rw-r----- 1 oracle oinstall  1024 Sep 13 02:40 o1_mf_1_25_76wnkt2l_.arc
-rw-r----- 1 oracle oinstall  2048 Sep 13 02:41 o1_mf_1_26_76wnlqxq_.arc
歸檔日誌確實未被刪除!

5.歸檔刪除策略測試3:
將歸檔日誌備份策略修改為備份1份到磁碟:
RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;

old RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK;
new RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;
new RMAN configuration parameters are successfully stored

再次執行歸檔日誌備份:
RMAN> backup archivelog all;

Starting backup at 2011-09-13 02:45:36
current log archived
using channel ORA_DISK_1
skipping archived log file /u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13/o1_mf_1_24_76wnkpn2_.arc; already backed up 1 time(s)
skipping archived log file /u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13/o1_mf_1_25_76wnkt2l_.arc; already backed up 1 time(s)
skipping archived log file /u01/app/oracle/fast_recovery_area/RACTEST/archivelog/2011_09_13/o1_mf_1_26_76wnlqxq_.arc; already backed up 1 time(s)
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=27 RECID=23 STAMP=761712336
channel ORA_DISK_1: starting piece 1 at 2011-09-13 02:45:36
channel ORA_DISK_1: finished piece 1 at 2011-09-13 02:45:37
piece handle=/u01/app/oracle/fast_recovery_area/RACTEST/backupset/2011_09_13/o1_mf_annnn_TAG20110913T024536_76wntjqk_.bkp tag=TAG20110913T024536 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2011-09-13 02:45:37
由於之前已經有過一次歸檔的備份,所以再次備份歸檔日誌,已經有過一次備份的歸檔日誌檔案就被跳過,這和我們配置的歸檔刪除策略要求備份到磁碟的備份數是一致的。如果未設定歸檔日誌的刪除策略,那麼重複執行歸檔的備份就會出現重複備份歸檔日誌的情況。

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

相關文章