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.
Comments on this entry are closed.
Hi,
Very useful article for DBA
Thanks
Very Nice! Thanks.
Great stuff I can always use info like this.
Good article ! Thanks.
I hope to see others articles on the same usefull topic. 🙂
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?
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?
@Tasslehoff
RMAN can make consistent and inconsistent backup,incremental or full backup,backup of whole or portion of database.
Rman scenarios please
yes, more scenarios please espc. to disaster recovery
cheers all DBAs
Useful article.Thanks.
Hi,
is there any view to check the retention time of the existing back in the catalog?
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..
Hi, it is very useful for me.Thanx
Nice pls update more scenerios for practice please.
Very usefull information about RMAN.
Very usefull information about RMAN.
Super Thanks. Excellent article, please keep posting more and more 🙂
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).
Simple and very helpful…cheers…!!!
your tutorial help me a lot
can you cover the recovery process after backing up the database ??
thanks
Thanks for your tutorial. simple and useful.
thanks a lot
Thanks and useful content
Really useful:-)
it’s very nice tutorial.It will very helpfull for beginners and experienced
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?
It is very nice. Elaborated nicely each and every thing
Regards, J
very useful thank you.
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
@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.
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.
Hi friend,
if you have some more details about logical backup and physical backup please inform.
Very useful …more
Very Very useful
Really it was help full article, Specially for those have started their carrier recently in oracle DBA field.
Thanks..
many thanks…very useful
Very helpfull !Thanks 😀
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
really helpful thankxx mate…
Nice, accurate and concise, to the point. enjoyable reading.
Great job !!
Thank you. Still relevant and very useful.
Very useful and helpful artical
Thanks alot
thanks
Love your article so much!!! very useful for me…thank you!
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.
Excellent one
keep it up! keep sharing this kind of articles very useful…..
That’s awesome. I thank you …
Could you please provide me the steps to backup oracle 11g database and its objects on a windows 7 32 bit machine. Further i would like to keep it as a archive and day to day basis.
Very useful article on RMAN backup concepts with precise examples.. well done !!
Excellent..!!!
Useful
Good One..!