RMAN中的expired和obsolete的真相

玩过业务库的DBA应该面对一个问题,就是归档日志的删除和备份集的删除时间策略的问题?

RMAN>show all;

参数里面有个保留策略,默认下是重复多少次后就可以删除,小仙我一般设置成多少天后可以被删除,然实际上并非如此,实际上是可以被恢复到几天。目前设置的是3天,也就是可以保证可以恢复到3天以前。

expired 有中文意思过期,和 无效两个意思。

obsolete 表示 过时的,废弃的。

这两个词好像都是近义词啊!

真相是 obsolete 表示过期的 expired表示无效的。

先来看归档日志,来检查一下

RMAN> crosscheck archivelog all;

released channel: ORA_DISK_1

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=68 device type=DISK

validation succeeded for archived log

archived log file name=/u01/archive/1_24917_882200602.dbf RECID=66827 STAMP=950991475

validation succeeded for archived log

archived log file name=/u01/archive/1_24918_882200602.dbf RECID=66830 STAMP=950991527

validation succeeded for archived log

archived log file name=/u01/archive/1_24919_882200602.dbf RECID=66833 STAMP=950991529

validation succeeded for archived log

archived log file name=/u01/archive/1_24920_882200602.dbf RECID=66836 STAMP=951009052

validation succeeded for archived log

archived log file name=/u01/archive/1_24921_882200602.dbf RECID=66839 STAMP=951073772

validation succeeded for archived log

archived log file name=/u01/archive/1_24922_882200602.dbf RECID=66841 STAMP=951073774

validation succeeded for archived log

archived log file name=/u01/archive/1_24923_882200602.dbf RECID=66845 STAMP=951159044

validation succeeded for archived log

archived log file name=/u01/archive/1_24924_882200602.dbf RECID=66848 STAMP=951160178

validation succeeded for archived log

archived log file name=/u01/archive/1_24925_882200602.dbf RECID=66850 STAMP=951160179

validation succeeded for archived log

archived log file name=/u01/archive/1_24926_882200602.dbf RECID=66854 STAMP=951239328

validation succeeded for archived log

archived log file name=/u01/archive/1_24927_882200602.dbf RECID=66857 STAMP=951246587

validation succeeded for archived log

archived log file name=/u01/archive/1_24928_882200602.dbf RECID=66860 STAMP=951246588

validation succeeded for archived log

archived log file name=/u01/archive/1_24929_882200602.dbf RECID=66863 STAMP=951309750

validation succeeded for archived log

archived log file name=/u01/archive/1_24930_882200602.dbf RECID=66866 STAMP=951332969

validation succeeded for archived log

archived log file name=/u01/archive/1_24931_882200602.dbf RECID=66869 STAMP=951332970

validation succeeded for archived log

archived log file name=/u01/archive/1_24932_882200602.dbf RECID=66872 STAMP=951393093

validation succeeded for archived log

archived log file name=/u01/archive/1_24933_882200602.dbf RECID=66875 STAMP=951419421

validation succeeded for archived log

archived log file name=/u01/archive/1_24934_882200602.dbf RECID=66878 STAMP=951419422

validation succeeded for archived log

archived log file name=/u01/archive/1_24935_882200602.dbf RECID=66881 STAMP=951478734

validation succeeded for archived log

archived log file name=/u01/archive/1_24936_882200602.dbf RECID=66884 STAMP=951506898

validation succeeded for archived log

archived log file name=/u01/archive/1_24937_882200602.dbf RECID=66887 STAMP=951506900

validation succeeded for archived log

archived log file name=/u01/archive/1_24938_882200602.dbf RECID=66890 STAMP=951596363

validation succeeded for archived log

archived log file name=/u01/archive/1_24939_882200602.dbf RECID=66892 STAMP=951596364

Crosschecked 23 objects

检查了23个归档日志,并且都是OK的。我们在去磁盘上看看

[oracle@oraclemain archive]ll

total 7.7G

-rw-r----- 1 oracle oinstall 853M Aug 2 20:17 1_24917_882200602.dbf

-rw-r----- 1 oracle oinstall 755K Aug 2 20:18 1_24918_882200602.dbf

-rw-r----- 1 oracle oinstall 1.5K Aug 2 20:18 1_24919_882200602.dbf

-rw-r----- 1 oracle oinstall 141M Aug 3 01:10 1_24920_882200602.dbf

-rw-r----- 1 oracle oinstall 685M Aug 3 19:09 1_24921_882200602.dbf

-rw-r----- 1 oracle oinstall 30K Aug 3 19:09 1_24922_882200602.dbf

-rw-r----- 1 oracle oinstall 853M Aug 4 18:50 1_24923_882200602.dbf

-rw-r----- 1 oracle oinstall 9.8M Aug 4 19:09 1_24924_882200602.dbf

-rw-r----- 1 oracle oinstall 3.0K Aug 4 19:09 1_24925_882200602.dbf

