RMAN Backup Command

RMAN backups are performed using the BACKUP statement

To perforn a full database backup use:

RMAN> BACKUP DATABASE;

To backup all archive logs use:

RMAN> BACKUP ARCHIVELOG ALL;

To backup the database and all archive log files use:

RMAN> BACKUP DATABASE PLUS ARCHIVELOG;

Note that the PLUS ARCHIVELOG clause performs the following:

  1. Runs the ALTER SYSTEM ARCHIVE LOG CURRENT command
  2. Runs the BACKUP ARCHIVELOG ALL command. If backup optimization is enabled only backs up logs that have not already been backed up.
  3. Backs up files specified in the BACKUP command
  4. Runs the ALTER SYSTEM ARCHIVE LOG CURRENT command
  5. Backs up any remaining archived logs including those generated during the backup

A FORMAT can be specified for each subclause in the BACKUP DATABASE PLUS ARCHIVELOG command. For example:

RUN
{
  ALLOCATE CHANNEL ch11 TYPE DISK MAXPIECESIZE 10G;
  BACKUP
  FORMAT '/u03/app/oracle/TEST/%d_D_%T_%u_s%s_p%p'
  DATABASE
  PLUS ARCHIVELOG
  FORMAT '/u03/app/oracle/TEST/%d_A_%T_%u_s%s_p%p';
  RELEASE CHANNEL ch11;
}

Note that FORMAT clause precedes the DATABASE clause, but follows the PLUS ARCHIVELOG clause.

The BACKUP command can be extended to backup the current control file and the SPFILE.

For example:

RUN
{
  ALLOCATE CHANNEL ch11 TYPE DISK MAXPIECESIZE 10G;
  BACKUP
  FORMAT '/u03/app/oracle/TEST/%d_D_%T_%u_s%s_p%p'
  DATABASE
  CURRENT CONTROLFILE
  FORMAT '/u03/app/oracle/TEST/%d_C_%T_%u'
  SPFILE
  FORMAT '/u03/app/oracle/TEST/%d_S_%T_%u'
  PLUS ARCHIVELOG
  FORMAT '/u03/app/oracle/TEST/%d_A_%T_%u_s%s_p%p';
  RELEASE CHANNEL ch11;
}

Controlfile backups

The current controlfile can be automatically backed up by the BACKUP command by configuring the CONTROLFILE AUTOBACKUP parameters

To backup the current controlfile explicitly use:

RMAN> BACKUP CURRENT CONTROLFILE;

SPFILE backups

The SPFILE can be automatically backed up with the control file during database backups by configuring the CONTROLFILE AUTOBACKUP parameters

To backup up the SPFILE explicitly use:

RMAN> BACKUP SPFILE;

Datafile backups

To backup a specific data file use BACKUP DATAFILE. For example:

RMAN> BACKUP DATAFILE '/u01/app/oradata/TEST/users01.dbf';

Altermatively specify the data file number. For example:

RMAN> BACKUP DATAFILE 4;

The data file number can be obtained from V$DATAFILE. For example:

SQL> SELECT file#, name FROM v$datafile;

Tablespace Backups

To backup a tablespace use the BACKUP TABLESPACE command. For example:

RMAN> BACKUP TABLESPACE USERS;

Compressed Backups

To compress the backup use:

RMAN> BACKUP AS COMPRESSED BACKUPSET DATABASE;

The resulting compressed backup is around 20%-30% of the size of the uncompressed equivalent.

Format clause

The format clause allows the backup files to be directed to a specific location.

For example:

BACKUP FORMAT '/u01/app/oracle/backup/%U' DATABASE;

The above statement created the following files in /u01/app/oracle/backup:

[oracle@vm3]$ ls -l /u01/app/oracle/backup
total 1161280
-rw-r----- 1 oracle oinstall 1178050560 Aug 14 06:31 15qeibgs_1_1
-rw-r----- 1 oracle oinstall    9928704 Aug 14 06:31 16qeibld_1_1

Other formats can be specified. For example:

BACKUP FORMAT '/backup2/TEST/TEST_df_%t_s%s_p%p' DATABASE;

In the above example %t is the backup set timestamp, %s is the backup set number and %p is the piece number within the backup set.

Tags

A backup tag can optionally be specified with the BACKUP command.

For example:

BACKUP DATABASE TAG = 'Full_Backup';

The tag is reported by the LIST command.

If a tag is not specified then a system-generated tag is assigned.

Incremental Backups

By default backups are full (level 0). Backups can also be incremental (level 1).

Incremental backups can be:

Differential backups require less space. Cumulative backups are faster to restore

Differential backups are the default.

To run a diffential incremental backup use:

RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;

To run a cumulative incremental backup use:

RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;

Note that in order to take a level 1 backup, a level 0 backup must already exist.

A full backup using BACKUP DATABASE is not the same as a level 0 backup. - the LV column of the LIST BACKUP output is NULL after a full backup.

In order to take a level 0 backup use

RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;

To create an image copy of an entire database use:

RMAN> BACKUP AS COPY DATABASE;

To create an image copy of a specific datafile use:

RMAN> BACKUP AS COPY DATAFILE <file#>

For example:

RMAN> BACKUP AS COPY DATAFILE 4 FORMAT '/u01/app/oracle/copy/users01.dbf';

Alternatively specify the source file name. For example:

RMAN> BACKUP AS COPY DATAFILE '/u01/app/oradata/TEST/users01.dbf'
FORMAT '/u01/app/oracle/copy/users01.dbf';

Recovery Area

To backup the recovery area use:

RMAN> BACKUP RECOVERY AREA TO DESTINATION '/u02/app/oracle';

Note that a destination must be specified if the recovery area is being backed up to disk.