Skip Headers
Oracle® Database Backup and Recovery Advanced User's Guide
10g Release 2 (10.2)

Part Number B14191-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

RMAN Backup Examples

This section contains these topics:

Skipping Tablespaces when Backing Up a Database: Example

The following example assumes that the database is running in ARCHIVELOG mode and that you have an automatic sbt channel configured as follows:

RMAN> CONFIGURE DEVICE TYPE sbt PARALLELISM 1;
RMAN> CONFIGURE DEFAULT DEVICE TYPE TO sbt;
RMAN> CONFIGURE CHANNEL DEVICE TYPE sbt PARMS='ENV=(NSR_DATA_VOLUME_POOL=BackupPool)';

To back up the database while skipping offline and read-only tablespaces, you can run the following command:

RMAN> BACKUP DATABASE
        SKIP READONLY
        SKIP OFFLINE;

You only need to back up a read-only tablespace once after it has been made read-only. You can use the SKIP READONLY option to skip read-only datafiles. If you use the SKIP OFFLINE option, then the BACKUP command does not attempt to access offline datafiles. Use this option if the offline datafiles are not available.

Another way to persistently skip tablespaces across RMAN sessions is to issue the CONFIGURE EXCLUDE command for each tablespace that you always want to skip. For example, you may always want to skip the example tablespace, which has been made read-only. You can then issue:

RMAN> CONFIGURE EXCLUDE FOR TABLESPACE example;

Then, whenever you run BACKUP DATABASE, RMAN skips this tablespace. You do not have to specify a SKIP clause on the BACKUP command. You can override this behavior and include the example tablespace as follows:

RMAN> BACKUP DATABASE NOEXCLUDE;

Restarting a Backup: Example

Assume that you back up the database and archived logs every night to tape by running this command:

RMAN> BACKUP
  MAXSETSIZE 10G
  DATABASE PLUS ARCHIVELOG;

The preceding command sets an upper limit to the size of each backup set so that RMAN produces multiple backup sets. Assume that the media management device fails halfway through the backup and is then restarted. The next day you discover that only half the backup sets completed. In this case, you can run this command in the evening:

RMAN> BACKUP 
  # Note that the NOT BACKED UP SINCE clause should be placed immediately after the BACKUP
  # keyword or after each individual backupSpec clause
  NOT BACKED UP SINCE TIME 'SYSDATE-1'
  MAXSETSIZE 10M 
  DATABASE PLUS ARCHIVELOG;

With this form of the command, RMAN backs up only files that were not backed up during in the previous 24 hours. When RMAN finds out that a backup from the specified time window is already avaialble, it displays output similar to the following:

RMAN-06501: skipping datafile 1; already backed up on NOV 02 2003 18:10:00
RMAN-06501: skipping datafile 2; already backed up on NOV 02 2003 18:09:45
RMAN-06501: skipping datafile 3; already backed up on NOV 02 2003 18:09:45

If the NOT BACKED UP SINCE clause is placed immediately after the backup command, it affects all objects to be backed up. It can also be placed after individual backupSpec clauses, to cause only backups for those objects described by the backupSpec to be subject to the limitation.

Spreading a Backup Across Multiple Disk Drives: Example

Typically, you do not need to specify a format when backing up to tape because the default %U variable generates a unique filename for tape backups. When backing up to disk, however, you can specify a format if you need to spread the backup across several drives for improved performance. In this case, allocate one DISK channel for each disk drive and specify the format string on the ALLOCATE CHANNEL command so that the filenames are on different disks. For example, issue:

RUN
{ 
  ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT '/disk1/%d_backups/%U';
  ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT '/disk2/%d_backups/%U';
  ALLOCATE CHANNEL disk3 DEVICE TYPE DISK FORMAT '/disk3/%d_backups/%U';
  BACKUP AS COPY DATABASE; 
} 

You can distribute backups in this manner by default in the future, by configuring channels as follows:

