11gR2 RMAN归档日志删除策略

从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/23135684/viewspace-707393/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23135684/viewspace-707393/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值