Oracle® Database Backup and Recovery Advanced User's Guide 10g Release 1 (10.1) Part Number B10734-01 |
|
|
View PDF |
This chapter describes how to use RMAN to make backups. This chapter contains these topics:
You have the following options for executing backups:
CONFIGURE
command, and then issue BACKUP
commands at the RMAN prompt or within a RUN
blockALLOCATE CHANNEL
command, and then issue BACKUP
commands using those channelsThe 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
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'; }
For the most part, the procedures in this chapter assume that you have configured automatic channels.
When backing up to disk, it is recommended to create image copies, rather than backup sets. Some features of RMAN backups, such as incrementally updated backups, require the use of image copies. Also, image copy backups are more convenient to use in some restore and recovery scenarios. However, by default, the BACKUP
command creates backups as backup sets, when backing up to disk as well as to tape. (Backups to tape must be stored as backup sets.)
To configure RMAN to create image copies by default when backing up to disk, use the following command:
RMAN> CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY;
To return RMAN to its default behavior of producing backup sets, use the following command:
RMAN> CONFIGURE DEVICE TYPE DISK BACKUP TYPE CLEAR;
It is safer to make multiple copies of backups to protect against disaster, media damage, or human error. 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 is to use BACKUP...
COPIES
or CONFIGURE
...
BACKUP
COPIES
to duplex backup sets. There is little value in creating multiple copies on the same physical media. 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.
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:
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;
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;
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.
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:
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.
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;
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.
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:
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';
RMAN> SQL 'ALTER SYSTEM SUSPEND';
RMAN> SQL 'ALTER SYSTEM RESUME';
RMAN> SQL 'ALTER TABLESPACE users END BACKUP';
You could also use ALTER DATABASE END BACKUP
to take all tablespaces out of backup mode.
CATALOG
command. For example, enter:
RMAN> CATALOG DATAFILECOPY '/dk2/oradata/trgt/users01.dbf'; # catalog split mirror
BACKUP
DATAFILECOPY
command at the prompt:
RMAN> BACKUP DATAFILECOPY '/dk2/oradata/trgt/users01.dbf';
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;
See Also:
Oracle Database SQL Reference for |
Use the BACKUP
BACKUPSET
command to back up backup sets rather than database files. This command is especially useful in the following scenarios:
To back up backup sets from disk to tape:
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;
LIST
command to see a listing of backup sets and pieces.Use the BACKUP
COPY
OF
command to back up image copies of datafiles, control files, and archived logs. The output of the BACKUP
command can be either backup sets or image copies, so you can generate backup sets from your image copies. This technique is useful when you want to back up a database backup on disk to tape, because all backups to tape must be backup sets. You can use the MAXSETSIZE
parameter of the BACKUP
command to set a maximum size for each backup set.
To back up image copies from disk to tape:
sbt
channel, issue the BACKUP
COPY
OF
command at the RMAN prompt. This example backs up the latest image copy 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 in backup sets on tape, and then deletes the input disk backups:
RMAN> BACKUP DEVICE TYPE sbt COPY OF DATABASE DELETE INPUT;
LIST
command to see a listing of backup sets and pieces.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 and archived redo logs 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. As explained previously, the tag of the image copy being backed up will also be assigned to the new backup. 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 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 |
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:
CONFIGURE
BACKUP
OPTIMIZATION
command. For example, enter:
RMAN> CONFIGURE BACKUP OPTIMIZATION ON;
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 |
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;
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:
|
This section contains these topics:
Assume that you configure an automatic sbt
channel as follows:
RMAN> CONFIGURE DEVICE TYPE sbt PARALLELISM 1; # configure device RMAN> CONFIGURE CHANNEL DEVICE TYPE sbt PARMS='...'; # configure options for channels RMAN> CONFIGURE DEFAULT DEVICE TYPE to sbt; # set default device type
Assume that you want to back up the database to disk and use the default configured DISK
channel. You can specify that the BACKUP
command should use a DISK
channel as follows:
RMAN> BACKUP DEVICE TYPE DISK DATABASE;
To back up the database to the sbt
device run this command:
RMAN> BACKUP DATABASE;
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 need to back up a read-only tablespace only 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;
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;
RMAN backs up only files that were not backed up during in the previous 24 hours. When RMAN finds out that particular file is already backed up 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
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 accomplish the same result by configuring automatic 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
In this scenario, you have a 35 GB database that you want to back up to disk. Because RMAN can only write one backup piece on a raw disk device, you decide to spread the backup across four file systems. You decide to make each backup set roughly the same size: 10 GB. You want each backup piece to be no more than 2 GB so that each backup set contains up to five backup pieces.
You decide to use the FORMAT
parameter of the CONFIGURE
CHANNEL
command so that each channel will write to a different file system. You use conversion variables to guarantee unique names for the backup pieces. For example, the following commands configure four channels, configures their formats so that they write to the four file systems (/fs1
, /fs2
, /fs3
, /fs4
) and groups the datafiles so that each backup set is about the same size.
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 4; RMAN> CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT='/fs1/%U' MAXPIECESIZE 2G; RMAN> CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT='/fs2/%U' MAXPIECESIZE 2G; RMAN> CONFIGURE CHANNEL 3 DEVICE TYPE DISK FORMAT='/fs3/%U' MAXPIECESIZE 2G; RMAN> CONFIGURE CHANNEL 4 DEVICE TYPE DISK FORMAT='/fs4/%U' MAXPIECESIZE 2G; RMAN> CONFIGURE DEFAULT DEVICE TYPE TO DISK;
Then, you can run this command every night to generate four backup sets, each in a different directory and each approximately the same size:
RMAN> BACKUP AS BACKUPSET DATABASE;
You can also back up the backup sets from disk to four different tapes from a tape pool by setting PARALLELISM=4
for the sbt
device (and specifying the appropriate vendor-specific PARMS
for the sbt
channel), as in the following example:
RMAN> CONFIGURE DEVICE TYPE sbt PARALLELISM 4; RMAN> CONFIGURE CHANNEL DEVICE TYPE sbt PARMS='...'; RMAN> BACKUP DEVICE TYPE sbt BACKUPSET ALL DELETE INPUT;
Note that this example makes certain assumptions, such as no datafile is too large to fit into a backup piece, that there are at least four datafiles in the database, and so on. In extrapolating from this example you must take into account the specifics of your own circumstances.
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
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 limit the backup file 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
.
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 a copy of each log in sequence 288 through 388 is located in at least one of the three directories, RMAN can back up all the specified logs.
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 Recovery Manager Reference for details on using BACKUP... PLUS ARCHIVELOG
.
Prior to Oracle Database Release 10g , however, you could manually determine which archived logs are required and back them up, using the following procedure.
To determine the archived logs needed for recovery of an online backup:
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
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
RMAN> BACKUP DATABASE;
RMAN> SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
V$LOG
to determine the log sequence number of the current redo log:
SQL> SELECT SEQUENCE# FROM V$LOG WHERE STATUS = 'CURRENT'; SEQUENCE# ---------- 9112
For example, issue the following to back up the necessary archived logs:
RMAN> BACKUP ARCHIVELOG FROM SEQUENCE 9100 UNTIL SEQUENCE 9111;
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;
A differential incremental backup contains only blocks that have been changed since the most recent backup at the same level or lower. The first incremental backup must be a level 0 backup that contains all used blocks. The following is a level 0 base backup:
RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;
An incremental backup at level 1 will contain all blocks changed since the most recent level 1 backup. If no previous level 1 backup is available, then RMAN copies all blocks changed since the base level 0 backup. The following is a level 1 backup of the database:
RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;
You can perform incremental backups in NOARCHIVELOG
mode, but the backups must be consistent. Hence, you cannot take online incremental backups.
A cumulative incremental backup at level 1 contains only blocks that have been changed since the most recent backup at level 0. Cumulative backups require more storage space than differential backups, but they are preferable during a restore operation because only one backup for a given level is needed. Note that the first incremental backup must be a level 0 backup that contains all used blocks.
In contrast to a cumulative backup, a differential backup at level 1 will determine which level 0 or level 1 backup occurred most recently and copy all blocks changed since this backup.
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE; # blocks changed since level 0
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; }
You cannot back up to DISK
and sbt
at the same time using automatic channels: you must manually allocate them.
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; # Now that the backup is complete, open the database. ALTER DATABASE OPEN;
You can skip tablespaces, but any skipped tablespace that has not been offline or read-only since its last backup will be lost if the database has to be restored from a backup. When backing up to disk, make sure that the destination file system has enough free space.
You can use operating system utilities to make copies of datafiles and then catalog them in the recovery catalog.
If the database is open and the datafile is online, then issue ALTER
TABLESPACE
...
BEGIN
BACKUP
to put the datafile in backup mode. (If you will be copying all datafiles, you can use ALTER DATABASE BEGIN BACKUP
to put all tablespaces in backup mode, instead of issuing individual commands for each tablespace.) Then copy the files using native operating system commands. Once the copy is completed, use ALTER TABLESPACE
... END BACKUP
to take the datafile out of backup mode (or use ALTER DATABASE END BACKUP
to take all tablespaces in backup mode out of backup mode). Finally, catalog the resulting datafile copy using the RMAN CATALOG DATAFILECOPY
command.
For example, if you created a copy of your datafile /oracle/oradata/users01.dbf into file /tmp/users01.dbf, this command will add /tmp/users01.dbf to the catalog:
CATALOG DATAFILECOPY '/tmp/users01.dbf';
If you try to catalog a datafile copy from a database other than the connected target database, then RMAN issues an error such as the following:
RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03009: failure of catalog command on default channel at 08/29/2001 14:44:34 ORA-19563: datafile copy header validation failed for file /tmp/tools01.dbf
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';
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;
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.
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.
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';
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;
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.
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; }