CONFIGURE DEVICE TYPE DISK PARALLELISM 3;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT '/disk1/%d_backups/%U';
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT '/disk2/%d_backups/%U';
CONFIGURE CHANNEL 3 DEVICE TYPE DISK FORMAT '/disk3/%d_backups/%U';
BACKUP AS COPY DATABASE;

If you specify a nonexistent directory, RMAN displays output such as the following:

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 08/29/2001 
            14:36:04
ORA-19504: failed to create file "/nosuchdisk/0cd2momi_1_1"
ORA-27040: skgfrcre: create error, unable to create file
SVR4 Error: 2: No such file or directory

Specifying the Size of Backup Sets: Example

When making backups, RMAN divides the total number of files requiring backups by the number of allocated channels to calculate the number of files to place in each backup set. Use the MAXSETSIZE parameter to override this calculation and specify how many files should go in each backup set.

The MAXSETSIZE parameter specifies a maximum size for a backup set in units of bytes (default), kilobytes, megabytes, or gigabytes. Thus, to limit a backup set to 305 MB, specify MAXSETSIZE=305M. RMAN attempts to limit all sets to this size.

You can use MAXSETSIZE to limit the size of backup sets so that the database is divided among more than one backup set. If you configure MAXSETSIZE so that you generate multiple backup sets, however, then if the backup fails partway through, you can use the restartable backup feature to back up only those files that were not backed up during the previous attempt. See "Restartable Backups" for a conceptual overview of restartable backups.

The following example configures a tape device, then backs up archived redo logs to tape, limiting the size to 100 MB so that if the backup fails partway through, it can be restarted:

RMAN> CONFIGURE DEVICE TYPE sbt PARALLELISM 1;
RMAN> CONFIGURE DEFAULT DEVICE TYPE TO sbt;
RMAN> BACKUP MAXSETSIZE = 100M ARCHIVELOG ALL;

This example accomplishes the same result with CONFIGURE MAXSETSIZE:

RMAN> CONFIGURE DEFAULT DEVICE TYPE TO sbt;
RMAN> CONFIGURE MAXSETSIZE = 100M;
RMAN> BACKUP ARCHIVELOG ALL;

Note that if you specify a MAXSETSIZE value that is too small to contain the biggest file that you are backing up (either the actual size of that file, or if binary compression is specified, then the size of tha tfile after compression), then RMAN displays an error stack such as the following:

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 11/03/03 14:40:33
RMAN-06182: archive log larger than MAXSETSIZE: thread 1 seq 1
            /oracle/oradata/trgt/arch/archive1_1.dbf

Limiting the Size of Backup Pieces: Example

Backup piece size is an issue in those situations where it exceeds the maximum file size of the file system or media management software. Use the MAXPIECESIZE parameter of the CONFIGURE CHANNEL or ALLOCATE CHANNEL command to limit the size of backup pieces.

For example, to always limit the backup piece size to 2GB or less, you can configure the automatic DISK channel as follows and then run BACKUP DATABASE:

# max file size for backup pieces is 2GB
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK MAXPIECESIZE 2GB;
RMAN> BACKUP DATABASE;

Note that in version 2.0 of the media management API, media management vendors can specify the maximum size of a backup piece that can be written to their media manager. RMAN will respect this limit regardless of the settings you configure for MAXPIECESIZE.

Backing Up Archived Redo Logs in a Failover Scenario: Example

Assume that you set your initialization parameters so that you archive to the following local destinations:

LOG_ARCHIVE_DEST_1 = 'LOCATION=/disk1/arch/'
LOG_ARCHIVE_DEST_2 = 'LOCATION=/disk2/arch/'
LOG_ARCHIVE_DEST_3 = 'LOCATION=/disk3/arch/'

Each directory contains the same set of logs, starting with log sequence 1 and ending at log sequence 400. Unknown to you, a user inadvertently deletes logs 300 through 400 from /disk1/arch and logs 350 through 400 from /disk2/arch. You run this backup command:

