≡ Menu

How to Delete Old Obsolete and Expired Oracle RMAN Backup

If you are sysadmin, sometimes you might find yourself dealing with Oracle backups.

Apart from taking oracle RMAN backup, you should also understand how to Delete the old backups from the RMAN catalog and from physical filesystem.

If you don’t properly delete obsolete and expired Oracle DB backup from the catalog, it will cause some unnecessary throw error message during backup and also it will take-up space at the filesystem level.

Also, it is not recommended to directly remove the RMAN backup files from the filesystem using Linux rm command.

This tutorial explains how to identify the backups that are obsolete and expired, and how to properly delete them from RMAN.

The main parameter that decides what to delete is the retention policy. To identify your retention policy, connect using RMAN and and execute “show all” and look for the following line.

RMAN Retention Policy

In the following example, retention policy is 4 days. So, any backup that is older than 4 days is considered obsolete and old.

$ rman target /
RMAN> SHOW ALL;

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 4 DAYS;

There is a big difference between Obsolte and Expired RMAN backup. We’ll explain both in this article.

I. Delete Obsolete Backup

1. What is an Obsolete Backup?

In our example above, any backup that we have in our system (both on RMAN catalog, and as physical RMAN backup files at the filesystem level) that is older than 4 days is considered obsolete. Please keep in mind that sometimes it might not be just 4 days. It depends on whether a full-backup is available within the last 4 days. If you don’t have a full backup in the last 4 days, then what RMAN considers as obsolete will be even longer than that. i.e Until the last full backup.

Obsolete backups are those that are not required to satisfy RMAN requirement of what is specified in the retention policy to recover the database from the backup.

The following three things will happen when you perform “DELETE OBSOLETE” from RMAN prompt:

  1. The physical backup files are removed from the filesystem level (or from tape backup)
  2. The backup entries are removed from the RMAN recovery catalog
  3. The entries are marked as DELETED in the Oracle control file

2. View Backups Before Delete Obsolete

In the following example, I see that there are lot of backup that I have on the system that are way older than what I need to satisfy my recovery requirement. i.e I have backups starting from 6th June until 26th Sep (several months).

RMAN> LIST BACKUP SUMMARY;

List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
624     B  F  A DISK        06-JUN-14       1       1       YES        TAG20140606T220138
625     B  F  A DISK        06-JUN-14       1       1       YES        TAG20140606T220138
626     B  F  A DISK        06-JUN-14       1       1       NO         TAG20140606T221610
627     B  F  A DISK        13-JUN-14       1       1       YES        TAG20140613T220147
..
..
666     B  F  A DISK        05-SEP-14       1       1       YES        TAG20140905T220151
667     B  F  A DISK        12-SEP-14       1       1       YES        TAG20140912T220151
668     B  F  A DISK        19-SEP-14       1       1       YES        TAG20140919T220152
669     B  F  A DISK        26-SEP-14       1       1       YES        TAG20140926T220206

3. Perform RMAN CrossCheck

Before we start executing the delete obsolete command, it is always recommended to do a crosscheck of the backup as shown below.

crosscheck backup command will check for the records in the RMAN repository to make sure they are accurate. If there is an record in the RMAN catalog that is not available on the physical filesystem, it will make that entry with appropriate status.

RMAN> CROSSCHECK BACKUP;

allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=37 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=22 device type=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/rman-backups/dev-db/full_okpa6ke3_788_1 RECID=642 STAMP=849564099
crosschecked backup piece: found to be 'AVAILABLE'
..
..
backup piece handle=/rman-backups/dev-db/full_qvpiu46h_863_1 RECID=686 STAMP=858722513
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/rman-backups/dev-db/full_r4pjgir0_868_1 RECID=687 STAMP=859327328
Crosschecked 46 objects

4. Delete Obsolete RMAN backup

Once the crosscheck is done, it is time to delete the old obsolete backup using the DELETE OBSOLETE command as shown below.

RMAN> DELETE OBSOLETE;

RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 4 days
using channel ORA_DISK_1
using channel ORA_DISK_2
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           625    06-JUN-14
  Backup Piece       643    06-JUN-14          /rman-backups/dev-db/full_ojpa6ke3_787_1
Backup Set           624    06-JUN-14
  Backup Piece       642    06-JUN-14          /rman-backups/dev-db/full_okpa6ke3_788_1