-rw-r----- 1 oracle oinstall 853M Aug 5 17:08 1_24926_882200602.dbf

-rw-r----- 1 oracle oinstall 59M Aug 5 19:09 1_24927_882200602.dbf

-rw-r----- 1 oracle oinstall 1.5K Aug 5 19:09 1_24928_882200602.dbf

-rw-r----- 1 oracle oinstall 853M Aug 6 12:42 1_24929_882200602.dbf

-rw-r----- 1 oracle oinstall 244M Aug 6 19:09 1_24930_882200602.dbf

-rw-r----- 1 oracle oinstall 16K Aug 6 19:09 1_24931_882200602.dbf

-rw-r----- 1 oracle oinstall 853M Aug 7 11:51 1_24932_882200602.dbf

-rw-r----- 1 oracle oinstall 341M Aug 7 19:10 1_24933_882200602.dbf

-rw-r----- 1 oracle oinstall 2.0K Aug 7 19:10 1_24934_882200602.dbf

-rw-r----- 1 oracle oinstall 855M Aug 8 11:38 1_24935_882200602.dbf

-rw-r----- 1 oracle oinstall 443M Aug 8 19:28 1_24936_882200602.dbf

-rw-r----- 1 oracle oinstall 5.5K Aug 8 19:28 1_24937_882200602.dbf

-rw-r----- 1 oracle oinstall 818M Aug 9 20:19 1_24938_882200602.dbf

-rw-r----- 1 oracle oinstall 17K Aug 9 20:19 1_24939_882200602.dbf

从磁盘上看归档日志是对的上的。

我们手工删除第一个归档日志24917然后去检查下

[oracle@oraclemain archive]rm 1_24917_882200602.dbf

RMAN> crosscheck archivelog all;

released channel: ORA_DISK_1

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=68 device type=DISK

validation failed for archived log

archived log file name=/u01/archive/1_24917_882200602.dbf RECID=66827 STAMP=950991475

结果表示该归档日志无效了

列出无效的归档日志

RMAN> list expired archivelog all;

List of Archived Log Copies for database with db_unique_name ORCL_PD

=====================================================================

Key Thrd Seq S Low Time


66827 1 24917 X 01-AUG-17

    Name: /u01/archive/1_24917_882200602.dbf

删除无效的归档日志

RMAN> delete expired archivelog all;

released channel: ORA_DISK_1

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=68 device type=DISK

List of Archived Log Copies for database with db_unique_name ORCL_PD

=====================================================================

Key Thrd Seq S Low Time


66827 1 24917 X 01-AUG-17

    Name: /u01/archive/1_24917_882200602.dbf

Do you really want to delete the above objects (enter YES or NO)? YES

deleted archived log

archived log file name=/u01/archive/1_24917_882200602.dbf RECID=66827 STAMP=950991475

Deleted 1 EXPIRED objects

总结的说一下:备份信息保存在控制文件中或者是恢复目录中,所谓的备份信息就是上面的归档日志信息,备份集信息等。如果在OS操作系统上面手工删除了的话,那么控制文件它是不会自动感知的。需要交叉检查下,核对下!避免到时候恢复的时候使用错误的信息,导致无法恢复之类的。很显然上面的删除只是删除控制文件中的信息。

要是把控制文件的信息和磁盘的归档日志一起删除的呢?

我一般使用下面语句删除归档日志

DELETE archivelog until time 'sysdate-3';

这条语句就是两者一起删除掉。

再看OBSOLETE;

RMAN> report obsolete;

RMAN retention policy will be applied to the command

RMAN retention policy is set to recovery window of 3 days

Report of obsolete backups and copies

Type Key Completion Time Filename/Handle


Backup Set 10250 07-AUG-17

Backup Piece 10250 07-AUG-17 /u01/backup/orcl_spfile_0csbb0j4_1_1_20170807

上面信息说明 该备份集已经过期了,超过了保留策略3天。可以被删除

delete obsolete;

就能把它删得比较干净

下面从OS看,为什么8月2日的备份集没有过期呢?

[oracle@oraclemain backup]ll

total 67G

-rw-r----- 1 oracle oinstall 12G Aug 2 19:31 orcl_datafile_level_0_uusatq1k_1_1_20170802

-rw-r----- 1 oracle oinstall 12G Aug 2 19:57 orcl_datafile_level_0_uvsatrsi_1_1_20170802

-rw-r----- 1 oracle oinstall 8.3G Aug 2 20:18 orcl_datafile_level_0_v0sattd5_1_1_20170802

-rw-r----- 1 oracle oinstall 279M Aug 2 20:19 orcl_archivelog_v2satul9_1_1_20170802

-rw-r----- 1 oracle oinstall 108M Aug 3 19:03 orcl_datafile_level_1_v6sb0edk_1_1_20170803