RMAN> BACKUP ARCHIVELOG 
  FROM SEQUENCE 288 UNTIL SEQUENCE 388
  THREAD 1 
  DELETE INPUT;

RMAN begins backing up logs starting with log sequence 288. If the copy of log 300 that was deleted from /disk1/arch is the one that RMAN attempts to back up, then RMAN checks the repository to determine whether other copies of this log sequence exist, and backs up the log in either /disk2/arch or /disk3/arch. Hence, because there is at least one intact copy of each log from sequence 288 through sequence 388, RMAN can back up all the specified logs.

Backing Up Archived Logs Needed to Recover an Online Backup: Example

Assume that you back up database trgt while it is open. You want to back up only those archived redo logs required to recover this online backup.

The recommended solution to this problem is to add the PLUS ARCHIVELOG clause to your database backup command, as shown here:

RMAN> BACKUP DATABASE PLUS ARCHIVELOG;

See Oracle Database Backup and Recovery Basics and Oracle Database Backup and Recovery Reference for details on using BACKUP... PLUS ARCHIVELOG.

You can also manually determine which archived logs are required and back them up, using the following procedure.

  1. Start SQL*Plus and archive all unarchived logs, including the current log:

    SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
    
    
  2. Query V$LOG to determine the log sequence number of the current redo log, as in the following example (which includes output):

    SQL> SELECT SEQUENCE# FROM V$LOG WHERE STATUS = 'CURRENT';
    
     SEQUENCE#
    ----------
          9100
    
    
  3. Start RMAN and make an online backup of the database. For example, enter:

    RMAN> BACKUP DATABASE;
    
    
  4. Archive all unarchived logs, including the current log:

    RMAN> SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
    
    
  5. In SQL*Plus, query V$LOG to determine the log sequence number of the current redo log:

    SQL> SELECT SEQUENCE# FROM V$LOG WHERE STATUS = 'CURRENT';
    
     SEQUENCE#
    ----------
          9112
    
    
  6. Back up the logs beginning with the first sequence number that you queried, and ending with the last sequence number minus 1. The log before the current log is the most recent archived log. For example, if the first query returned 9100, then start at 9100. If the second query returned 9112, then end at 9111.

    For example, issue the following to back up the necessary archived logs:

    RMAN> BACKUP ARCHIVELOG FROM SEQUENCE 9100 UNTIL SEQUENCE 9111;
    

Backing Up and Deleting Multiple Copies of an Archived Redo Log: Example

In this scenario, you set initialization parameters so that you automatically archive redo logs to two directories: ?/oradata/trgt/arch/dest_1 and ?/oradata/trgt/arch/dest_2. Therefore, you have two identical copies of the archived redo log for each log sequence number. You decide to back up each copy of the archived redo logs and then delete the originals. (Note that the degree of backup duplexing configured or specified in the BACKUP command determines the number of output files, independent of the number of input files. See Duplexing Backup Sets for details.)

The easiest solution in this case is to use the DELETE ALL INPUT option means that RMAN deletes all logs that match the ARCHIVELOG criteria. Hence, it can remove all logs from both ?/oradata/trgt/arch/dest_1 and ?/oradata/trgt/arch/dest_2.

For example, run the following command to back up all logs that could be used to recover from a point 10 days ago, and then delete all logs within the specified time range from disk:

RMAN> BACKUP DEVICE TYPE sbt
  ARCHIVELOG ALL FROM TIME 'SYSDATE-10'
  DELETE ALL INPUT;

Determining How Channels Distribute a Backup Workload: Example

When you create multiple backup sets and allocate multiple channels, RMAN automatically writes multiple backup sets in parallel. The allocated server sessions share the work of backing up the specified datafiles, control files, and archived redo logs. Note that you cannot stripe a single backup set across multiple channels.

