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

Part Number B14191-03
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
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

6 Making Backups with RMAN: Advanced Topics

This chapter describes how to use RMAN to make backups. This chapter contains these topics:

Configuring and Allocating Channels for Use in Backups

You have the following options for executing backups:

The easiest way to make backups is to configure automatic channels. For example, so long as you have already configured an sbt device type, you can configure a default sbt channel as follows (note that the PARMS value is vendor-specific) and then back up the database using these defaults:

RMAN> CONFIGURE DEVICE TYPE sbt PARALLELISM 1;
RMAN> CONFIGURE DEFAULT DEVICE TYPE TO sbt;
RMAN> CONFIGURE CHANNEL DEVICE TYPE sbt PARMS 'ENV=(NSR_SERVER=bksvr1)';
RMAN> BACKUP DATABASE;

RMAN preconfigures a DISK channel for you, so you can make disk backups using automatic channels without performing any configuration whatsoever.

The other method is to allocate channels manually within a RUN block before running the BACKUP command. For example, this command allocates multiple disk channels and then backs up the database and archived redo logs:

RMAN> RUN
{ 
  ALLOCATE CHANNEL ch1 DEVICE TYPE DISK;
  ALLOCATE CHANNEL ch2 DEVICE TYPE DISK;
  ALLOCATE CHANNEL ch3 DEVICE TYPE DISK;
  BACKUP DATABASE PLUS ARCHIVELOG;
}

The following example manually allocates an sbt channel (with a vendor-specific PARMS value) and backs up a datafile copy:

RMAN> RUN
{ 
  ALLOCATE CHANNEL ch1 DEVICE TYPE sbt PARMS 'ENV=(NSR_SERVER=bksvr1)';
  BACKUP DATAFILECOPY '/tmp/system01.dbf';
}

Most examples in this chapter assume that you have configured automatic channels.

Duplexing Backup Sets

RMAN can make up to four copies of a backup set simultaneously, each an exact duplicate of the others. A copy of a backup set is a copy of each backup piece in the backup set, with each copy getting a unique copy number (for example, 0tcm8u2s_1_1 and 0tcm8u2s_1_2).

In most cases, the easiest method of duplexing backup sets is to use BACKUP... COPIES or CONFIGURE ... BACKUP COPIES to duplex backup sets. For DISK channels, specify multiple values in the FORMAT option to direct the multiple copies to different physical disks. For sbt channels, if you use a media manager that supports Version 2 of the SBT API, then the media manager will automatically put each copy onto a separate medium (for example, a separate tape).

Note that it is not possible to duplex backup sets to the flash recovery area, and that duplexing only applies to backup sets, not image copies. It is an error to specify the BACKUP... COPIES when creating image copy backups, and the CONFIGURE... BACKUP COPIES setting is ignored for image copy backups.

Duplexing Backup Sets with CONFIGURE BACKUP COPIES

The CONFIGURE ... BACKUP COPIES command specifies the number of identical backup sets that you want to create on the specified device type. This setting applies to all backups except control file autobackups (because the autobackup of a control file always produces one copy) and backup sets when backed up with the BACKUP BACKUPSET command. You must have automatic channels configured.

To duplex a backup with CONFIGURE BACKUP COPIES:

Configure the number of copies on the desired device type for datafiles and archived redo logs on the desired device types. This example configures duplexing for datafiles and archived logs on tape as well as duplexing for datafiles (but not archived logs) on disk:

RMAN> CONFIGURE DEVICE TYPE sbt PARALLELISM 1;
RMAN> CONFIGURE DEFAULT DEVICE TYPE TO sbt;
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/save1/%U', '/save2/%U';
RMAN> CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE sbt TO 2;
RMAN> CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE sbt TO 2;
RMAN> CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2;

Execute the BACKUP command. The following command backs up the database and archived logs to tape, making two copies of each datafile and archived redo log:

RMAN> BACKUP DATABASE PLUS ARCHIVELOG; # uses default sbt channel

Because of the configured formats for the disk channel, the following command backs up the database to disk, placing one copy of the backupsets produced in the /save1 directory and the other in the /save2 directory:

