≡ Menu

How to Backup Oracle Database using RMAN (with Examples)

Even if you are not an Oracle DBA, you’ll still encounter a situation where you may have to take a backup of an Oracle database.

Using Oracle RMAN, you can take a hot backup for your database, which will take a consistent backup even when your DB is up and running.

This tutorial gives you an introduction on how to perform Oracle DB backup using RMAN.

For the impatient, here is the quick snippet, that takes RMAN backup of both database and archive logs.

RMAN> BACKUP AS BACKUPSET DATABASE PLUS ARCHIVELOG;

1. View Current RMAN Configuration

Before we take the backup, we have to configure certain RMAN parameters. For example, how long you want to reatain the RMAN backup, etc.

Before we modify any configuration, execute the following command to view all current RMAN configuration settings.

To connect to RMAN, do the following from command line. This will take you to RMAN> command prompt, from here you can execute all RMAN commands.

$ rman target /
Recovery Manager: Release 10.2.0.3.0 - Production on Sat Aug 10 11:21:29 2013
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: DEVDB (DBID=821773)
RMAN>

To view current RMAN configurations, execute “show all”.

RMAN> SHOW ALL;
using target database control file instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "/backup/rman/ctl_%F";
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 2;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   "/backup/rman/full_%u_%s_%p" MAXPIECESIZE 2048 M;
CONFIGURE MAXSETSIZE TO UNLIMITED;
CONFIGURE ENCRYPTION FOR DATABASE OFF;
CONFIGURE ENCRYPTION ALGORITHM 'AES128';
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/10.2.0/dbs/snapcf_devdb.f'; # default

As you see above, it displays various RMAN parameters and their current values.

2. Change Few RMAN Configuration Parameters

Location: One of the important configuration parameters to set will be, where you want to save the RMAN backup. In the following example, I’m settting the RMAN backup loacation as “/backup/rman/”

RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/backup/rman/full_%u_%s_%p';

Retention Period: Next, you should specify how long you want to retain the backup for. When RMAN takes a backup, it automatically deletes all the old backups that are older than the retention period. In the following example, I’m setting the retention period as 7 days, which will keep the DB backup for a week.

RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

Verify that the above two changes are done.

RMAN> SHOW ALL;
..
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/backup/rman/full_%u_%s_%p';
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
..

Clear a Parameter: If you want to clear a parameter and set its value to default, use CLEAR at the end of the configuration as shown below.

RMAN> CONFIGURE RETENTION POLICY CLEAR;

In this example, since we cleared the retention policy’s value, it was set to the default value, which is 1. So, the retention policy is set to 1 day as shown below.

RMAN> SHOW ALL;
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default

3. Backup Oracle Database

Make sure the directory mentioned in the CHANNEK DEVICE TYPE DISK FORMAT is created. i.e /backup/rman/

$ mkdir -p /backup/rman

Currently this directory is empty. We’ll see what this has after the backup is taken.

$ ls -l /backup/rman
total 0

We can take a backup using image copy or in backup set. It is strongly recommended to use RMAN backup sets to backup the database.

RMAN stores the backup in backup sets, which are nothing but whole bunch of files which contains the backed-up data. Only RMAN understands the format of these files. So, if you backup an Oracle DB using RMAN, only RMAN knows how to read the backup and restore it.

Typically we’ll use “BACKUP AS BACKUPSET” to backup a database. So, to take a full backup of the database without the archive logs, do the following.

RMAN> BACKUP AS BACKUPSET DATABASE

To take a full backup of the database with the archive logs, do the following:

RMAN> BACKUP AS BACKUPSET DATABASE PLUS ARCHIVELOG;

You can also take a backup of only a specific table space. The following example takes backup of only PRD01 tablespace.

RMAN> BACKUP AS BACKUPSET TABLESPACE PRD01;

The RMAN backup output will be something similar to the following:

RMAN> BACKUP AS BACKUPSET DATABASE
Starting backup at 10-AUG-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=193 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=192 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00025 name=/u03/oradata/devdb/devuser07.dbf
input datafile fno=00003 name=/u02/oradata/devdb/temp01.dbf
channel ORA_DISK_1: starting piece 1 at 10-AUG-13
channel ORA_DISK_2: starting full datafile backupset
channel ORA_DISK_2: specifying datafile(s) in backupset
input datafile fno=00008 name=/u03/oradata/devdb/devusers05.dbf
channel ORA_DISK_2: starting piece 1 at 10-AUG-13
...
..