RMAN automatically assigns a backup set to a device. You can use the CHANNEL parameter so that RMAN writes all backup sets for a backupSpec to a specific channel.

For example, this example parallelizes the backup operation by specifying which channels RMAN should back up to disk and which to sbt:

RMAN> RUN
{
  ALLOCATE CHANNEL ch1 DEVICE TYPE DISK FORMAT = '/backup/df/%U';
  ALLOCATE CHANNEL ch2 DEVICE TYPE DISK FORMAT = '/backup/cf/%U';
  ALLOCATE CHANNEL ch3 DEVICE TYPE sbt;
  BACKUP AS BACKUPSET # all output files are in backup sets
    # channel ch1 backs up datafiles to /backup/df directory
    DATAFILE 1,2,3,4 
    CHANNEL ch1
    # channel ch2 backs up control file copy to /backup/cf directory
    CONTROLFILECOPY '/tmp/control01.ctl'
    CHANNEL ch2;
  BACKUP AS BACKUPSET
    # channel ch3 backs up archived redo logs to tape
    ARCHIVELOG FROM TIME 'SYSDATE-14'
    CHANNEL ch3;
}


Note:

You cannot back up to DISK and sbt at the same time using configured channels: you must manually allocate them.

Backing Up in NOARCHIVELOG Mode: Example

This script puts the database into the correct mode for a consistent, whole database backup and then backs up the database. The script performs a shutdown, startup, shutdown, and then startup again before creating multiple copies of the backup:

# Shut down database cleanly with immediate option. This type of shutdown lets  
# current calls to the database complete, but prevents further logons or calls. 
# If the database is not up, you receive a message saying so but RMAN will not 
# treat this situation as an error.
SHUTDOWN IMMEDIATE; 
  
# Start up the database in case it suffered instance failure or was 
# closed with SHUTDOWN ABORT before starting this script. 
# The script performs instance recovery if 
# needed. Oracle uses the default init.ora file. Alternatively, use this form:
# STARTUP FORCE DBA pfile=filename. 
# Use the DBA option because you are going to shut down again
# and do not want to let users in during the short interval. Use the FORCE 
# option because it cannot hurt and might help in certain situations. 
STARTUP FORCE DBA; 
SHUTDOWN IMMEDIATE; 
  
# The database is cleanly closed and ready for a consistent backup. RMAN
# requires that the database be started and mounted to perform a backup.
RMAN> STARTUP MOUNT;

# this example uses automatic channels to make the backup
BACKUP 
  COPIES 2 
  INCREMENTAL LEVEL 0 
  MAXSETSIZE 10M 
  DATABASE 
  INCLUDE CURRENT CONTROLFILE
  TAG 'BACKUP_1'
;

# Now that the backup is complete, open the database. 
ALTER DATABASE OPEN; 

Note the inclusion of the current control file with the backup, and the use of the tag to identify the backup. To use this backup of the database, the control file must be restored from the same backup as the rest of the database. Adding INCLUDE CURRENT CONTROLFILE ensures that a usable backup of the control file is included with the backup and tagged in order to simplify restoring the control file with the rest of the database.

You can skip tablespaces, such as read-only tablespaces, but any skipped tablespace that has not been offline or read-only since its last backup is lost if the database has to be restored from a backup.

Keeping a Long-Term Backup: Example

If you configure a retention policy, then you may want to exclude specified backups from this policy. For example, you may want to archive a consistent backup of the database once a year to serve as a historical record. This long-term backups does not function as a backup that you may perform recovery on, but an archived snapshot of data at a particular time.

To exempt a backup from the retention policy, specify the KEEP option on the BACKUP command. You can also specify LOGS or NOLOGS to indicate whether RMAN should save archived logs for possible recovery of this backup. If you specify NOLOGS, then the backup must be consistent.

This example keeps the backup of the database indefinitely and does not save archived logs needed to recover it:

