News
Perth, Australia
+ (61) 417713124
prosolutions@gavinsoorma.com

RMAN KEEP FOREVER, KEEP UNTIL TIME and FORCE commands

  • Posted by Gavin Soorma
  • On April 9, 2010
  • 2 Comments
  • force, keep forever, keep until time, obsolete, retain

The KEEP FOREVER option in 11g has been improved over what was available in Oracle 10g from the point of view that in 11g, only the archivelogs which are required to keep the online backup consistent are retained.

In Oracle 10g we could roll forward this backup taken with the KEEP FOREVER option allowing point in time recovery to a time after the backup was taken. In Oracle 11g, the KEEP option will only retain enough archive logs to keep the backup consistent – so we can only use this backup to recover to the point where the backup was taken.

Archivelogs generated after this backup is completed need not be retained and can be candidates for the DELETE OBSOLETE command. In Oracle 10g, ALL archivelog backups taken after the KEEP FOREVER backup was taken had to be retained.

The KEEP FOREVER requires the use of an RMAN Catalog. The KEEP UNTIL TIME does not require a catalog.

Let us use an example to illustrate how the KEEP and FORCE clauses can be used and the differences between the two.

In this case our retention period has been configured to just one day. We are taking the backups on 6th of April. So these backups will become obsolete on the 7th of April by default.

RMAN> show retention policy;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name GAVIN are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 1 DAYS;

CASE 1

We take a backup and configure the retention for 2 days using the KEEP UNTIL TIME keyword

Note that along with the database backup, archivelog backups are automatically taken to make this backup a consistent backup. We provide a tag ‘RETAIN’ for this backup.

RMAN> backup database format ‘/u02/oracle/backup/bkp.%U’ tag ‘retain’ keep until time ‘sysdate+2’;

Starting backup at 06-APR-10
current log archived

using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=11 device type=DISK
backup will be obsolete on date 08-APR-10
archived logs required to recover from this backup will be backed up
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u02/oradata/gavin/sysaux01.dbf
input datafile file number=00001 name=/u02/oradata/gavin/system01.dbf
input datafile file number=00005 name=/u02/oradata/gavin/ggs_data01.dbf
input datafile file number=00007 name=/u02/oradata/gavin/mydata01.dbf
input datafile file number=00003 name=/u02/oradata/gavin/undotbs01.dbf
input datafile file number=00004 name=/u02/oradata/gavin/users01.dbf
input datafile file number=00006 name=/u02/oradata/gavin/disc10_data01.dbf
channel ORA_DISK_1: starting piece 1 at 06-APR-10
channel ORA_DISK_1: finished piece 1 at 06-APR-10
piece handle=/u02/oracle/backup/bkp.0ilae8jn_1_1 tag=RETAIN comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:46

using channel ORA_DISK_1
backup will be obsolete on date 08-APR-10
archived logs required to recover from this backup will be backed up
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 06-APR-10
channel ORA_DISK_1: finished piece 1 at 06-APR-10
piece handle=/u02/oracle/backup/bkp.0jlae8l5_1_1 tag=RETAIN comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

current log archived
using channel ORA_DISK_1
backup will be obsolete on date 08-APR-10
archived logs required to recover from this backup will be 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=118 RECID=117 STAMP=715596454
channel ORA_DISK_1: starting piece 1 at 06-APR-10
channel ORA_DISK_1: finished piece 1 at 06-APR-10
piece handle=/u02/oracle/backup/bkp.0klae8l6_1_1 tag=RETAIN comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

using channel ORA_DISK_1
backup will be obsolete on date 08-APR-10
archived logs required to recover from this backup will be backed up
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 06-APR-10
channel ORA_DISK_1: finished piece 1 at 06-APR-10
piece handle=/u02/oracle/backup/bkp.0llae8l7_1_1 tag=RETAIN comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 06-APR-10

CASE 2

We take a backup on the same day using the FORCE keyword – we provide a tag ‘FORCE’ for this backup

RMAN> backup database format ‘/u02/oracle/backup/bkp.%U’ tag ‘force’ force;