piece handle=/backup/rman/full_4dogpd0u_4237_1 tag=TAG20130808T114846 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 10-AUG-13
...
Starting Control File and SPFILE Autobackup at 10-AUG-13
piece handle=/backup/rman/ctl_c-758818131-20130808-00 comment=NONE
Finished Control File and SPFILE Autobackup at 10-AUG-13

Once the backup is completed, do an ls on the /backup/rman directory, you’ll now see RMAN backup files.

$ ls -l /backup/rman
total 14588
-rw-r----- 1 oracle dba 14585856 Aug  8 11:48 ctl_c-758818131-20130808-00
-rw-r----- 1 oracle dba   327680 Aug  8 11:48 full_4dogpd0u_4237_1

Note: Once a backup is taken, to view all available database backups from RMAN, you need to use “list” command that is shown further down in one of the examples.

While this may be obvious, it is worth repeating again: Since we are taking hotbackup, the Oracle database can be up and running. Make sure your Oracle database is running before you execute any of the above RMAN backup commands.

4. Assign Backup TAG Name for Quick Identification

If you are taking lot of backups, it will be easier to assign a tag to a particular backup, which we’ll later use during Oracle recovery (or while using list command to view it).

The following example assign a backup tag called “WEEEKLY_PRD01_TBLS_BK_ONLY” to this particular backup.

RMAN> BACKUP AS BACKUPSET TAG 'WEEEKLY_PRD01_TBLS_BK_ONLY' TABLESPACE PRD01;
Starting backup at 10-AUG-13
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00002 name=/u03/oradata/devdb/PRD01_1.dbf
channel ORA_DISK_1: starting piece 1 at 10-AUG-13
channel ORA_DISK_1: finished piece 1 at 10-AUG-13
piece handle=/backup/rman/full_4fogpdb3_4239_1 tag=WEEEKLY_PRD01_TBLS_BK_ONLY comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-AUG-13
Starting Control File and SPFILE Autobackup at 10-AUG-13
piece handle=/backup/rman/ctl_c-758818131-20130808-01 comment=NONE
Finished Control File and SPFILE Autobackup at 10-AUG-13

Once the backup is finished, if you view the files from rman directory, you’ll not see the tag name here. Tag name is used only from RMAN repositories to view and restore backups. So, now you see there are more files in this directory, as we’ve taken couple of backups.

$ ls -l /backup/rman/
total 29176
-rw-r----- 1 oracle dba 14585856 Aug  8 11:48 ctl_c-758818131-20130808-00
-rw-r----- 1 oracle dba 14585856 Aug  8 11:54 ctl_c-758818131-20130808-01
-rw-r----- 1 oracle dba   327680 Aug  8 11:48 full_4dogpd0u_4237_1
-rw-r----- 1 oracle dba   327680 Aug  8 11:54 full_4fogpdb3_4239_1

5. Change Oracle RMAN Backup File Name Format

If you want the backup files itself will be in a specific format, you need to change the format in the RMAN configuration as shown below. In this example, we’ve appended the tag “full_devdb_bk_” prefix to all our backup files.

RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   "/backup/rman/full_devdb_bk_%u_%s_%p" MAXPIECESIZE 2048 M;

Now, let us take another backup with this modified configuration.

RMAN> BACKUP AS BACKUPSET TAG 'WEEEKLY_PRD01_TBLS_BK_ONLY' TABLESPACE PRD01;

Now when you view the RMAN files, you’ll see the new RMAN backup file has this new file name format for the files. This is easier to identify certain information about the backup just by looking at the file names.

$ ls -l /backup/rman/
total 43764
-rw-r----- 1 oracle dba 14585856 Aug  8 11:48 ctl_c-758818131-20130808-00
-rw-r----- 1 oracle dba 14585856 Aug  8 11:54 ctl_c-758818131-20130808-01
-rw-r----- 1 oracle dba 14585856 Aug  8 11:56 ctl_c-758818131-20130808-02
-rw-r----- 1 oracle dba   327680 Aug  8 11:48 full_4dogpd0u_4237_1
-rw-r----- 1 oracle dba   327680 Aug  8 11:54 full_4fogpdb3_4239_1
-rw-r----- 1 oracle dba   327680 Aug  8 11:55 full_devdb_bk_4hogpdef_4241_1