RMAN> SHUTDOWN IMMEDIATE;
RMAN> STARTUP MOUNT;  # put database in consistent state
RMAN> BACKUP DATABASE KEEP FOREVER NOLOGS 
              TAG 'db_archive_1'; # make long-term consistent backup

# mark backup as unavailable in the repository so that RMAN does not attempt to
# restore it unless explicitly specified on the RESTORE command
RMAN> CHANGE BACKUP TAG 'db_archive_1' UNAVAILABLE;
RMAN> SQL 'ALTER DATABASE OPEN';

Using Backup Optimization: Examples

Run the CONFIGURE BACKUP OPTIMIZATION command to enable backup optimization. When specific conditions are met (described in "Backup Optimization Algorithm"), RMAN skips backups of files that are identical to files that are already backed up.

Assume that you configure optimization and a retention policy as follows:

CONFIGURE DEFAULT DEVICE TYPE TO sbt;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 4 DAYS;

Optimizing a Database Backup: Example

Then, you run this command every night to back up the database to tape:

BACKUP DATABASE;

Because backup optimization is configured, RMAN skips backups of offline and read-only datafiles only if the most recent backups were made on or after the earliest point in the recovery window. RMAN does not skip backups when the most recent backups are older than the window. For example, optimization ensures you do not end up with a new backup of the read-only datafile ?/oradata/trgt/history01.dbf every night, so long as one backup set containing this file exists within the recovery window.

For example, if the most recent backup of the datafiles was on Sunday, and the point of recoverability (that is, the earliest date in the recovery window) is on Saturday, then RMAN skips the datafiles when you run the Wednesday backup. On Friday, the point of recoverability is now Monday, so the Sunday backup is now outside the window. Hence, the Friday backup does not skip the datafiles.

Optimizing a Daily Archived Log Backup to a Single Tape: Example

Assume that you want to back up all the archived logs every night. However, you do not want to have multiple copies of each log sequence number. So, you configure backup optimization to ON, then run this command in a script every night at 1 a.m.:

BACKUP DEVICE TYPE sbt ARCHIVELOG ALL;

RMAN skips all logs except those produced in the last 24 hours. In this way, you keep only one copy of each archived log on tape.

Optimizing a Daily Archived Log Backup to Multiple Tapes: Example

In this example, you back up logs that are not already on tape to one tape pool, then back up the same logs to a second tape pool. Finally, you delete old logs.

For the first step, perform the one-time configuration:

# configure backup optimization
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO sbt;

Then, run the following script at the same time every night to back up the logs generated during the previous day to two separate tape pools:

# The following command backs up just the logs that are not on tape. The 
# first copies are saved to the tapes from the pool "archivelog_pool_1"
RUN
{
  ALLOCATE CHANNEL c1 DEVICE TYPE sbt
    PARMS='NSR_DATA_VOLUME_POOL=ARCHIVELOG_POOL_1';
  BACKUP ARCHIVELOG ALL;
}
# Make one more copy of the archived logs and save them to tapes from a 
# different pool 
RUN
{
  ALLOCATE CHANNEL c2 DEVICE TYPE sbt 
    PARMS='NSR_DATA_VOLUME_POOL=ARCHIVELOG_POOL_2';
  BACKUP ARCHIVELOG
    FROM TIME 'SYSDATE-1'
    UNTIL TIME 'SYSDATE'; 
# specify UNTIL so RMAN does not archive current log
}
# Delete old logs - for example, delete logs created within the last week. 
DELETE ARCHIVELOG ALL COMPLETED AFTER 'SYSDATE-7';

Note:

Specifying the UNTIL TIME clause causes RMAN to not use backup optimization in deciding which archive logs to back up. In this case, logs are backed up even if other usable backups are already available.

Creating a Weekly Secondary Backup of Archived Logs: Example

Assume a more sophisticated scenario in which your goal is to back up the archived logs to tape every day. However, you are worried about tape failure, so you want to ensure that you have more than copy of each log sequence number on an separate tape before you perform your weekly deletion of logs from disk.

