Instructor's Notes
(If applicable)
- Lesson 11 – RMAN Maintenance (Handling expired and obsolete backups.)
- Author: Dave Anderson, SkillBuilders
- www.skillbuilders.com
- Last Update: October 17, 2007
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- In this lesson you will learn how to:
- Check for expired backups with the CROSSCHECK command
- Deleting expired backups
- Removing unwanted or obsolete backups
- Concepts and retention policy review
- REPORT OBSOLETE command
- Deleting obsolete backups with the DELETE OBSOLETE Command
- Overriding configured retention policy
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- It is obviously possible that the RMAN catalog (control file or actual catalog) has a record of a backup set, but the backup set (or one or more of the pieces) is actually missing from the backup device. Several scenarios can cause this:
- A tape or disk file was accidentally deleted.
- The tape retention policy for a backup set expired (yet the RMAN retention policy has not; we will discuss RMAN retention policy and “obsolete” backups later in this lesson).
- The tape or disk containing the backup piece or set was lost or has become corrupt (i.e. unreadable).
- Missing backup pieces or sets are called “expired” backups. (Don’t confuse “expired” backups with “obsolete” backups, which has to do with retention policy. We will cover obsolete backups later in this lesson.)
- We will use the RMAN CROSSCHECK command to locate expired backups. The command output will identify the expired (missing) files and the command will update the catalog (views) to permanently record the fact the files are missing (if the files are found and the command is re-run, the catalog will be updated to reflect the available status).
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- For this example I used Legato Administrator to manually remove the file from the tape catalog.
- The CROSSCHECK command verify the existence of files. Specifically, it will:
- search disk devices looking for files that make up a backup set
- send requests to the tape server software to check for the existence of a file in the tape catalog (A.K.A. tape index).
- search for archived logs or image copies (also refer to the Oracle9i Recovery Manager Reference for details on the CROSSCHECK ARCHIVELOG or CROSSCHECK COPY commands).
- The CROSSCHECK command output relays the status back to the terminal. It also records the status in the STATUS column of these views:
- RC_BACKUP_SET. “A” indicates all pieces are available. “O” indicates one or more pieces are expired, thus the backup set can not be used in a recovery operation. “D” means that all backup pieces have been deleted.
- Notes continue on the following page…
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> crosscheck backup;
<br>
<br>using channel ORA_SBT_TAPE_1
<br>using channel ORA_DISK_1
<br>crosschecked backup piece: found to be 'EXPIRED'
<br>backup piece handle=7nf7oa5t_1_1 recid=242 stamp=511453373
<br>crosschecked backup piece: found to be 'AVAILABLE'
<br>backup piece handle=7pfb1hh7_1_1 recid=243 stamp=514901544
<br>
<br>crosschecked backup piece: found to be 'AVAILABLE'
<br>backup piece handle=/mnt/disk2/6uf7lgq5_1_1 recid=220 stamp=511361861<br>File no longer in tape catalog. Could still exist on tape.<br>This file is in the tape index. However, Legato does not mount tape to validate physical file!<br>This disk file was found.<br>
Instructor's Notes
(If applicable)
- CROSSCHECK notes continued from the previous page:
- RC_BACKUP_PIECE (catalog database) and V$BACKUP_PIECE (target database). “A” means available. “X” means expired. “D” means deleted. “U” means unavailable. A DBA can set a backup set (i.e. all pieces) to a status of unavailable with the CHANGE . . . UNAVAILABLE. This might be done, for example, if a backup piece has become temporarily unavailable due to loss of disk drive. Later in this lesson I will show you how to query the RC_ views.
- Supplemental Notes concerning CROSSCHECK:
- RMAN sends requests to the tape server software (Legato Single Server Version in my environment) to check the availability of files recorded in the RMAN catalog. Legato simply checks its catalog; it does not mount the tape and actually try to read the file. Nor does RMAN attempt to read disk files; it simply checks to see that they exist. (To actually validate/read file(s), use the VALIDATE command, e.g. RMAN> validate backupset 2177;)
- The Oracle9i Recovery Manager Reference states that, if you have tape backups and do not have a default tape channel configured, you must manually allocate a tape channel. I did not find this to be the case. RMAN seems smart enough to allocate a tape channel in response to my CROSSCHECK BACKUP command, even without a tape channel configured with the CONFIGURE command.
- The CROSSCHECK BACKUP command checks the existence of backup sets, pieces and control file autobackups. Use the CROSSCHECK COPY command to check for image copies, control file copies and archive logs.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- The CROSSCHECK command has many parameters and formats. Refer to the Oracle9i Recovery Manager Reference manual for detailed descriptions of all parameters.
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> crosscheck backup of database;
<br>
<br>RMAN> crosscheck backup of archivelog all;
<br>
<br>RMAN> crosscheck backup of controlfile;<br>RMAN> crosscheck backup completed after 'sysdate-7';
<br>RMAN> crosscheck backup device type sbt;
<br>RMAN> crosscheck backup of tablespace users;
<br>RMAN> crosscheck archivelog all;<br>Check existence of archivelogs<br>Check existence of pieces created in last 7 days<br>Crosscheck all obsolete datafile backups, arc log backups and control file backups<br>
Instructor's Notes
(If applicable)
- The RMAN LIST command, when used with the EXPIRED parameter, will scan the RMAN catalog (or control file if you are not connected to a catalog) looking for expired backups. Remember that the CROSSCHECK command must be run first to search for the backup pieces and update the catalog accordingly.
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> list expired backup;
<br>
<br>
<br>List of Backup Sets
<br>===================
<br>
<br>BS Key Type LV Size Device Type Elapsed Time Completion Time
<br>------- ---- -- -------- ----------- ------------ ---------------
<br>2177 Full 536M SBT_TAPE 00:02:38 08-JAN-04
<br> BP Key: 2178 Status: EXPIRED Tag: TAPE1
<br> Piece Name: 7pfb1hh7_1_1
<br> SPFILE Included: Modification time: 28-NOV-03
<br> List of Datafiles in backup set 2177
<br> File LV Type Ckp SCN Ckp Time Name
<br> ---- -- ---- -------- --------- ----
<br> 1 Full 2540689 08-JAN-04 /opt/oracle/oradata/test/system01.dbf
<br> 2 Full 2540689 08-JAN-04 /opt/oracle/oradata/test/undotbs01.db
<br> . . .
<br>Display info on expired backups
<br>
<br>Execute after CROSSCHECK<br>
Instructor's Notes
(If applicable)
- An alternate method of listing backups (and their status) is to query the RMAN catalog.
- The catalog views RC_BACKUP_PIECE and RC_BACKUP_SET record the status of the backup piece. The status will start as “A” for available (it can be used in a restore operation). The CROSSCHECK command will change the status to “X” for expired if the physical file (backup piece) is not found. If the CROSSCHECK changes the status to expired, the query shown above will show the backup piece to be expired:
- 7nf7oa5t_1_1 EXPIRED 11/30/2003 14:22 FULL/LEV 0
- Refer the supplied script “BACKUP_PIECE_STATUS.SQL” for a working example of this code.
Other Text:
(Examples or comments displayed on slide, if any).
rman@DAVE> select handle,
2 case status when 'A' then 'AVAILABLE'
<br> 3 when 'X' then 'EXPIRED'
<br> 4 end as status,
<br> 5 to_char(start_time, 'mm/dd/yyyy hh24:mi') as time,
<br> 6 case backup_type when 'D' then 'FULL/LEV 0'
<br> 7 when 'I' then 'INCREMENTAL'
<br> 8 when 'L' then 'ARC LOG'
<br> 9 end as type
<br> 10 from rc_backup_piece
<br> 11 where db_id = 1808373586
<br> 12 order by start_time
<br> 13 /
<br>
<br>HANDLE STATUS TIME TYPE
<br>------------------------- --------- ---------------- -----------
<br>/mnt/disk2/6uf7lgq5_1_1 AVAILABLE 11/29/2003 12:57 FULL/LEV 0
<br>/mnt/disk2/6vf7lh23_1_1 AVAILABLE 11/29/2003 13:01 FULL/LEV 0
<br>. . .
<br>7nf7oa5t_1_1 AVAILABLE 11/30/2003 14:22 FULL/LEV 0
<br>7pfb1hh7_1_1 AVAILABLE 01/08/2004 12:12 FULL/LEV 0
<br>7qfbca3e_1_1 AVAILABLE 01/12/2004 14:13 FULL/LEV 0<br>
Instructor's Notes
(If applicable)
- If you find expired (i.e. missing) backup pieces, and you cannot restore the pieces (or do not want to), you will want to update the RMAN catalog to reflect this. This is accomplished with the DELETE EXPIRED command as shown above. You can also be more specific, i.e. list the exact backupset you wish to delete. For example, the previous example shows that backupset 2177 is expired. I can delete this backupset with this command:
- RMAN> delete backupset 2177;
- using channel ORA_SBT_TAPE_1
- using channel ORA_DISK_1
- . . .
- Note that if you delete a backup but the file is still available, you can re-catalog it in the RMAN catalog with the DBMS_BACKUP_RESTORE procedure. (If it is a tape file, this assumes you can ask the tape server to re-read the tape and re-catalog the file in the tape catalog first.) However, I have not yet found documentation on this procedure – you will have to ask metalink for help on this.
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> delete expired backup;
<br>
<br>using channel ORA_SBT_TAPE_1
<br>using channel ORA_DISK_1
<br>
<br>List of Backup Pieces
<br>BP Key BS Key Pc# Cp# Status Device Type Piece Name
<br>------- ------- --- --- ----------- ----------- ----------
<br>2147 2146 1 1 EXPIRED SBT_TAPE 7nf7oa5t_1_1
<br>
<br>Do you really want to delete the above objects (enter YES or NO)? yes
<br>deleted backup piece
<br>backup piece handle=7nf7oa5t_1_1 recid=242 stamp=511453373
<br>Deleted 1 EXPIRED objects<br>Confirm delete; suppress with the NOPROMPT option<br>Releases before 8.1.6 left catalog entries; use prgrmanc.sql to clean-up catalog.<br>
Instructor's Notes
(If applicable)
- This example demonstrates a more complete cross check procedure – crosscheck all backups of datafiles, archived redo logs and control files. Any missing (expired) files are removed from the RMAN and tape media manager catalogs with the DELETE commands.
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> crosscheck backup of database;
<br>RMAN> delete noprompt expired backup of database;
<br>RMAN> crosscheck backup of archivelog all;
<br>RMAN> delete noprompt expired backup of archivelog all;
<br>RMAN> crosscheck backup of controlfile;
<br>RMAN> delete noprompt expired backup of controlfile; <br>Crosscheck and remove all obsolete datafile backups, arc log backups and control file backups<br>
Instructor's Notes
(If applicable)
- Oracle uses the term “obsolete” backupsets to describe backups that have exceeded the user-specified retention policy.
- Retention Policy Review
- We can configure RMAN so that backups are retained for 30 days:RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;The REPORT OBSOLETE and DELETE OBSOLETE commands will now only report and delete, respectively, backup sets that are older than 30 days.
- Alternatively, you can configure RMAN to retain multiple copies of a backup:RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 3;
- Note that redundancy is mutually exclusive from RECOVERY Window. Recovery Window is usually a better method but redundancy “1” is the default to maintain compatibility with the 8i REPORT OBSOLETE command.
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> configure retention policy to recovery window of 14 days;
<br>
<br>new RMAN configuration parameters:
<br>CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;
<br>. . .
<br>
<br>RMAN> report obsolete ;
<br>
<br>RMAN retention policy will be applied to the command
<br>RMAN retention policy is set to recovery window of 14 days
<br>Report of obsolete backups and copies
<br>Type Key Completion Time Filename/Handle
<br>-------------------- ------ ----------------- --------------------
<br>Backup Set 1963 29-NOV-03
<br> Backup Piece 1964 29-NOV-03 /mnt/disk2/6uf7lgq5_1_1
<br>Backup Set 1987 29-NOV-03
<br> Backup Piece 1988 29-NOV-03 /mnt/disk2/75f7lqtm_1_1<br>
Instructor's Notes
(If applicable)
- When backup sets become obsolete it is common to delete those sets. This is done with the DELETE OBSOLETE command as shown above.
- NOTE: As of Oracle 10g, if backups are stored in the flash recovery area, Oracle will automatically delete obsolete backups when space is needed. Refer to Lesson 13, Backup and Recovery Enhancements, for more information.
- Note that disk files are physically deleted. Tape files are not (at least that is the way Legato works) though they are removed from the tape index (a.k.a. catalog).
- It is notable that when deleting tape backupsets, the DELETE command removes the entry from both the RMAN and tape server (e.g. Legato) catalogs. If the file exists on the tape, it is left intact. Some tape server software, Legato for example, will let you scan the tape and re-catalog files, which can then be re-cataloged with the DBMS_BACKUP_RESTORE procedure. Refer to Oracle’s metalink for help on DBMS_BACKUP_RESTORE (I have been unable to locate docs on this procedure).
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> delete obsolete;
<br>
<br>RMAN retention policy will be applied to the command
<br>RMAN retention policy is set to recovery window of 14 days
<br>allocated channel: ORA_SBT_TAPE_1
<br>allocated channel: ORA_DISK_1
<br>Deleting the following obsolete backups and copies:
<br>Type Key Completion Time Filename/Handle
<br>-------------------- ------ ----------------- --------------------
<br>Backup Set 1963 29-NOV-03
<br> Backup Piece 1964 29-NOV-03 /mnt/disk2/6uf7lgq5_1_1
<br>Backup Set 1987 29-NOV-03
<br> Backup Piece 1988 29-NOV-03 /mnt/disk2/75f7lqtm_1_1
<br>
<br>Do you really want to delete the above objects (enter YES or NO)? yes
<br>Deleted 2 objects<br>
Instructor's Notes
(If applicable)
- Since we are discussing obsolete backups and retention policies, let’s take a moment to talk about overriding the configured retention policy.
- There is two ways to affect the retention policy of a backup set:
- KEEP option of the BACKUP command – The KEEP option allows for overriding the configured retention policy for the backup set(s) created by this backup. There are several options:
- KEEP FOREVER [LOGS | NOLOGS] – The backup set(s) never become obsolete. LOGS causes all archive logs necessary to recover this backup to be kept too. NOLOGS is only useful if you want to be able to restore to the point in time at which the backup is taken. The database must not be open to use NOLOGS.
- KEEP UNTIL TIME ‘date’ [LOGS |NOLOGS] – Keep the backup sets until the specified time (e.g. ‘sysdate+1’).
- See notes on the CHANGE command on the next page.
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> backup tablespace users keep forever logs;
<br>
<br>Starting backup at 15-JAN-04
<br>released channel: ORA_SBT_TAPE_1
<br>using channel ORA_DISK_1
<br>backup will never be obsolete
<br>archived logs required to recover from this backup will expire when this backup expires
<br>. . .
<br>piece handle=/opt/oracle/product/9.2.0/dbs/80fbkdhc_1_1 comment=NONE
<br>channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
<br>Finished backup at 15-JAN-04 <br>
Instructor's Notes
(If applicable)
- The CHANGE command supports the changing of a retention policy. The example above shows how to set a backupset back to the configured retention policy, e.g. 14 days. Several options are available. Here are a couple:
- Change the retention attribute of all backups to the configured policy:
- RMAN> change backup nokeep;
- Change all backups so that they never become obsolete:
- RMAN> change backup keep forever logs;
Other Text:
(Examples or comments displayed on slide, if any).
RMAN> change backupset 2306 nokeep;
<br>
<br>. . .
<br>using channel ORA_DISK_1
<br>keep attributes for the backup are deleted
<br>backup set key=2306 recid=248 stamp=515520046
<br>
<br>RMAN> <br>
Instructor's Notes
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
- RMAN Maintenance Workshop
- This workshop requires that at least one successful full backup of your database has been taken. Use the REPORT NEED BACKUP command and the LIST BACKUP command to determine if successful backup(s) have been completed and what backup sets are in place.
- If one or more full backups have not been completed, take a full backup before proceeding with this workshop.
- Expired Backups Workshop
- Determine if there are any expired backup pieces for your database. (At this point, there should not be any expired pieces. If there are, skip steps 2 and 3.)
- Use an OS to command to delete one of the backup set pieces.
- Again determine if there are any expired backup pieces for your database.
- Delete the expired backup(s).
- Obsolete Backups Workshop
- Check if there are any obsolete backups for your database. If there are any, skip step 2.
- Take the actions necessary so that an obsolete backup exists.
- Delete the obsolete backup.
Other Text:
(Examples or comments displayed on slide, if any).