RMAN> BACKUP DEVICE TYPE DISK AS COPY DATABASE;

Issue a LIST BACKUP command to see a listing of backup sets and pieces. For example, enter:

RMAN> LIST BACKUP SUMMARY;

The #Copies column shows the number of backupsets, which may have been produced by duplexing or by multiple backup commands.

Duplexing Backupsets with BACKUP... COPIES

The COPIES option of the BACKUP command overrides every other COPIES or DUPLEX setting to control duplexing of backupsets.

To duplex a backup with BACKUP COPIES:

Specify the number of identical copies with the COPIES option of the BACKUP command. For example, run the following to make three copies of each backup set in the default DISK location:

RMAN> BACKUP AS BACKUPSET DEVICE TYPE DISK 
  COPIES 3 
  INCREMENTAL LEVEL 0 
  DATABASE;

Because you specified COPIES on the BACKUP command, RMAN makes three backupsets of each datafile regardless of the CONFIGURE DATAFILE COPIES setting.

Issue a LIST BACKUP command to see a listing of backup sets and pieces (the #Copies column shows the number of copies, which may have been produced through duplexing or through multiple invocations of the BACKUP command). For example, enter:

RMAN> LIST BACKUP SUMMARY;

Making Split Mirror Backups with RMAN

Many sites keep an backup of the database stored on disk in case a failure occurs on the primary database or an incorrect user action such as a DROP TABLE requires point-in-time recovery. A datafile backup on disk simplifies the restore step of recovery, making recovery much quicker and more reliable.

Caution:

Never make backups, split mirror or otherwise, of online redo logs. Restoring online redo log backups can create two archived logs with the same sequence number but different contents. Also, it is best to use the BACKUP CONTROLFILE command rather than a split mirror to make control file backups.

One way of creating a datafile backup on disk is to use disk mirroring. For example, you can use the operating system to maintain three identical copies of each file in the database. In this configuration, you can split off a mirrored copy of the database to use as a backup.

RMAN does not automate the splitting of mirrors, but can make use of split mirrors in backup and recovery operations. For example, RMAN can treat a split mirror of a datafile as a datafile copy, and can also back up this copy to disk or tape.

The following procedure shows how to make a split mirror backup with the SUSPEND/RESUME functionality. The SUSPEND/RESUME feature is not required for split mirror backups in most cases, although it is necessary if your system requires the database cache to be free of dirty buffers before the volume can be split.

To make a split mirror backup of a tablespace by using SUSPEND/RESUME:

Start RMAN and then place the tablespaces that you want to back up into backup mode with the ALTER TABLESPACE ... BEGIN BACKUP statement. (To place all tablespaces in backup mode, you can use ALTER DATABASE BEGIN BACKUP instead.)

For example, to place tablespace users in backup mode, start RMAN and run the following commands:

RMAN> CONNECT TARGET SYS/oracle@trgt 
RMAN> CONNECT CATALOG rman/cat@catdb

RMAN> SQL 'ALTER TABLESPACE users BEGIN BACKUP'; 

Suspend the I/Os if your mirroring software or hardware requires it. For example, enter the following SQL statement:

RMAN> SQL 'ALTER SYSTEM SUSPEND';

Split the mirrors for the underlying datafiles contained in these tablespaces.

Take the database out of the suspended state:

RMAN> SQL 'ALTER SYSTEM RESUME';

Take the tablespaces out of backup mode. For example, enter:

RMAN> SQL 'ALTER TABLESPACE users END BACKUP';

You could also use ALTER DATABASE END BACKUP to take all tablespaces out of backup mode.

Start an RMAN session and then catalog the user-managed mirror copies as datafile copies with the CATALOG command. For example, enter:

RMAN> CATALOG DATAFILECOPY '/dk2/oradata/trgt/users01.dbf'; # catalog split mirror

Back up the datafile copies. For example, assuming that you have configured automatic channels, run the BACKUP DATAFILECOPY command at the prompt:

RMAN> BACKUP DATAFILECOPY '/dk2/oradata/trgt/users01.dbf';

When you are ready to resilver the split mirror, first use the CHANGE ... UNCATALOG command to uncatalog the datafile copies you cataloged in step 6. For example, enter:

RMAN> CHANGE DATAFILECOPY '/dk2/oradata/trgt/users01.dbf' UNCATALOG;

Resilver the split mirror for the affected datafiles.

See Also:

Oracle Database SQL Reference for ALTER SYSTEM SUSPEND syntax

Backing Up Backup Sets with RMAN

Use the BACKUP BACKUPSET command to back up backup sets produced by other backup jobs. This command is especially useful in the following scenarios:

To back up backup sets from disk to tape:

Assuming that you have configured an automatic sbt channel, issue the BACKUP BACKUPSET command at the RMAN prompt. This example backs up all disk backup sets to tape:

RMAN> BACKUP DEVICE TYPE sbt BACKUPSET ALL;

This example backs up all disk backup sets to tape and then deletes the input disk backups:

RMAN> BACKUP DEVICE TYPE sbt BACKUPSET ALL DELETE INPUT; 

Issue a LIST command to see a listing of backup sets and pieces.

BACKUP BACKUPSET and Backup Retention Policy

BACKUP BACKUPSET creates additional copies of backup pieces in a backup set by copying backup pieces from disk to tape. If you use the LIST BACKUPS command, the output contains the list of all copies (including copies created by BACKUP BACKUPSET command).

However, BACKUP BACKUPSET does not create a new backup set. In this way, BACKUP BACKUPSET is similar to using the DUPLEX or MAXCOPIES option of BACKUP. The extra copy of a backup set created by BACKUP BACKUPSET is not considered to be a new backup set, as the several copies of a backup set produced by these other forms of the BACKUP command are not separate backup sets.

For the purposes of a redundancy-based backup retention policy, a backup set is counted as one instance of backup, even if there are multiple copies of the backup pieces that make up backup set, such as when a backup set has been backed up from disk to tape. For the purposes of a recovery window retention policy, either all of the copies of a backup set are obsolete, or none of them are.

This is easier to understand if you look at the output of the LIST and REPORT commands. For example, perform the following backup:

RMAN> backup as backupset datafile 5 
RMAN> backup backupset <previous backupset>; 

Now, run the LIST command. The output contains the following:

Notice that the set_stamp and set_count values remain the same, but the copy# is incremented for the new backup. To see the effect of these copies under a redundancy-based backup retention policy, use the following command:

report obsolete redundancy 1;
 

None of the copies is reported as obsolete because both copies of the backup set have the same values for set_stamp & set_count.

To see the effect of these copies under a recovery window-based retention policy, use the following command:

report obsolete recovery window 1 day;
 

None of the copies of the backup set is reported as obsolete or based on the checkpoint_change# of this backupset, with respect to the current time and the availability of other backups.

Backing Up Existing Image Copy Backups with RMAN

Use the BACKUP COPY OF command to back up image copies of datafiles, control files, and archived logs. The output of the BACKUP COPY OF command can be either backup sets or image copies, so you can generate backup sets from your image copies. This form of backup is used to back up a database backup created as image copies on disk to tape. You can use the MAXSETSIZE parameter of the BACKUP command to set a maximum size for each backup set.

Assuming that you have configured an automatic sbt channel, issue this command to back up the latest image copy backup of the database to tape:

RMAN> BACKUP DEVICE TYPE sbt COPY OF DATABASE;

This example backs up the latest image copy backup of a database to backup sets on tape, and then deletes the input disk backups:

RMAN> BACKUP DEVICE TYPE sbt COPY OF DATABASE DELETE INPUT; 

When backing up your image copies, identifying the image copy to back up is easier if you provide tags for your backups. Image copies of datafiles have associated tags (if you do not provide one, one is automatically generated). The tag of an image copy is inherited by default when the image copy is backed up as a new image copy. You can also specify your own tag.

To take advantage of the tags associated with your image copy backups, use the WITH TAG selector. The new backup will be tagged with the same tag as the image copy backup being backed up. When multiple image copies have the same tag, the most recent image copy of a file with the specified tag will be backed up.

RMAN Encrypted Backups

For improved security, RMAN backups created as backup sets can be encrypted. Encrypted backups cannot be read if they are obtained by unauthorized people.

Any RMAN backups as backup sets can be encrypted. However, image copy backups cannot be encrypted.

Encrypted backups are decrypted automatically during restore and recover operations, as long as the required decryption keys are available, by means of either a user-supplied password or the Oracle Encryption Wallet.

To use RMAN encryption, the COMPATIBLE initialization parameter at the target database must be set to at least 10.2.0.

When the BACKUP BACKUPSET command is used with encrypted backup sets, the backup sets are backed up in their encrypted form. Because BACKUP BACKUPSET just copies an already-encrypted backup set to disk or tape, no decryption key is needed during a BACKUP BACKUPSET operation, and the data is never decrypted during any part of the operation. The BACKUP BACKUPSET command can neither encrypt nor decrypt backup sets.

If some columns in the database are encrypted using Transparent Data Encryption, and those columns are backed up using backup encryption, then those columns will be encrypted a second time during the backup. When the backup sets are decrypted during a restore, the encrypted columns are returned to their original encrypted form.

The V$RMAN_ENCRYPTION_ALGORITHMS view contains a list of encryption algorithms supported by RMAN. If no encryption algorithm is specified, the default encryption algorithm is 128-bit AES.

RMAN Backup Encryption Modes

RMAN offers three encryption modes: transparent mode, password mode, and dual mode.

Note:

Both transparent mode and dual mode depend upon the Oracle Encryption Wallet. See Oracle Advanced Security Administrator's Guide for details about configuring the Oracle Encryption Wallet.

Transparent Encryption of Backups

Transparent encryption can create and restore encrypted backups with no DBA intervention, as long as the required Oracle key management infrastructure is available. Transparent encryption is best suited for day-to-day backup operations, where backups will be restored at the same database that they were backed up from. Transparent encryption is the default mode for RMAN encryption.

When using transparent encryption, you must first configure the Oracle Encryption Wallet, as described in the documentation for Oracle's Transparent Data Encryption feature. After the Oracle Encryption Wallet is configured, encrypted backups can be created and restored with no further DBA intervention.

Note:

Because the Oracle key management infrastructure archives all previous master keys in the Oracle Encryption Wallet, changing or resetting the current database master key will not affect your ability to restore encrypted backups performed using an older master key. You may reset the database master key at any time, and RMAN will always be able to restore all encrypted backups that were ever created by this database.

Transparent backup encryption supports both the encrypted and autologin forms of the Oracle Encryption Wallet. When using the encrypted wallet, the wallet must be opened before any backup encryption operations, either backups or restores, can be done. When using the autologin wallet, encrypted backup operations can be done at any time, because the autologin wallet is always open.

Caution:

If you use an autologin wallet, do not back up the autologin wallet along with your encrypted backup data, because anybody will be able to read the encrypted backups if they obtain both the backups and the autologin wallet. It is safe to back up the encrypted wallet, because that form of the wallet cannot be used without the wallet password.

Caution:

If you lose your Oracle Encryption Wallet then you will be unable to restore any transparently-encrypted backups.

Password Encryption of Backups

Password encryption requires that the DBA provide a password when creating and restoring encrypted backups. Restoring a password-encrypted backup requires the same password that was used to create the backup. Password encryption is useful for backups that will be restored at remote locations, but which must remain secure in transit. Password encryption cannot be persistently configured. The Oracle Encryption Wallet need not be configured if password encryption is to be used exclusively.

Caution:

If you forget, or lose, the password that you used to encrypt a password-encrypted backup, you will be unable to restore that backup.

To use password encryption, use the SET ENCRYPTION ON IDENTIFIED BY password ONLY command in your RMAN scripts.

Dual Mode Encryption of Backups

Dual-mode encrypted backups can be restored either transparently or by specifying a password. Dual-mode encrypted backups are useful when you create backups that are normally restored on-site using the Oracle Encryption Wallet, but which occasionally need to be restored off-site, where the Oracle Encryption Wallet is not available.

When restoring a dual-mode encrypted backup, you can use either the Oracle Encryption Wallet or a password for decryption.

Caution:

If you forget, or lose, the password that you used to encrypt a dual-mode encrypted backup and you also lose your Oracle Encryption Wallet, then you will be unable to restore that backup.

To create dual-mode encrypted backup sets, specify the SET ENCRYPTION ON IDENTIFIED BY password command in your RMAN scripts.

Using CONFIGURE and SET to Control RMAN Backup Encryption

The CONFIGURE command is used to make persistent settings controlling RMAN encryption of backups, including:

  • Whether to encrypt backups of all database files.

  • Whether to encrypt backups of specific tablespaces.

  • Which algorithm to use for encrypting backups.

The SET ENCRYPTION command is used to:

  • Override the encryption settings specified by the CONFIGURE ENCRYPTION command. For example, you can use SET ENCRYPTION OFF to create an unencrypted backup, even though your database is configured to create encrypted backups.

  • Set a password for backup encryption, persisting until the RMAN client exits. Due to the sensitive nature of passwords, RMAN does not allow configuration of passwords that persist between RMAN sessions.

If you wish to modify your existing backup environment so that all RMAN backups are encrypted, perform the following steps:

  • Set up the Oracle Encryption Wallet

  • Issue the following RMAN command:

    RMAN> CONFIGURE ENCRYPTION FOR DATABASE ON
    

After these steps, all RMAN backup sets created by this database will be encrypted, unless you explicitly override this behavior for an RMAN session with:

RMAN> SET ENCRYPTION ON

This remains in effect until you issue the SET ENCRYPTION OFF command during an RMAN session, or change the persistent setting again with:

RMAN> CONFIGURE ENCRYPTION FOR DATABASE OFF

Creating Encrypted Backups

The BACKUP command arguments do not change for creating encrypted backups. Encryption is performed based on the encryption settings specified with CONFIGURE ENCRYPTION or SET ENCRYPTION. Any backup to backup sets is encrypted with the specified settings.

Oracle uses a new encryption key for every encrypted backup. The backup encryption key is then encrypted with either the password, the database master key, or both, depending on the chosen encryption mode. Individual backup encryption keys or passwords are never stored in the clear.

Restoring Data from Encrypted Backups

RMAN automatically decrypts backup sets when their contents are restored. Transparently encrypted backups require no intervention to restore, as long as the Oracle Encryption Wallet is open and available. Password encrypted backups require the correct password to be entered before they can be restored.

You must enter the encryption password using the SET DECRYPTION command. Restore passwords cannot be persistently configured. If restoring from a set of backups that were created with different passwords, then specify all of the required passwords on the SET DECRYPTION command. RMAN will automatically use the correct password with each backup set.

Encryption of Archived Log Backups

There is no persistent configuration that controls whether archivelog backups as backupsets are encrypted. Backup sets containing archived logs are encrypted if any of the following are true:

  • SET ENCRYPTION ON is in effect at the time that the archive log backup is being created.

  • Encryption is configured for backups of the whole database or at least one tablespace.

This behavior ensures that the redo associated with any encrypted backup of a datafile is also encrypted.

Performance Impact of Encrypting RMAN Backups

Encryption can have a negative effect upon backup performance. Because encrypted backups will use more CPU resource than non-encrypted backups, you can improve performance of encrypted backups by using more RMAN channels.

Restarting and Optimizing RMAN Backups

RMAN supports two distinct features by which it can back up only those files that require backups: restartable backups and backup optimization.

With the restartable backup feature, RMAN backs up only those files that were not backed up after a specified date. For example, by specifying the NOT BACKED UP SINCE TIME clause, you can direct RMAN to back up only those files that were not backed up within the last day.

With backup optimization, the BACKUP command skips the backup of a file if the identical file has already been backed up to the allocated device type. To override this behavior and back up all files whether or not they have changed, specify the FORCE option on the BACKUP command. To enable or disable backup optimization, specify ON or OFF on the CONFIGURE BACKUP OPTIMIZATION command.

Additionally, BACKUP ... PLUS ARCHIVELOG can archive unarchived online logs as well as back up archived logs.

See Also:

"Backup Optimization" for a conceptual overview of optimization, and "Restartable Backups" for a conceptual overview of restartable backups

Backing Up Files Using Backup Optimization

For backup optimization to be enabled, you must CONFIGURE BACKUP OPTIMIZATION to ON. Backup optimization is OFF by default.

To use backup optimization with a backup operation:

If you have not already enabled backup optimization, then enable it by running the CONFIGURE BACKUP OPTIMIZATION command. For example, enter:

RMAN> CONFIGURE BACKUP OPTIMIZATION ON;

Back up the desired files. The following example backs up to an sbt device any archived redo logs that either have not been already backed up, or where the existing backups do not satisfy the current duplexing setting:

RMAN> BACKUP DEVICE TYPE sbt ARCHIVELOG ALL;

RMAN does not signal an error when it skips backing up files due to backup optimization.

See Also:

"Backup Optimization" for a conceptual overview of optimization and backup retention policies

Restarting a Backup After It Partially Completes

Use the SINCE TIME parameter of the BACKUP command to specify a date after which a new backup is required. If you do not specify the SINCE parameter, then RMAN only backs up files that have never been backed up.

To only back up files that were not backed up after a specified date:

Specify a valid date in the SINCE TIME parameter. For example, this command uses the default configured channel to back up all database files and archived redo logs that have not been backed up in the last two weeks:

RMAN> BACKUP NOT BACKED UP SINCE TIME 'SYSDATE-14'
          DATABASE PLUS ARCHIVELOG;

Backups to CD, DVD and Other Disk Devices with Large Block Sizes

When backing up database files to DISK, the logical block size of the database file to be backed up must be an even multiple of the physical block size of the destination device. For example, a DISK device with a block size of 2K can only be used as a destination for backups of database files with logical block sizes of 2K, 4K, 6K and so on. In practice, most disk drives have physical block sizes of 512 bytes, so this limitation rarely affects backup to disk drives. However, you can encounter this limitation when using BACKUP ... DEVICE TYPE DISK to back your database up to a writeable CD or DVD, or some other device which has a larger physical block size.

Validating Backups with RMAN

You can use the VALIDATE keyword of the BACKUP command to do the following:

RMAN does not actually produce backup sets, but rather reads the specified files in their entirety, to determine whether they can be backed up and are not corrupted. In this sense, the BACKUP... VALIDATE command is similar to the RESTORE... VALIDATE command, except for backups rather than restore jobs.

If the backup validation discovers corrupt blocks, then RMAN updates the V$DATABASE_BLOCK_CORRUPTION view with rows describing the corruptions. After a corrupt block is repaired, the row identifying this block is deleted from the view.

For example, you can validate that all database files and archived redo logs can be backed up by running a command as follows:

RMAN> BACKUP VALIDATE DATABASE ARCHIVELOG ALL;

This form of the command would check for physical corruption. To check for logical corruption,

RMAN> BACKUP VALIDATE CHECK LOGICAL DATABASE ARCHIVELOG ALL;

RMAN displays the same output that it would if it were really backing up the files. If RMAN cannot validate the backup of one or more of the files, then it displays an error message. For example, RMAN may show output similar to the following:

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 08/29/2001 14:33:47
ORA-19625: error identifying file /oracle/oradata/trgt/arch/archive1_6.dbf
ORA-27037: unable to obtain file status
SVR4 Error: 2: No such file or directory
Additional information: 3

You cannot use the MAXCORRUPT or PROXY parameters with the VALIDATE option.

See Also:

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 available, 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 the 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.

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

SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

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

Start RMAN and make an online backup of the database. For example, enter:

RMAN> BACKUP DATABASE;

Archive all unarchived logs, including the current log:

RMAN> SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';

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

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; 
}