3、归档日志删除实验
下面继续进行第四次备份动作。
RMAN> backup database plus archivelog;
Starting backup at 21-SEP-15
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=592 device type=DISK
skipping archived logs of thread 1 from sequence 114 to 116; already backed up
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=117 RECID=29 STAMP=890990667
input archived log thread=1 sequence=118 RECID=30 STAMP=890993128
input archived log thread=1 sequence=119 RECID=31 STAMP=890993175
input archived log thread=1 sequence=120 RECID=32 STAMP=890994130
channel ORA_DISK_1: starting piece 1 at 21-SEP-15
channel ORA_DISK_1: finished piece 1 at 21-SEP-15
(篇幅原因,有省略……)
handle=/u01/app/oracle/fast_recovery_area/CHINAREDB/autobackup/2015_09_21/o1_mf_s_890994178_bzytj261_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 21-SEP-15
根据删除策略,备份过两次的日志,是不会继续备份的。
SQL> select recid, sequence#, archived, deleted, backup_count from v$archived_log where backup_count>1;
RECID SEQUENCE# ARCHIVED DELETED BACKUP_COUNT
---------- ---------- -------- ------- ------------
(篇幅原因,有省略……)
23 111 YES YES 2
24 112 YES YES 2
25 113 YES YES 2
26 114 YES YES 2
27 115 YES YES 2
28 116 YES NO 2
29 117 YES NO 2
30 118 YES NO 2
31 119 YES NO 2
20 rows selected
连续两次切换动作。
SQL> alter system switch logfile;
System altered
SQL> alter system switch logfile;
System altered
SQL> select recid, sequence#, archived, deleted, backup_count from v$archived_log where recid>18;
RECID SEQUENCE# ARCHIVED DELETED BACKUP_COUNT
---------- ---------- -------- ------- ------------
(篇幅原因,有省略……)
26 114 YES YES 2
27 115 YES YES 2
28 116 YES NO 2
29 117 YES NO 2
30 118 YES NO 2
31 119 YES NO 2
32 120 YES NO 1
33 121 YES NO 1
34 122 YES NO 0
35 123 YES NO 0
17 rows selected
在RMAN里面,可以使用archive log all进行直接的删除动作。
RMAN> delete archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=592 device type=DISK
RMAN-08138: WARNING: archived log not deleted - must create more backups
archived log file name=/u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_120_bzytgl7c_.arc thread=1 sequence=120
RMAN-08138: WARNING: archived log not deleted - must create more backups
archived log file name=/u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_121_bzytj0wf_.arc thread=1 sequence=121
RMAN-08138: WARNING: archived log not deleted - must create more backups
archived log file name=/u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_122_bzytlmsc_.arc thread=1 sequence=122
RMAN-08138: WARNING: archived log not deleted - must create more backups
archived log file name=/u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_123_bzytlpv0_.arc thread=1 sequence=123
List of Archived Log Copies for database with db_unique_name CHINAREDB
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
28 1 116 A 21-SEP-15
Name: /u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_116_bzypwksv_.arc
29 1 117 A 21-SEP-15
Name: /u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_117_bzyq2cc6_.arc
30 1 118 A 21-SEP-15
Name: /u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_118_bzysh8hg_.arc
31 1 119 A 21-SEP-15
Name: /u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_119_bzysjq6c_.arc
Do you really want to delete the above objects (enter YES or NO)? yes
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_116_bzypwksv_.arc RECID=28 STAMP=890990481
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_117_bzyq2cc6_.arc RECID=29 STAMP=890990667
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_118_bzysh8hg_.arc RECID=30 STAMP=890993128
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_119_bzysjq6c_.arc RECID=31 STAMP=890993175
Deleted 4 objects
从recid=28开始,没有被删除的日志一共有8个。从RMAN里面,本次只删除了备份过两次的归档日志。备份次数低于两次的日志,RMAN是拒绝进行删除的。这个是deletion policy的另一个特性:想删除,也不能轻易删除。
4、Obsolete
RMAN引入了很多概念,obsolete、expired是初学者们经常纠结的话题。简单的说,obsolete是依据备份保留策略而言的,如果不满足保留策略的备份集合,就认为是obsolete性质。备份集合是否obsolete,是不需要额外的操作的(如crosscheck),从控制文件中就可以定义得知。
而expired反映了备份集合、归档日志在文件系统与控制文件的不匹配。如果我们“背着”Oracle删除了文件系统中的对象,Oracle是不会自己知道的,是需要手工进行的crosscheck才能知道。所谓的删除expired,删除的也是控制文件中的信息记录。
在deletion policy控制下,我们又有了一个删除定义维度。原则上,是不会影响obsolete删除的。
RMAN> show all;
RMAN configuration parameters for database with db_unique_name CHINAREDB are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
RMAN> delete obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=592 device type=DISK
Deleting the following obsolete backups and copies:
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set 15 21-SEP-15
Backup Piece 15 21-SEP-15 /u01/app/oracle/fast_recovery_area/CHINAREDB/backupset/2015_09_21/o1_mf_annnn_TAG20150921T092121_bzypwkxf_.bkp
Backup Set 16 21-SEP-15
Backup Piece 16 21-SEP-15 /u01/app/oracle/fast_recovery_area/CHINAREDB/autobackup/2015_09_21/o1_mf_s_890990482_bzypwm2p_.bkp
Backup Set 17 21-SEP-15
Backup Piece 17 21-SEP-15 /u01/app/oracle/fast_recovery_area/CHINAREDB/backupset/2015_09_21/o1_mf_annnn_TAG20150921T100528_bzysh8xg_.bkp
Backup Set 18 21-SEP-15
Backup Piece 18 21-SEP-15 /u01/app/oracle/fast_recovery_area/CHINAREDB/backupset/2015_09_21/o1_mf_nnndf_TAG20150921T100529_bzyshbbp_.bkp
Backup Set 19 21-SEP-15
Backup Piece 19 21-SEP-15 /u01/app/oracle/fast_recovery_area/CHINAREDB/backupset/2015_09_21/o1_mf_annnn_TAG20150921T100615_bzysjq9x_.bkp
Backup Set 20 21-SEP-15
Backup Piece 20 21-SEP-15 /u01/app/oracle/fast_recovery_area/CHINAREDB/autobackup/2015_09_21/o1_mf_s_890993176_bzysjrgn_.bkp
Archive Log 32 21-SEP-15 /u01/app/oracle/fast_recovery_area/CHINAREDB/archivelog/2015_09_21/o1_mf_1_120_bzytgl7c_.arc
Backup Set 21 21-SEP-15
Backup Piece 21 21-SEP-15 /u01/app/oracle/fast_recovery_area/CHINAREDB/backupset/2015_09_21/o1_mf_annnn_TAG20150921T102210_bzytglmn_.bkp
(篇幅原因,有删除……)
Deleted 8 objects
5、delete force archivelog
重新设置deletion policy参数。
RMAN> configure archivelog deletion policy to backed up 1 times to device type disk;
new RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;
new RMAN configuration parameters are successfully stored
切换日志,提供归档用于使用。
SQL> alter system switch logfile;
System altered
SQL> alter system switch logfile;
System altered
SQL> alter system switch logfile;
System altered
SQL> select recid, sequence#, archived, deleted, backup_count from v$archived_log;
RECID SEQUENCE# ARCHIVED DELETED BACKUP_COUNT
---------- ---------- -------- ------- ------------
1 25 YES NO 0
2 26 YES NO 0
3 27 YES NO 0
4 28 YES NO 0
5 29 YES NO 0
进行第一次备份。
RMAN> backup database plus archivelog;
Starting backup at 21-SEP-15
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=479 device type=DISK
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=25 RECID=1 STAMP=891026065
input archived log thread=1 sequence=26 RECID=2 STAMP=891026104
input archived log thread=1 sequence=27 RECID=3 STAMP=891026115
input archived log thread=1 sequence=28 RECID=4 STAMP=891026116
input archived log thread=1 sequence=29 RECID=5 STAMP=891026117
input archived log thread=1 sequence=30 RECID=6 STAMP=891026158
channel ORA_DISK_1: starting piece 1 at 21-SEP-15
channel ORA_DISK_1: finished piece 1 at 21-SEP-15
piece
(篇幅原因,有省略……)
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 21-SEP-15
备份后,日志情况。
SQL> select recid, sequence#, archived, deleted, backup_count from v$archived_log;
RECID SEQUENCE# ARCHIVED DELETED BACKUP_COUNT
---------- ---------- -------- ------- ------------
1 25 YES NO 1
2 26 YES NO 1
3 27 YES NO 1
4 28 YES NO 1
5 29 YES NO 1
6 30 YES NO 1
7 31 YES NO 1
7 rows selected
经过系列备份实验后,日志情况如下:
SQL> alter system switch logfile;
System altered
SQL> select recid, sequence#, archived, deleted, backup_count from v$archived_log;
RECID SEQUENCE# ARCHIVED DELETED BACKUP_COUNT
---------- ---------- -------- ------- ------------
1 25 YES YES 1
2 26 YES YES 1
3 27 YES YES 1
4 28 YES YES 1
5 29 YES YES 1
6 30 YES YES 1
7 31 YES YES 1
8 32 YES YES 1
9 33 YES YES 1
10 34 YES YES 1
11 35 YES YES 1
12 36 YES NO 1
13 37 YES NO 1
14 38 YES NO 0
14 rows selected
使用archive log delete all,可以将满足删除条件的日志删除。
RMAN> delete archivelog all;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=479 device type=DISK
RMAN-08138: WARNING: archived log not deleted - must create more backups
archived log file name=/u01/app/oracle/fast_recovery_area/SICSDB/archivelog/2015_09_21/o1_mf_1_38_c000yd44_.arc thread=1 sequence=38
List of Archived Log Copies for database with db_unique_name SICSDB
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
12 1 36 A 21-SEP-15
Name: /u01/app/oracle/fast_recovery_area/SICSDB/archivelog/2015_09_21/o1_mf_1_36_bzzw2jco_.arc
13 1 37 A 21-SEP-15
Name: /u01/app/oracle/fast_recovery_area/SICSDB/archivelog/2015_09_21/o1_mf_1_37_c000f3nv_.arc
Do you really want to delete the above objects (enter YES or NO)? yes
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/SICSDB/archivelog/2015_09_21/o1_mf_1_36_bzzw2jco_.arc RECID=12 STAMP=891028560
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/SICSDB/archivelog/2015_09_21/o1_mf_1_37_c000f3nv_.arc RECID=13 STAMP=891032995
Deleted 2 objects
只有两个日志满足条件,被自动删除。
SQL> select recid, sequence#, archived, deleted, backup_count from v$archived_log;
RECID SEQUENCE# ARCHIVED DELETED BACKUP_COUNT
---------- ---------- -------- ------- ------------
1 25 YES YES 1
2 26 YES YES 1
3 27 YES YES 1
4 28 YES YES 1
5 29 YES YES 1
6 30 YES YES 1
7 31 YES YES 1
8 32 YES YES 1
9 33 YES YES 1
10 34 YES YES 1
11 35 YES YES 1
12 36 YES YES 1
13 37 YES YES 1
14 38 YES NO 0
15 39 YES NO 0
15 rows selected
但是,使用force语句,可以忽略掉delete policy设置。
RMAN> delete force archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=479 device type=DISK
List of Archived Log Copies for database with db_unique_name SICSDB
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
14 1 38 A 21-SEP-15
Name: /u01/app/oracle/fast_recovery_area/SICSDB/archivelog/2015_09_21/o1_mf_1_38_c000yd44_.arc
15 1 39 A 21-SEP-15
Name: /u01/app/oracle/fast_recovery_area/SICSDB/archivelog/2015_09_21/o1_mf_1_39_c0012x9g_.arc
Do you really want to delete the above objects (enter YES or NO)? yes
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/SICSDB/archivelog/2015_09_21/o1_mf_1_38_c000yd44_.arc RECID=14 STAMP=891033548
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/SICSDB/archivelog/2015_09_21/o1_mf_1_39_c0012x9g_.arc RECID=15 STAMP=891033693
Deleted 2 objects
RMAN>
SQL> select recid, sequence#, archived, deleted, backup_count from v$archived_log;
RECID SEQUENCE# ARCHIVED DELETED BACKUP_COUNT
---------- ---------- -------- ------- ------------
1 25 YES YES 1
2 26 YES YES 1
3 27 YES YES 1
4 28 YES YES 1
5 29 YES YES 1
6 30 YES YES 1
7 31 YES YES 1
8 32 YES YES 1
9 33 YES YES 1
10 34 YES YES 1
11 35 YES YES 1
12 36 YES YES 1
13 37 YES YES 1
14 38 YES YES 0
15 39 YES YES 0
15 rows selected
6、结论
RMAN中对于archive log删除策略的参数,是十分方便使用的。