The primary purpose of RMAN backups is to protect your data. If a media failure or disaster occurs, then you can restore your backups and recover lost changes.
You can back up all or part of your database with the BACKUP command from within the RMAN client.
You can back up the database by entering the following command at the RMAN prompt:
RMAN> BACKUP DATABASE;
RMAN uses the configured settings, the records of previous backups, and the control file record of the database structure to determine an efficient set of steps for the backup. RMAN then carries out these steps.
RMAN Backup Output
There are number of options for RMAN backup output files. RMAN determines the destination device, locations for backup output, and a backup tag automatically based on your configured environment and built-in RMAN defaults.
You can also provide arguments to BACKUP to override these defaults.
RMAN Backup to Disk or SBT
RMAN can output their backups to disk or tape device. As explained in "Configure RMAN Backup Device Type: Disk or SBT". You can override this default with the DEVICE TYPE clauses as you can see in following examples.
RMAN> BACKUP DATABASE DEVICE TYPE DISK; #Creates RMAN BACKUP to DISK
RMAN> BACKUP DATABASE DEVICE TYPE SBT; #Creates RMAN BACKUP to SBT(Tape device)
RMAN Backup Set or RMAN Image Copy
RMAN can create backups on disk as image copies or as backup sets. As explained in "Configure RMAN Backup Type: Backup Sets or Image Copies". You can override this default with the AS COPY or AS BACKUPSET clauses.
RMAN Backup as BACKUP SET
By default, RMAN creates backup sets rather than image copies. A backup set consists of one or more backup pieces. RMAN can store backup data in a logical structure called a backup set, which is the smallest unit of an RMAN backup. A backup set contains the data from one or more datafiles, archived redo logs, or control files or server parameter file.
Following example makes full database backup to configured device type as backup set.
RMAN> BACKUP AS BACKUPSET DATABASE;
RMAN BACKUP as image copy
If you specify BACKUP AS COPY, then RMAN copies each file as an image copy, which is a bit-for-bit copy of a database file created on disk. Image copies are not stored in an RMAN-specific format. Image copies are identical to copies created with operating system commands like cp on Linux or COPY on Windows. You can use RMAN to make image copies while the database is open.
Following example makes full database Backup to disk as image copy
RMAN> BACKUP AS COPY DEVICE TYPE DISK DATABASE;
Format for RMAN Backup output files
BACKUP DATABASE FORMAT "/disk1/backup_%U";
Tags for an RMAN Backup output files
RMAN attaches a character string called a tag to every backup it creates, as a way of identifying the backup. You can either accept the default tag or specify your own with the TAG parameter of the BACKUP command.
RMAN> BACKUP AS BACKUPSET COPIES 1 DATAFILE 7 TAG mondaybkp;
If you do not specify a tag , then RMAN assigns a default tag with the date and time. Tags are always stored in the RMAN repository in uppercase
RMAN Backup Compression
RMAN can create compressed backups. Following example creates full database backup as compressed backup sets.
RMAN> BACKUP AS COMPRESSED BACKUPSET DATABASE;
You can set binary compression for every backup as backupset by Configuring RMAN Backup Compression.
Making RMAN Backups / Datafile
BACKUP command is used to backup oracle database and datafiles. You can make backups as image copies or as backupsets. BACKUPSET is default if you do not specify.
Before issuing BACKUP command you need to perform following steps:
- Start RMAN and connect to a target database and a recovery catalog (if used). See: How to start and connect to RMAN
- Ensure the database is mounted or open.
Following are the some common backup operation you can perform using RMAN BACKUP command.
BackUp Whole Database with RMAN
Whole or full database backup can be performed by simpling issuing
BACKUP DATABASE command from the RMAN prompt.
RMAN> BACKUP DATABASE;
Backup Datafiles with RMAN
Individual datafiles can be backed up as easily as we can back up a tablespace. You can back up one or more datafile with the
BACKUP DATAFILE command.
The following example back up the OE_TRANS_06.DBF datafile to disk:
RMAN> BACKUP AS BACKUPSET DATAFILE '/U04/ORADATA/ORD/OE_TRANS_06.DBF';
Backup Tablespaces with RMAN
You might need to backup an individual tablespace in a database that is too large to backup all at once. You can back up one or more tablespaces with the
BACKUP DATAFILE command form the RMAN prompt.
The following example backs up the tools tablespaces to disk:
RMAN > BACKUP AS BACKUPSET TABLESPACE tools;
Backup Archivelog With RMAN
Archivelog are the key to media recovery. You should back them up regularly. To back up archived logs, use the
BACKUP ARCHIVELOG command form the RMAN prompt.
The following example backs up the database and all archived redo logs:
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
Backup Controlfile with RMAN
If the CONFIGURE CONTROLFILE AUTOBACKUP command is set to ON (by default it is OFF), then RMAN automatically backs up the control file and server parameter file after every backup and after database structural changes. A control file contains the record of physical structure of the DB and RMAN backup meta-data. A Control file backup enables RMAN to recover the database even if the current control file, recovery catalog, and server parameter file are lost.
The following example backs up the current control file to the default disk device:
RMAN> BACKUP AS COPY CURRENT CONTROLFILE;
The following example backs up tablespace users to tape and includes the current control file in the backup:
RMAN> BACKUP DEVICE TYPE sbt TABLESPACE users INCLUDE CURRENT CONTROLFILE;
Backup spfile with RMAN
Oracle spfile contains the parameters and settings about oracle database. These parameters and settings help the oracle program to know how to start, how much memory to allocate and where to put files related to oracle database.
RMAN automatically backs up the current server parameter file in certain cases as explained in RMAN controlfile autobackup. The
BACKUP SPFILE command backs up the parameter file explicitly.
The following example backs up the server parameter file to tape:
RMAN> BACKUP DEVICE TYPE sbt SPFILE;
RMAN Incremental Backup
RMAN can take incremental backups in which only modified blocks are backed up. Incremental backups provide more compact backups and faster recovery.
BACKUP INCREMENTAL command is used to perform incremental backups.
The starting point for an incremental backup strategy is a level 0 incremental backup, which backs up all blocks in the database. An incremental backup at level 0 is identical in content to a full backup, however, unlike a full backup the level 0 backup is considered a part of the incremental backup strategy.
A level 1 incremental backup contains only blocks changed after a previous incremental backup. If no level 0 backup exists in either the current or parent database incarnation when you run a level 1 backup, then RMAN makes a level 0 backup automatically.
A level 1 backup can be a cumulative incremental backup, which includes all blocks changed since the most recent level 0 backup, or a differential incremental backup, which includes only blocks changed since the most recent incremental backup. Incremental backups are differential by default.
- Start RMAN and connect to a target database.
- Run the BACKUP INCREMENTAL command.
The following example creates a level 0 incremental backup to serve as a base for an incremental backup strategy:
BACKUP INCREMENTAL LEVEL 0 DATABASE;
The following example creates a level 1 cumulative incremental backup:
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
The following example creates a level 1 differential incremental backup:
BACKUP INCREMENTAL LEVEL 1 DATABASE;
To improve the performance of incremental backups block change tracking file can be enable. For a traditional incremental backup, RMAN inspect every block of the tablespace or datafile to see what block has been changed since the last backup.
By enabling block change tracking, RMAN knows which blocks have changed by using a change tracking file. Block change tracking is disabled by default how to enable block change tracking file is explained in RMAN Incremental Backup Block Change Tracking