6. Compress a RMAN Backup

If you are taking a backup of a big database, you’ll notice that the RMAN backup files are bigger (almost same size as the database itself).

So, for most situation, you should always tak ea compressed backup of the database.

The following example take a compressed backup of the tablepsace PRD01.

RMAN> BACKUP AS COMPRESSED BACKUPSET TAG 'WEEEKLY_PRD01_TBLS_BK_ONLY' TABLESPACE PRD01;

When you view the backup files from the file system level, you will not see any .gz (or .zip, or .bz2) to indicate that the RMAN has taken a compressed backup. The file naming convention will still follow the same as a non-compressed backup.

$ ls -l /backup/rman/
total 58352
-rw-r----- 1 oracle dba 14585856 Aug  8 11:48 ctl_c-758818131-20130808-00
-rw-r----- 1 oracle dba 14585856 Aug  8 11:54 ctl_c-758818131-20130808-01
-rw-r----- 1 oracle dba 14585856 Aug  8 11:56 ctl_c-758818131-20130808-02
-rw-r----- 1 oracle dba 14585856 Aug  8 11:59 ctl_c-758818131-20130808-03
-rw-r----- 1 oracle dba   327680 Aug  8 11:48 full_4dogpd0u_4237_1
-rw-r----- 1 oracle dba   327680 Aug  8 11:54 full_4fogpdb3_4239_1
-rw-r----- 1 oracle dba   327680 Aug  8 11:55 full_devdb_bk_4hogpdef_4241_1
-rw-r----- 1 oracle dba   127680 Aug  8 11:59 full_devdb_bk_4jogpdl0_4243_1

Note: The way to tell whether RMAN has take a compressed backup or not, it by looking at the size, and by looking at the output of the RMAN “list” command which is shown in one of the section below.

7. View all RMAN Backups

To view all the RMAN backups, execute “list backup summary” as shown below.

RMAN> LIST BACKUP SUMMARY;

using target database control file instead of recovery catalog

List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
..
4215    B  F  A DISK        10-AUG-13       1       1       NO         TAG20130808T114846
4216    B  F  A DISK        10-AUG-13       1       1       NO         TAG20130808T114849
4217    B  F  A DISK        10-AUG-13       1       1       NO         WEEEKLY_PRD01_TBLS_BK_ONLY
4218    B  F  A DISK        10-AUG-13       1       1       NO         TAG20130808T115413
4219    B  F  A DISK        10-AUG-13       1       1       NO         WEEEKLY_PRD01_TBLS_BK_ONLY
4220    B  F  A DISK        10-AUG-13       1       1       NO         TAG20130808T115600
4221    B  F  A DISK        10-AUG-13       1       1       YES        WEEEKLY_PRD01_TBLS_BK_ONLY

As you see above, it displays various information about the backups. In the above output, it show 7 RMAN backups. The last column shows the “Tag” that we specified when we took a backup. If we didn’t specify any TAG, RMAN creates a default tag with the prefix “TAG” followed by some numbers. You can also see that under the column “Compressed”, the last RMAN backup shows “YES”, which indicates that out of all the 7 RMAN backups, only the last one was compressed.

Also, when the RMAN backup is running, if you want to see the proress, you can query the V$RMAN_STATUS table from sql*plus as shown below.

SQL> SELECT OPERATION, STATUS, MBYTES_PROCESSED, START_TIME, END_TIME from V$RMAN_STATUS;

OPERATION                         STATUS                  MBYTES_PROCESSED START_TIM END_TIME
--------------------------------- ----------------------- ---------------- --------- ---------
CONTROL FILE AND SPFILE AUTOBACK  COMPLETED                             14 07-NOV-12 07-NOV-12
RMAN                              COMPLETED                              0 07-NOV-12 07-NOV-12
RESTORE VALIDATE                  COMPLETED                              0 07-NOV-12 07-NOV-12
RMAN                              COMPLETED WITH ERRORS                  0 07-NOV-12 07-NOV-12
DELETE                            COMPLETED                              0 08-NOV-12 08-NOV-12
BACKUP                            COMPLETED                              0 10-AUG-13 10-AUG-13
CONTROL FILE AND SPFILE AUTOBACK  COMPLETED                             14 10-AUG-13 10-AUG-13
RMAN                              COMPLETED WITH ERRORS               1832 10-AUG-13 10-AUG-13
RMAN                              COMPLETED                              0 10-AUG-13 10-AUG-13
...