..
..
Backup Set           664    05-SEP-14
  Backup Piece       682    05-SEP-14          /rman-backups/dev-db/full_qjphp6ug_851_1
Backup Set           667    12-SEP-14
  Backup Piece       685    12-SEP-14          /rman-backups/dev-db/full_qqpiblig_858_1

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

Once you say “YES” to the above confirmation, then it will start deleting those obsolete backups.

backup piece handle=/rman-backups/dev-db/full_ojpa6ke3_787_1 RECID=643 STAMP=849564099
deleted backup piece
backup piece handle=/rman-backups/dev-db/full_okpa6ke3_788_1 RECID=642 STAMP=849564099
deleted backup piece
..
..
backup piece handle=/rman-backups/dev-db/full_qjphp6ug_851_1 RECID=682 STAMP=857512912
deleted backup piece
backup piece handle=/rman-backups/dev-db/full_qqpiblig_858_1 RECID=685 STAMP=858117712
Deleted 40 objects

WARNING: This will also physically delete the RMAN backup files from the filesystem. So, be careful and know exactly what you are doing before you execute this command.

5. Other Delete Obsolete Options

If you are writing a shell script that will automatically do this for you on an on-going basis, you don’t want to manually say “YES” to delete obsolete command as shown above.

Instead, you can ignore the prompt and automatically delete all obsolete backups as shown below.

RMAN> DELETE NOPROMPT OBSOLETE;

Also, if you want to delete obsolete backup based on your own recovery window criteria (instead of what is configured in RMAN when you do “show all”), you can specify it as shown below. The following will delete old backups based on recovery window of 10 days.

RMAN> DELETE OBSOLETE RECOVERY WINDOW OF 10 DAYS;

6. View Backups After Delete Obsolete

Finally, if you do the list backup summary, you’ll notice that this has only the backups that are required to satisfy the recovery criteria. All other backups are deleted.

RMAN> LIST BACKUP SUMMARY;

List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
661     B  F  A DISK        29-AUG-14       1       1       YES        TAG20140829T220152
663     B  F  A DISK        29-AUG-14       1       1       NO         TAG20140829T221624
665     B  F  A DISK        05-SEP-14       1       1       YES        TAG20140905T220151
666     B  F  A DISK        05-SEP-14       1       1       YES        TAG20140905T220151
668     B  F  A DISK        19-SEP-14       1       1       YES        TAG20140919T220152
669     B  F  A DISK        26-SEP-14       1       1       YES        TAG20140926T220206

II. Delete Expired Backup

1. What is an Expired Backup?

When you have an entry in the RMAN repository for a backup, but there are no corresponding physical rman backup files at the filesystem level, that is considered as expired entry.

But, you need to execute the crosscheck command, which will go through all the records in the RMAN catalog, and mark any expired records appropriately.

2. Perform RMAN CrossCheck

Sometimes when you try to execute the delete command, you might get the following “RMAN-06207” error message, when there is a mis-match of the status for the records in the RMAN repository.

RMAN-06207: WARNING: 20036 objects could not be deleted for DISK channel(s) due
RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status
RMAN-06210: List of Mismatched objects
RMAN-06211: ==========================
RMAN-06212:   Object Type   Filename/Handle
RMAN-06213: --------------- ---------------------------------------------------
RMAN-06214: Backup Piece    /rman-backup/sales-db/full_52ob26cd_149666_1
RMAN-06214: Backup Piece    /rman-backup/sales-db/full_50ob26cd_149664_1

As you see from the following output, crosscheck backup finds few records that are expired, and marking them as EXPIRED status in the catalog.

RMAN> CROSSCHECK BACKUP;

allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=453 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=435 devtype=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/rman-backup/sales-db/full_4cpqjjca_196748_1 recid=217396 stamp=866766218
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/rman-backup/sales-db/full_4epqjjca_196750_1 recid=217397 stamp=866766218
..
..
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/rman-backup/sales-db/ctl_c-863661937-20141013-19 recid=211590 stamp=860879752
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/rman-backup/sales-db/ctl_c-863661937-20141013-1a recid=211591 stamp=860879769
Crosschecked 1253 objects

3. View Backups Before Delete Expired

As you see from the output below, there are several records in the RMAN catalog that are marked as EXPIRED.

RMAN> LIST BACKUP SUMMARY;

