Getty Images/iStockphoto


Oracle RMAN tutorial: Get started with database backup

In this tutorial, find out how to use Oracle RMAN for different types of database backups and learn which commands admins must know to get the most out of the tool.

Oracle Recovery Manager is a built-in utility for backing up and recovering databases. RMAN is designed to perform integrity checks that are simply not possible with the user-managed method.

The utility works with third-party media management software and, unlike the user-managed method, RMAN enables users to create incremental backups. This Oracle RMAN tutorial takes you through the steps to create full database backups, compressed backups and incremental backups.

RMAN is a command-line tool, so there might be a bit of a learning curve. Even so, many of the commands closely resemble natural language, which makes the learning process easier.

Creating database backups

Not surprisingly, the command used to create an RMAN backup is BACKUP. To back up a full database, for example, you would use this command:


To back up the database and the corresponding archive logs, you would use the following:


The BACKUP command is far less limiting than these RMAN tutorial examples might lead you to believe, and it includes a wide variety of helpful options.

One such option is to use the TAG parameter. If you use RMAN to create backups on a regular basis, you will need a way to distinguish between the backups. This is where backup tags come into play.

If you use the LIST command to display a list of the current backups, each backup is assigned a tag. However, you can apply a custom tag to a backup instead of the system-generated tag.

The simplest way to create a backup is to use the BACKUP DATABASE; command. With that in mind, if I want to create a tag containing my name (Brien) as a way of showing that I was the one who created the backup, I would use this command:


Using the LIST command

As previously noted, it is relatively common to create multiple backups using RMAN. The LIST command allows you to see which backups have been created and are available for your use. At its simplest, you can type the following:


This command will show you all the backups that currently exist. Depending on what you have backed up, however, the list of backups could potentially be a bit overwhelming. Fortunately, there are some ways of narrowing down the list. If, for instance, you only want to see database backups then you would type this command:


Similarly, you could generate a list of the backups of a specific datafile by typing this command:


How to compress backups in RMAN

RMAN enables you to create compressed backups to reduce the amount of space consumed by the backup. The degree to which compression can shrink a backup varies widely depending on the data within the database, but it is common to achieve a reduction rate of 70% to 80%.

The command used to create a compressed backup is simple, but it's important to understand the concept of a backup set.

So far in this RMAN tutorial, there have been several examples of how to use the BACKUP command to create a backup. To be technically precise, however, what the BACKUP command creates is a backup set, which includes data from one or more data files, any archived redo logs, control files or server parameter files.

When you compress a backup, you are compressing the backup set. The command even mentions the backup set. If you want to run the BACKUP DATABASE; command, but want the resulting backup to be compressed, the command would be as follows:


Creating incremental backups

RMAN can also do incremental backups. However, this process might work a little differently than what you would expect, so we'll take a closer look at the process in this RMAN tutorial.

Incremental backups usually refer to a backup of everything that has changed since the last full backup. Even though the BACKUP DATABASE; command creates a full backup, the resulting backup is not compatible with incremental backups.

If you plan on making incremental backups, the full backup must be level 0. The level 0 backup is just another type of full backup, but one that can be used as the basis for incremental backups. You can create a level 0 backup by using this command:


Once a level 0 backup exists, you can create incremental backups, which are differential or cumulative. Differential backups are the default and created using a command that is almost identical to the one used to create a level 0 backup. The only difference is that you will need to create a level 1 backup instead. The command is as follows:


If you want the backup to be cumulative, then the command would be the following:


When you create an incremental backup, that backup is defined as a level 1 backup. A level 1 backup must have a parent backup, and that parent can be a level 0 backup or a previous level 1 backup.

Backup a database plus archive log

When backing up an Oracle database, it is usually a good idea to make sure that you are also backing up the archive log. The archive log is essentially a transaction history log that you can use when recovering a database.

To back up a database and an archive log, begin by making the archive log current by entering this command:


Next, you will need to make a backup of the archive log by using this command:


Now, you can back up your system using the BACKUP command. When this is complete, it's good practice to repeat the two previously mentioned commands to capture any transactions that have occurred while the backup was in progress.

Recovering a database

Recovering a database essentially involves three main steps, although additional steps might be necessary to prepare for the recovery. Additional steps might include ensuring that the backup is accessible to the right users, or configuring backup storage on the target database.

The first step is to restore the control file. However, you will only have to do this if no control file exists, such as would be the case if you were restoring a database to a new server. The commands used to restore the control file are as follows:

SET DBID <DBID number>;


RESTORE CONTROLFILE FROM "/backup/rman/<name>";


The second step in the process is to restore the database. This can be completed with a single command:


The final step in the process is to recover the database. At its simplest, this means entering the RECOVER DATABASE; command. However, you can use variations of this command to recover a specific table space or specific data files.

You can learn more about what RMAN backup commands can do by checking out the Oracle documentation. Comprehensive recovery instructions can be found on Oracle's website.

Dig Deeper on Data backup and recovery software

Disaster Recovery