There you have it!. That is how you take an Oracle RMAN backup and sleep peacefully.

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 50 comments… add one }

  • Jalal Hajigholamali August 27, 2013, 8:49 am

    Hi,

    Very useful article for DBA

    Thanks

  • Selvam August 27, 2013, 9:23 am

    Very Nice! Thanks.

  • A.Baines August 27, 2013, 11:39 am

    Great stuff I can always use info like this.

  • Astorre August 28, 2013, 1:49 am

    Good article ! Thanks.
    I hope to see others articles on the same usefull topic. :)

  • dudex00F August 30, 2013, 2:00 am

    thanks for the hints, however RMAN backup seems to be working only when an Oracle instance is up, thus can it be used against disaster recovery?

    will you cover RMAN process?

  • Tasslehoff September 2, 2013, 6:56 am

    Great post, very useful!
    Do you think to cover also the restore procedure with RMAN?

    One more question, if I remember RMAN backup is possibile only if the Oracle database is running in archive mode, is it right?

  • Mahfuz September 9, 2013, 11:40 am

    @Tasslehoff
    RMAN can make consistent and inconsistent backup,incremental or full backup,backup of whole or portion of database.

  • Anonymous October 28, 2013, 11:38 am

    Rman scenarios please

  • Tomas Kirsten November 14, 2013, 1:50 am

    yes, more scenarios please espc. to disaster recovery
    cheers all DBAs

  • Delwar November 19, 2013, 4:55 am

    Useful article.Thanks.

  • shanmugam January 21, 2014, 6:33 am

    Hi,
    is there any view to check the retention time of the existing back in the catalog?

  • Naveen Sunkari February 4, 2014, 10:18 pm

    Hi

    Very usefull i am working on Netbackup in IBM and in my present environment we dont have RMAN backups, but i am interested to know about this. i am new and fresh to this concept, now i got clear idea on Data base backups. its very usefull information for all those who are new to RMAN backups.

    Thank you so much for sharing..

  • Bijayalaxmi Behera March 4, 2014, 10:59 pm

    Hi, it is very useful for me.Thanx

  • prasad May 19, 2014, 8:39 am

    Nice pls update more scenerios for practice please.

  • Rezaul June 6, 2014, 3:21 pm

    Very usefull information about RMAN.

  • Anonymous June 12, 2014, 4:32 am

    Very usefull information about RMAN.

  • Manoj June 19, 2014, 12:56 pm

    Super Thanks. Excellent article, please keep posting more and more :-)

  • abhishek July 14, 2014, 2:56 am

    very impressive article….would you please more elaborate this topic..how to recover RMAN backup…or some other topic ie: migrate oracle DB from Linux(R.H.E.L) to UNIX(A.I.X).

  • Vishan July 15, 2014, 12:08 am

    Simple and very helpful…cheers…!!!

  • manfred August 17, 2014, 8:01 am

    your tutorial help me a lot
    can you cover the recovery process after backing up the database ??

    thanks

  • cithu August 24, 2014, 7:37 am

    Thanks for your tutorial. simple and useful.

  • sundar September 9, 2014, 2:02 am

    thanks a lot

  • Raj September 15, 2014, 10:03 pm

    Thanks and useful content

  • Shalini Singh October 5, 2014, 12:44 am

    Really useful:-)

  • ramana October 17, 2014, 2:39 pm

    it’s very nice tutorial.It will very helpfull for beginners and experienced

  • Dave Bowers October 30, 2014, 10:54 am

    I am trying to do a database backup to disk and I am using the instruction in this post but I continue to have the following error message:
    RMAN-03009: failure of backup command on ORA_DISK_1 channel at 10/30/2014 11:46:29
    ORA-07217: sltln: environment variable cannot be evaluated.

    I have added the suggested parameters to RMAN.

    I have ORACLE_SID and ORACLE_HOME set.

    What variable am I missing?

  • Junaid November 11, 2014, 1:16 am

    It is very nice. Elaborated nicely each and every thing
    Regards, J

  • Orcl November 14, 2014, 5:13 pm

    very useful thank you.

  • Anthony December 5, 2014, 6:57 am

    Hi,
    Thx for the post I am trying this on the test instance I am getting the following errror

    BACKUP AS BACKUPSET DATABASE PLUS ARCHIVELOG;

    Starting backup at 05-DEC-14
    ORACLE error from target database:
    ORA-00258: manual archiving in NOARCHIVELOG mode must identify log

    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=2860 device type=DISK
    specification does not match any archived log in the recovery catalog
    backup cancelled because all files were skipped
    Finished backup at 05-DEC-14

    Starting backup at 05-DEC-14
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting full datafile backup set
    channel ORA_DISK_1: specifying datafile(s) in backup set
    RMAN-03009: failure of backup command on ORA_DISK_1 channel at 12/05/2014 21:01:49
    ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
    continuing other job steps, job failed will not be re-run
    channel ORA_DISK_1: starting full datafile backup set
    channel ORA_DISK_1: specifying datafile(s) in backup set
    including current control file in backup set
    channel ORA_DISK_1: starting piece 1 at 05-DEC-14
    channel ORA_DISK_1: finished piece 1 at 05-DEC-14
    piece handle=/mnt/anthony/rman/full_08ppea9t_8_1 tag=TAG20141205T210148 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of backup plus archivelog command at 12/05/2014 21:01:52

    RMAN-03009: failure of backup command on ORA_DISK_1 channel at 12/05/2014 21:01:49
    ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode

  • Tasslehoff December 5, 2014, 4:50 pm

    @Anthony
    It’s normal, you can use rman only if the database is working in archive log mode.
    Connect to your db as sysdba with a client (sqlplus or sql developer or any other) and lauch “archive log list”.
    It will return some information, “Database log mode” will tell you if your database works in archive log mode or no archive log.
    Probably yours will work in no archive log, you can change it but you must create a directory for archivelogs and tell the database to use that directory.

  • Charles Martel March 9, 2015, 3:52 pm

    This was the best documentation on Rman to be found on the web. It’s far more concise and useful than anything that I saw on the Oracle sites. Oracle – if you read this- please take note of the practical nature of this man’s work.
    Mr NATARAJAN – THANK YOU ! You have saved my week and perhaps my whole work with Oracle.

  • Rahul March 18, 2015, 5:39 am

    Hi friend,
    if you have some more details about logical backup and physical backup please inform.

  • Abdul Hamed June 5, 2015, 2:18 pm

    Very useful …more

  • Alok July 3, 2015, 1:02 am

    Very Very useful

  • Antim July 15, 2015, 5:16 am

    Really it was help full article, Specially for those have started their carrier recently in oracle DBA field.

  • PC July 30, 2015, 12:33 am

    Thanks..

  • laxmi August 1, 2015, 1:34 am

    many thanks…very useful

  • Lorena August 4, 2015, 6:42 am

    Very helpfull !Thanks 😀

  • tpen August 28, 2015, 11:02 am

    It is nice article on RMAN, and most of people getting the error, they should make sure that RMAN is achivelog enable mode, before they can use RMAN for fully backup

  • Chathuranga September 26, 2015, 7:34 am

    really helpful thankxx mate…

  • Nos October 2, 2015, 8:33 am

    Nice, accurate and concise, to the point. enjoyable reading.
    Great job !!

  • Nelson November 11, 2015, 10:57 am

    Thank you. Still relevant and very useful.

  • Waseem November 30, 2015, 4:57 am

    Very useful and helpful artical

  • GIANGTD December 23, 2015, 3:48 am

    Thanks alot

  • hamma March 8, 2016, 9:09 am

    thanks

  • hoanguyentvn March 28, 2016, 3:51 am

    Love your article so much!!! very useful for me…thank you!

  • Krishna April 1, 2016, 12:11 am

    Thanks for this article on backup and RMAN in Database. This gives a basic understanding how backup are done at DB level for non-DBA support team even though we depend on DB.

  • Sam April 6, 2016, 8:19 pm

    Excellent one

  • ali May 18, 2016, 3:05 am

    keep it up! keep sharing this kind of articles very useful…..

  • Lamine May 29, 2016, 1:30 pm

    That’s awesome. I thank you …

Leave a Comment