7-25. Backing Up Only Those Files Previously Not Backed Up
Problem
You want to create a backup of only new files that have been recently added or those files that
failed to get backed up during the normal backup schedule.
Solution
You can limit RMAN to backing up only specific files using the not backed up or since time
clause within a backup command. Using the not backed up clause, you can instruct RMAN to
back up only those datafiles or archived log files that were never backed up previously. Here’s
the backup command that shows how to back up only previously backed-up files:
RMAN> backup database not backed up;
Starting backup at 15-NOV-06
using channel ORA_DISK_1
skipping datafile 1; already backed up on 14-NOV-06
skipping datafile 2; already backed up on 14-NOV-06
skipping datafile 3; already backed up on 14-NOV-06
skipping datafile 4; already backed up on 14-NOV-06
skipping datafile 5; already backed up on 14-NOV-06
Finished backup at 15-NOV-06
RMAN>
You can also use the not backed up command with additional specifications such as the
number of backups. The following example shows how to back up only those archived redo
logs that were backed up less than twice on tape:
RMAN> backup device type sbt archivelog all not backed up 2 times;
RMAN considers only backups created on identical device type as the current backup when
counting the number of backups it has already made. Thus, the not backed up clause is ideal for
specifying the number of archived redo logs to be stored on a specific type of media. The previous
example specifies RMAN to keep at least two copies of archived redo logs on tape.
How It Works
The backup ... not backed up command comes in handy when you add one or more new
files and want to ensure that the new file’s contents are backed up soon rather than waiting for
the regular scheduled time for backup.
If you’re making backup sets (instead of image copies), RMAN considers the completion
time for any file in the backup set as the completion time for the entire backupset. That is, all
files in a backup set must have the same finishing time. Let’s say you’re making a backup that
involves multiple backup sets. If the target database crashes midway through a database
backup, you don’t have to start the backup from the beginning. You can use the not backed up
since time command to back up only those datafiles that haven’t been backed up since the
specified time, as shown in the following example:
RMAN> backup database not backed up since time 'sysdate-31';
If you use the not backed up since time clause when you restart the RMAN backup,
RMAN will skip backing up the files it already backed up prior to the instance failure. Recipe 7-26 explains this in more detail. If you’re using the since time clause, you can specify either a
date in the nls_date_format or a SQL data expression such as sysdate-7. Note that RMAN considers
only backups made on the same device type as the current backup when figuring out
whether a new backup ought to be made.
7-26. Restarting Backups After a Crash
Problem
The RMAN backup process fails midway through a database backup, say, because of a database
instance crash or because of the unavailability of some datafiles. You want to resume the
backup but save time by backing up only those parts of the database that failed to be backed
up the first time.
Solution
Use the restartable backup feature to back up only those files that failed to be backed up the
first time around. Use the not backed up since time clause of the backup command to restart a backup after it partially completes. If the time you specify for the since time clause is a more
recent time than the backup completion time, RMAN backs up the database file.
Here’s an example that shows how to restart an RMAN backup that failed midway through
a nightly backup. You discover the backup failure in the morning and decide to back up only
those parts of the database that weren’t backed up by RMAN before the backup failed. Simply
run the following backup command to achieve your goal.
■Note If you use the backup database not backed up command without the since time clause,
RMAN backs up only those files that were never backed up before by RMAN.
RMAN> backup not backed up since time 'sysdate-1'
database plus archivelog;
The previous backup command will back up all the database files and archivelogs that
weren’t backed up during the past 24 hours. Any database file or archivelogs that were backed
up during the last 24 hours won’t be backed up again. You thus avoid backing up files you
already backed up. When RMAN encounters database files that it had already backed up
before the backup failed, it issues messages such as these:
RMAN-06501: skipping datafile 1; already backed up on APR11 2007 20:12:00
RMAN-06501: skipping datafile 2; already backed up on APR 11 2007 20:13:35
RMAN-06501: skipping datafile 3; already backed up on APR 11 2007 20:14:50
The backup command that produced this output used a SQL expression of type date
(sysdate-1). You may also specify a date string as a literal string that matches the nls_date_
format environment variable setting.
How It Works
The restartable backup feature backs up only those files that weren’t backed up since a specified
date and uses the last completed backup set or image copy as the restart point for the new
backup. By using the restartable backup feature after a backup failure, you back up the parts
of the database that the failed backup didn’t back up. If your backup consists of multiple
backup sets and the backup fails midway, you don’t have to back up the backup sets that were
already backed up. However, if your backup consists only of a single backup set, a backup failure
means that the entire backup must be rerun.
All the database files are affected when you place the not backed up since clause right
after the backup command, as shown in our example. By placing the not backed up since
clause after a specific backupset, you can limit the backup to only the objects that are part of
the backup set.
It’s important to understand that when considering the number of backups, RMAN takes
into account only those backups made on an identical device as the device in the current
backup command.