-rw-r----- 1 oracle oinstall 131M Aug 3 19:06 orcl_datafile_level_1_v7sb0ekc_1_1_20170803

-rw-r----- 1 oracle oinstall 127M Aug 3 19:09 orcl_datafile_level_1_v8sb0eq5_1_1_20170803

-rw-r----- 1 oracle oinstall 267M Aug 3 19:10 orcl_archivelog_vasb0evf_1_1_20170803

-rw-r----- 1 oracle oinstall 125M Aug 4 19:03 orcl_datafile_level_1_vesb32pk_1_1_20170804

-rw-r----- 1 oracle oinstall 132M Aug 4 19:06 orcl_datafile_level_1_vfsb330m_1_1_20170804

-rw-r----- 1 oracle oinstall 123M Aug 4 19:09 orcl_datafile_level_1_vgsb335s_1_1_20170804

-rw-r----- 1 oracle oinstall 287M Aug 4 19:10 orcl_archivelog_visb33bk_1_1_20170804

-rw-r----- 1 oracle oinstall 100M Aug 5 19:03 orcl_datafile_level_1_vmsb5n5j_1_1_20170805

-rw-r----- 1 oracle oinstall 114M Aug 5 19:06 orcl_datafile_level_1_vnsb5ncv_1_1_20170805

-rw-r----- 1 oracle oinstall 100M Aug 5 19:09 orcl_datafile_level_1_vosb5ni5_1_1_20170805

-rw-r----- 1 oracle oinstall 300M Aug 5 19:10 orcl_archivelog_vqsb5nnt_1_1_20170805

-rw-r----- 1 oracle oinstall 103M Aug 6 19:03 orcl_datafile_level_1_vusb8bhj_1_1_20170806

-rw-r----- 1 oracle oinstall 83M Aug 6 19:06 orcl_datafile_level_1_vvsb8bol_1_1_20170806

-rw-r----- 1 oracle oinstall 106M Aug 6 19:09 orcl_datafile_level_1_00sb8btg_1_1_20170806

-rw-r----- 1 oracle oinstall 355M Aug 6 19:10 orcl_archivelog_02sb8c3b_1_1_20170806

-rw-r----- 1 oracle oinstall 127M Aug 7 19:03 orcl_datafile_level_1_06sbavtl_1_1_20170807

-rw-r----- 1 oracle oinstall 196M Aug 7 19:06 orcl_datafile_level_1_07sbb051_1_1_20170807

-rw-r----- 1 oracle oinstall 132M Aug 7 19:10 orcl_datafile_level_1_08sbb0ag_1_1_20170807

-rw-r----- 1 oracle oinstall 390M Aug 7 19:11 orcl_archivelog_0asbb0gv_1_1_20170807

-rw-r----- 1 oracle oinstall 1.9M Aug 7 19:11 orcl_controlfile_0bsbb0j1_1_1_20170807

-rw-r----- 1 oracle oinstall 121M Aug 8 19:11 orcl_datafile_level_1_0esbdk9m_1_1_20170808

-rw-r----- 1 oracle oinstall 142M Aug 8 19:18 orcl_datafile_level_1_0fsbdkug_1_1_20170808

-rw-r----- 1 oracle oinstall 217M Aug 8 19:27 orcl_datafile_level_1_0gsbdlbq_1_1_20170808

-rw-r----- 1 oracle oinstall 408M Aug 8 19:29 orcl_archivelog_0isbdluk_1_1_20170808

-rw-r----- 1 oracle oinstall 1.9M Aug 8 19:29 orcl_controlfile_0jsbdm0n_1_1_20170808

-rw-r----- 1 oracle oinstall 96K Aug 8 19:29 orcl_spfile_0ksbdm0q_1_1_20170808

-rw-r----- 1 oracle oinstall 14G Aug 9 19:32 orcl_datafile_level_0_0msbg8lj_1_1_20170809

-rw-r----- 1 oracle oinstall 8.4G Aug 9 19:54 orcl_datafile_level_0_0nsbgaie_1_1_20170809

-rw-r----- 1 oracle oinstall 9.7G Aug 9 20:19 orcl_datafile_level_0_0osbgbs5_1_1_20170809

-rw-r----- 1 oracle oinstall 268M Aug 9 20:20 orcl_archivelog_0qsbgdac_1_1_20170809

-rw-r----- 1 oracle oinstall 1.9M Aug 9 20:20 orcl_controlfile_0rsbgdbr_1_1_20170809

-rw-r----- 1 oracle oinstall 96K Aug 9 20:20 orcl_spfile_0ssbgdbu_1_1_20170809

这个嘛 就是增量备份了 8月2日是增量备份0级别,不能把它给删了,昨天9号才开始新的增量0级备份。

上一篇:程序员考公指南:逃离996的最强出路,拒绝秃顶的最佳方法


下一篇:如何给localStorage设置一个过期时间?