First, perform a one-time configuration:

# configure backup optimization
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEVICE TYPE sbt PARALLELISM 1;
CONFIGURE default DEVICE TYPE TO sbt;
# configure a default channel that sends backups to tape pool "first_copy"
CONFIGURE CHANNEL DEVICE TYPE sbt PARMS='ENV=(NSR_DATA_VOLUME_POOL=first_copy);

Because you have optimization enabled, you can run the following command every evening to back up all archived logs to the "first_copy" pool that have not already been backed up:

BACKUP ARCHIVELOG ALL TAG first_copy;

Every Friday evening you create an additional backup of all archived logs in a different tape pool. Also, at the end of the backup, you want to delete all archived logs that already have at least two copies on tape. So you run the following script:

RUN
{
  # manually allocate a channel, in order to specify that the backup run by this
  # channel should go to both pools "first_copy" and "second_copy"
  ALLOCATE CHANNEL c1 DEVICE TYPE sbt
      PARMS='ENV=(NSR_DATA_VOLUME_POOL=second_copy)';
  ALLOCATE CHANNEL c2 DEVICE TYPE sbt
      PARMS='ENV=(NSR_DATA_VOLUME_POOL=first_copy)';
  BACKUP CHANNEL C1 ARCHIVELOG UNTIL TIME 'SYSDATE' 
    NOT BACKED UP 2 TIMES # back up only logs without 2 backups on tape
    TAG SECOND_COPY; 
  BACKUP CHANNEL C2 ARCHIVELOG UNTIL TIME 'SYSDATE' 
    NOT BACKED UP 2 TIMES # back up only logs without 2 backups on tape
    TAG FIRST_COPY;
}

# now delete from disk all logs that have been backed up to tape at least twice
DELETE ARCHIVELOG ALL
  BACKED UP 2 TIMES TO DEVICE TYPE sbt;

The Friday script creates a second copy of all archived logs in the "second_copy" tape pool. After the backup, you can send the tape from the pool "second_copy" to secure storage. You should use this tape backup only if the primary tape from pool "first_copy" is damaged. Because the secondary tape is in a secure place, you do not want RMAN to use it for recovery, so you can mark the backup as unavailable:

CHANGE BACKUP OF ARCHIVELOG TAG SECOND_COPY UNAVAILABLE;

Handling Corruption During Backups: Example

By default a checksum is calculated for every block read from a datafile and stored in the backup or image copy. If you use the NOCHECKSUM option, then checksums are not calculated. If the block already contains a checksum, however, then the checksum is validated and stored in the backup. If the validation fails, then the block is marked corrupt in the backup.

The SET MAXCORRUPT FOR DATAFILE command sets how many corrupt blocks in a datafile that BACKUP will tolerate. If a datafile has more corrupt blocks than specified by the MAXCORRUPT parameter, the command terminates. If you specify the CHECK LOGICAL option, RMAN checks for logical and physical corruption.

By default, the BACKUP command terminates when it cannot access a datafile. You can specify parameters to prevent termination, as listed in the following table.

If you specify the option ... Then RMAN skips...
SKIP INACCESSIBLE Inaccessible datafiles. A datafile is only considered inaccessible if it cannot be read. Some offline datafiles can still be read because they exist on disk. Others have been deleted or moved and so cannot be read, making them inaccessible.
SKIP OFFLINE Offline datafiles.
SKIP READONLY Datafiles in read-only tablespaces.

The following example uses an automatic channel to back up the database, and sets the corruption level for the datafile in the SYSTEM tablespace so that up to 10 errors will be accepted:

RMAN> RUN
{
  SET MAXCORRUPT FOR DATAFILE 1 TO 10;
  BACKUP DATABASE
    SKIP INACCESSIBLE
    SKIP READONLY
    SKIP OFFLINE; 
}