Starting backup at 06-APR-10
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=00002 name=/u02/oradata/gavin/sysaux01.dbf
input datafile file number=00001 name=/u02/oradata/gavin/system01.dbf
input datafile file number=00005 name=/u02/oradata/gavin/ggs_data01.dbf
input datafile file number=00007 name=/u02/oradata/gavin/mydata01.dbf
input datafile file number=00003 name=/u02/oradata/gavin/undotbs01.dbf
input datafile file number=00004 name=/u02/oradata/gavin/users01.dbf
input datafile file number=00006 name=/u02/oradata/gavin/disc10_data01.dbf
channel ORA_DISK_1: starting piece 1 at 06-APR-10
channel ORA_DISK_1: finished piece 1 at 06-APR-10
piece handle=/u02/oracle/backup/bkp.0mlae8p1_1_1 tag=FORCE comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 06-APR-10
channel ORA_DISK_1: finished piece 1 at 06-APR-10
piece handle=/u02/oracle/backup/bkp.0nlae8q4_1_1 tag=FORCE comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 06-APR-10

RMAN> list backup of database summary;


List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
12      B  F  A DISK        06-APR-10       1       1       NO         RETAIN
16      B  F  A DISK        06-APR-10       1       1       NO         FORCE

7th April – After the one day default backup retention period has expired

We see here that even though the one day retention has expired, we are still able to restore the database from the backup taken with the KEEP UNTIL clause as this backup will only expire on the 8th.

RMAN> restore validate database from tag ‘retain’;

Starting restore at 07-APR-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=11 device type=DISK

skipping datafile 7; already restored to file /u02/oradata/gavin/mydata01.dbf
channel ORA_DISK_1: starting validation of datafile backup set
channel ORA_DISK_1: reading from backup piece /u02/oracle/backup/bkp.0ilae8jn_1_1
channel ORA_DISK_1: piece handle=/u02/oracle/backup/bkp.0ilae8jn_1_1 tag=RETAIN
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: validation complete, elapsed time: 00:00:15
Finished restore at 07-APR-10

8th April – After the two day KEEP UNTIL TIME period has expired

We now use the DELETE OBSOLETE command to delete obsoleted backups. We will see that the backup taken with the tag ‘RETAIN’ is deleted.

The same RESTORE VALIDATE command will now fail.

RMAN> restore validate database from tag ‘retain’;

Starting restore at 08-APR-10
using channel ORA_DISK_1

skipping datafile 7; already restored to file /u02/oradata/gavin/mydata01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/08/2010 11:43:45
RMAN-06026: some targets not found - aborting restore
RMAN-06023: no backup or copy of datafile 6 found to restore
RMAN-06023: no backup or copy of datafile 5 found to restore
RMAN-06023: no backup or copy of datafile 4 found to restore
RMAN-06023: no backup or copy of datafile 3 found to restore
RMAN-06023: no backup or copy of datafile 2 found to restore
RMAN-06023: no backup or copy of datafile 1 found to restore

However, if we try the same RESTORE VALIDATE command without the tag ‘RETAIN’, we see that it will now succeed and find that the database can still be restored from the backup taken with the tag ‘FORCE’ – even though the one day retention period has expired and the delete obsolete command has been run.

RMAN> restore validate database ;

Starting restore at 08-APR-10
using channel ORA_DISK_1

skipping datafile 7; already restored to file /u02/oradata/gavin/mydata01.dbf
channel ORA_DISK_1: starting validation of datafile backup set
channel ORA_DISK_1: reading from backup piece /u02/oracle/backup/bkp.0mlae8p1_1_1
channel ORA_DISK_1: piece handle=/u02/oracle/backup/bkp.0mlae8p1_1_1 tag=FORCE
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: validation complete, elapsed time: 00:00:15
Finished restore at 08-APR-10
 

2 Comments

Kavita
  • Jan 24 2011
Nice post. What is the point you are tryin to make via this post? It's expected behavior. Are you saying that FORCE keyword played that magic and you were able to restore the database? I dont think FORCE keyword has anything to do with this scenario. You will still be able to restore the database even without a FORCE keyword in your backup.
Dude
  • Apr 24 2019
You wrote the KEEP option will only retain enough archive logs to keep the backup consistent. According to the documentation, however, the KEEP option will exclude the backup from the retention policy and keep enough informaion to restore the database to a consistent state. The only way to make a backup consistent, meaning it requies no recovery, is a cold backup.

Leave Reply

Your email address will not be published. Required fields are marked *