List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
728642  B  A  X DISK        29-SEP-14       1       1       YES        DBARCHLOGS_20140929
728643  B  A  X DISK        29-SEP-14       1       1       YES        DBARCHLOGS_20140929
..
..
819598  B  A  A DISK        29-DEC-14       1       1       YES        DBARCHLOGS_20141229
819607  B  F  A DISK        29-DEC-14       1       1       NO         TAG20141229T161328

Note: The 4th column which has the title of “S” is Status column. The value “X” indicates EXPIRED status. The value “A” indicates AVAILABLE status.

4. Delete Expired RMAN Catalog Entries

The following will delete all the records that are in RMAN catalog which are marked as EXPIRED. In other words, this deletes the expired records that don’t have the corresponding physical RMAN backup file in the filesystem.

RMAN> DELETE EXPIRED BACKUP;

using channel ORA_DISK_1
using channel ORA_DISK_2
List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
728642  728712  1   1   EXPIRED     DISK        /rman-backup/sales-db/full_52ob26cd_149666_1
728643  728713  1   1   EXPIRED     DISK        /rman-backup/sales-db/full_50ob26cd_149664_1
..
..
Do you really want to delete the above objects (enter YES or NO)?

As shown above, before deleting it will ask for a confirmation. Say “YES” to the above, which will delete those files as shown below.

backup piece handle=/rman-backup/sales-db/full_52ob26cd_149666_1 RECID=591 STAMP=840751343
deleted backup piece
backup piece handle=/rman-backup/sales-db/full_50ob26cd_149664_1 RECID=592 STAMP=840752380
deleted backup piece
..
Deleted 107 EXPIRED objects

5. View Backups After Delete Expired

After deleting the expired entries, view the catalog to make sure it contains only the active available RMAN backup records.

RMAN> LIST BACKUP SUMMARY;

List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
809652  B  F  A DISK        20-DEC-14       1       1       YES        DBFULLFILE_20141220
809653  B  F  A DISK        20-DEC-14       1       1       YES        DBFULLFILE_20141220
809654  B  F  A DISK        20-DEC-14       1       1       YES        DBFULLFILE_20141220
809655  B  F  A DISK        20-DEC-14       1       1       YES        DBFULLFILE_20141220
809656  B  F  A DISK        20-DEC-14       1       1       YES        DBFULLFILE_20141220
..
..
819598  B  A  A DISK        29-DEC-14       1       1       YES        DBARCHLOGS_20141229
819607  B  F  A DISK        29-DEC-14       1       1       NO         TAG20141229T161328

As you see from the Status column (4th column), we see only values “A”, which indicates that all the records in the RMAN catalog are in AVAILABLE status now.

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Md. Mahfuzur Rhamah January 8, 2015, 2:10 am

    Helpful article. Thanks

  • Petricia February 26, 2015, 5:52 am

    Very simple and easy to understand. Thanks for your effort.

  • San March 21, 2015, 2:36 am

    Good article. Many thanks

  • Vishal June 8, 2015, 5:41 am

    Thankx for created Nice tutorial

  • Andrew Bloss July 17, 2015, 8:55 am

    Hi Ramesh,

    So clearly written with love of the subject and your readers.

    Thank you very much.

  • Anonymous December 7, 2015, 10:17 am

    Well written. Thank you!

  • Ross June 3, 2016, 10:14 am

    Thanks for posting this helpful and well written article.

  • Samer June 24, 2016, 6:58 pm

    Hi ,

    thanks for the article , however , i still need your help with the following

    lets say i have level 0 backup every week plus archive log ( to tape)– no archivelog delete here

    and daily level 1 ( to tape ) – still no archivelog delete

    my retention policy :
    CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 days;

    how can i manage the archivelog on local filesystem or ASM to satisfy the above retention policy

    how can i delete archivelogs if i need to keep 7 days only of archivelog locally and the rest on tape

    waiting your reply

    Regards,
    Sam

  • Hari July 10, 2016, 6:04 am

    Excellent explanation… about RMAN obsolete and expired backups……Please keep doing to help us….

  • Ekrem August 10, 2016, 2:51 am

    Very helpful. Many thanks…

  • Yatender December 30, 2016, 12:23 pm

    Thanks for sharing such a valuable information in good manner.

  • Menoria February 16, 2017, 12:23 am

    huge thanks for the article !
    but my question is how do I make the lost backup set pieces available to rman again related to expired backup?

  • Anonymous April 2, 2019, 11:35 am

    Thanks for basic concepts.