备份保留策略的目的是确保数据库的可恢复性的同时提高空间利用率,它决定了那些数据文件需要被备份及短期性文件如何被删除。一般是通过命令configure进行配置,持久保存与控制文件和恢复编录中,策略分为两种:备份冗余读和恢复窗口的大小。由configure retentionn policy命令设置,与report need backup、report obsolete、delete obsolete命令及快速恢复区配合使用。无论采取那种保留策略,如果rman认为某个备份需要保留,那么该备份之后产生的归档日志也必须保留。
一:备份冗余度
##备份冗余度是指同一文件(
指包含控制文件和数据文件)的备份数量,比如将冗余度设置为1,表示
控制文件和所有的数据文件只需要保留一份全备份及其后期产生的归档日志
##1.将备份策略设置为冗余度2
RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
new RMAN configuration parameters are successfully stored
##2.先将之前的备份全部删除,通过以下命令查看有那些文件需要备份
###bkps:表示当前拥有的备份数量(包含disk备份和copy两种类型)
RMAN> report need backup;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
Report of files with less than 2 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------
1 0 /oradata/orcl/system01.dbf
2 0 /oradata/orcl/users02.dbf
3 0 /oradata/orcl/sysaux01.dbf
4 0 /oradata/orcl/undotbs01.dbf
5 0 /oradata/orcl/lhh02.dbf
7 0 /oradata/orcl/users01.dbf
##3.执行第一次备份,再次查看需要的备份信息
RMAN> backup database;
Starting backup at 19-MAR-22
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=00001 name=/oradata/orcl/system01.dbf
input datafile file number=00003 name=/oradata/orcl/sysaux01.dbf
input datafile file number=00007 name=/oradata/orcl/users01.dbf
input datafile file number=00004 name=/oradata/orcl/undotbs01.dbf
input datafile file number=00005 name=/oradata/orcl/lhh02.dbf
input datafile file number=00002 name=/oradata/orcl/users02.dbf
channel ORA_DISK_1: starting piece 1 at 19-MAR-22
channel ORA_DISK_1: finished piece 1 at 19-MAR-22
piece handle=/home/oracle/fra/ORCL/backupset/2022_03_19/o1_mf_nnndf_TAG20220319T125817_k3brq9jl_.bkp tag=TAG20220319T125817 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 19-MAR-22
Starting Control File and SPFILE Autobackup at 19-MAR-22
piece handle=/home/oracle/fra/ORCL/autobackup/2022_03_19/o1_mf_s_1099738206_k3brqdq1_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 19-MAR-22
##说明:#bkps=1说明已经有一次全备记录了
RMAN> report need backup;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
Report of files with less than 2 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------
1 1 /oradata/orcl/system01.dbf
2 1 /oradata/orcl/users02.dbf
3 1 /oradata/orcl/sysaux01.dbf
4 1 /oradata/orcl/undotbs01.dbf
5 1 /oradata/orcl/lhh02.dbf
7 1 /oradata/orcl/users01.dbf
##4.再次进行全备
RMAN> backup database;
Starting backup at 19-MAR-22
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=00001 name=/oradata/orcl/system01.dbf
input datafile file number=00003 name=/oradata/orcl/sysaux01.dbf
input datafile file number=00007 name=/oradata/orcl/users01.dbf
input datafile file number=00004 name=/oradata/orcl/undotbs01.dbf
input datafile file number=00005 name=/oradata/orcl/lhh02.dbf
input datafile file number=00002 name=/oradata/orcl/users02.dbf
channel ORA_DISK_1: starting piece 1 at 19-MAR-22
channel ORA_DISK_1: finished piece 1 at 19-MAR-22
piece handle=/home/oracle/fra/ORCL/backupset/2022_03_19/o1_mf_nnndf_TAG20220319T130006_k3brtp9c_.bkp tag=TAG20220319T130006 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 19-MAR-22
Starting Control File and SPFILE Autobackup at 19-MAR-22
piece handle=/home/oracle/fra/ORCL/autobackup/2022_03_19/o1_mf_s_1099738206_k3brtscy_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 19-MAR-22
##再次查看那些文件需要备份满足备份策略
##这里已经没有任何文件输出,
RMAN> report need backup;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
Report of files with less than 2 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------
二:备份保留窗口
设置备份窗口保留日期
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS ;
##查看需要备份的信息
RMAN> report need backup;
RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 7 days
Report of files that must be backed up to satisfy 7 days recovery window
File Days Name
---- ----- -----------------------------------------------------
1 1878 /oradata/orcl/system01.dbf
3 1878 /oradata/orcl/sysaux01.dbf
4 1878 /oradata/orcl/undotbs01.dbf
5 17 /oradata/orcl/lhh02.dbf
7 1878 /oradata/orcl/users01.dbf
##执行手工备份后再次查看备份信息
##这里发现report need backup命令已经不输入任何文件信息了,那么也就是意味这时间窗口策略仅仅需要一份备份就能满足策略条件,只不过是窗口时间内的备份片不会过期
RMAN> backup database;
Starting backup at 19-MAR-22
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=00001 name=/oradata/orcl/system01.dbf
input datafile file number=00003 name=/oradata/orcl/sysaux01.dbf
input datafile file number=00007 name=/oradata/orcl/users01.dbf
input datafile file number=00004 name=/oradata/orcl/undotbs01.dbf
input datafile file number=00005 name=/oradata/orcl/lhh02.dbf
input datafile file number=00002 name=/oradata/orcl/users02.dbf
channel ORA_DISK_1: starting piece 1 at 19-MAR-22
channel ORA_DISK_1: finished piece 1 at 19-MAR-22
piece handle=/home/oracle/fra/ORCL/backupset/2022_03_19/o1_mf_nnndf_TAG20220319T131402_k3bsnt6z_.bkp tag=TAG20220319T131402 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 19-MAR-22
Starting Control File and SPFILE Autobackup at 19-MAR-22
piece handle=/home/oracle/fra/ORCL/autobackup/2022_03_19/o1_mf_s_1099738206_k3bsnx9w_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 19-MAR-22
RMAN> report need backup;
RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 7 days
Report of files that must be backed up to satisfy 7 days recovery window
File Days Name
---- ----- -----------------------------------------------------
三:过期备份片处理
1.备份策略修改成保留两份
RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
old RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
new RMAN configuration parameters are successfully stored
2.执行两次全备
RMAN> backup database;
RMAN> backup database;
3.查看是否还需要备份满足备份策略
##这里已经满足备份策略
RMAN> report need backup;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
Report of files with less than 2 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------
##再次进行全备
RMAN> backup database;
RMAN> backup database;
4.查看备份片信息
Status: AVAILABLE表示此备份片是可用的
RMAN> list backupset of database;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
104 Full 1.16G DISK 00:00:05 19-MAR-22
BP Key: 116 Status: AVAILABLE Compressed: NO Tag: TAG20220319T135804
Piece Name: /home/oracle/fra/ORCL/backupset/2022_03_19/o1_mf_nnndf_TAG20220319T135804_k3bw7dh7_.bkp
List of Datafiles in backup set 104
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
1 Full 3753713 19-MAR-22 NO /oradata/orcl/system01.dbf
2 Full 3754250 19-MAR-22 NO /oradata/orcl/users02.dbf
3 Full 3753713 19-MAR-22 3753832 NO /oradata/orcl/sysaux01.dbf
4 Full 3753713 19-MAR-22 NO /oradata/orcl/undotbs01.dbf
5 Full 3753713 19-MAR-22 NO /oradata/orcl/lhh02.dbf
7 Full 3754250 19-MAR-22 NO /oradata/orcl/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
106 Full 1.16G DISK 00:00:05 19-MAR-22
BP Key: 118 Status: AVAILABLE Compressed: NO Tag: TAG20220319T135929
Piece Name: /home/oracle/fra/ORCL/backupset/2022_03_19/o1_mf_nnndf_TAG20220319T135929_k3bwb1vb_.bkp
List of Datafiles in backup set 106
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
1 Full 3753713 19-MAR-22 NO /oradata/orcl/system01.dbf
2 Full 3754250 19-MAR-22 NO /oradata/orcl/users02.dbf
3 Full 3753713 19-MAR-22 3753832 NO /oradata/orcl/sysaux01.dbf
4 Full 3753713 19-MAR-22 NO /oradata/orcl/undotbs01.dbf
5 Full 3753713 19-MAR-22 NO /oradata/orcl/lhh02.dbf
7 Full 3754250 19-MAR-22 NO /oradata/orcl/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
108 Full 1.16G DISK 00:00:02 19-MAR-22
BP Key: 120 Status: AVAILABLE Compressed: NO Tag: TAG20220319T140028
Piece Name: /home/oracle/fra/ORCL/backupset/2022_03_19/o1_mf_nnndf_TAG20220319T140028_k3bwcwh4_.bkp
List of Datafiles in backup set 108
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
1 Full 3753713 19-MAR-22 NO /oradata/orcl/system01.dbf
2 Full 3754250 19-MAR-22 NO /oradata/orcl/users02.dbf
3 Full 3753713 19-MAR-22 3753832 NO /oradata/orcl/sysaux01.dbf
4 Full 3753713 19-MAR-22 NO /oradata/orcl/undotbs01.dbf
5 Full 3753713 19-MAR-22 NO /oradata/orcl/lhh02.dbf
7 Full 3754250 19-MAR-22 NO /oradata/orcl/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
110 Full 1.16G DISK 00:00:03 19-MAR-22
BP Key: 122 Status: AVAILABLE Compressed: NO Tag: TAG20220319T140958
Piece Name: /home/oracle/fra/ORCL/backupset/2022_03_19/o1_mf_nnndf_TAG20220319T140958_k3bwxpm9_.bkp
List of Datafiles in backup set 110
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
1 Full 3753713 19-MAR-22 NO /oradata/orcl/system01.dbf
2 Full 3754250 19-MAR-22 NO /oradata/orcl/users02.dbf
3 Full 3753713 19-MAR-22 3753832 NO /oradata/orcl/sysaux01.dbf
4 Full 3753713 19-MAR-22 NO /oradata/orcl/undotbs01.dbf
5 Full 3753713 19-MAR-22 NO /oradata/orcl/lhh02.dbf
7 Full 3754250 19-MAR-22 NO /oradata/orcl/users01.dbf
##查看过期备份
##一共有四个备份集,策略是保留2份,因此有里两个备份集是过期的
RMAN> report obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 949 17-MAR-22 /oradata/arch/1_529_1086360874.dbf
Archive Log 951 19-MAR-22 /oradata/arch/1_530_1086360874.dbf
Archive Log 952 19-MAR-22 /oradata/arch/1_531_1086360874.dbf
Backup Set 357 19-MAR-22
Backup Piece 357 19-MAR-22 /home/oracle/backup/fulli30opnkm_1_1
Backup Set 358 19-MAR-22
Backup Piece 358 19-MAR-22 /home/oracle/backup/fulli40opnkt_1_1
5.删除过期备份集
RMAN> delete noprompt obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process
archived log file name=/oradata/arch/1_530_1086360874.dbf thread=1 sequence=530
RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process
archived log file name=/oradata/arch/1_531_1086360874.dbf thread=1 sequence=531
