An Introduction To Rman With Examples
An Introduction To Rman With Examples
For beginners and non, rman is one of the most obscure Oracle tools, but in reality it is based on quite
simple principles. It is true, though, that a restoration can be distructive for a database.
Is WinZip dangerous?
The creation of a zip archive is not dangerous, unless you choose the same name for the output file, or the
archive is so big that you fill a device or the temporary directory etc. The same thing can be said about
rman: taking an rman backup cannot be dangerous (unless you stop the database, or close it intentionally)
and you don't overwrite previous backups (you can prevent it).
rman creates a compressed backup of the physical database files, including controlfiles, datafiles,
archived logs and stores them somewhere. This somewhere can be a disk (like WinZip) or a tape.
Therefore, the first important point to remember is:
rman creates compressed backups of the physical database; if you prefer, rman zips the database,
entirely or not.
Is Unzip dangerous?
Unzip, on the other hand, can be very dangerous. The risk is overwriting files that should not be
overwritten and, therefore, losing important content. The very same applies to rman restores: since they
overwrite database files, you should know whether this is the right decision because, otherwise, you may
lose your data. This is the main difference between an import and an rman restoration: an rman
restoration (restore) overwrites one or more datafiles; this means WATCH OUT.
The only requirements for taking simple, useful rman backups are two:
On our Windows 2000 workstation we open a CMD window and type the following few lines:
E:\>rman target /
run {
allocate channel t1 type disk;
backup database format 'E:\RMAN_BACKUPS\ARK9201\%d_%u_%s';
release channel t1;
}
using target database controlfile instead of recovery catalog
allocated channel: t1
channel t1: sid=9 devtype=DISK
Database altered.
SQL> alter database open;
Database altered.
Let's now repeat the operation having put the database in archive mode Choosing C:\Temp as directory
for the backup is, of course, a very bad idea. Backups are gold and shoud be kept on a dedicated device; a
good name could be E:\RMAN_BACKUPS\SID
E:\>rman target /
RMAN> run {
2> allocate channel t1 type disk;
3> backup database format 'E:\RMAN_BACKUPS\ARK9201\%d_%u_%s';
4> release channel t1;
5> }
allocated channel: t1
channel t1: sid=12 devtype=DISK
released channel: t1
The resulting backup file(s) are in our case
dir c:\rman_backups\ark9201
Volume in drive C is 80-01-14A2
Volume Serial Number is 64DA-0BF7
Directory of c:\rman_backups\ark9201
12/26/2004 02:29p .
12/26/2004 02:29p ..
12/26/2004 02:44p 418,471,936 ARK920_03G8KC6G_3
allocated channel: t1
channel t1: sid=12 devtype=DISK
Starting backup at 26-DEC-04
current log archived
channel t1: starting archive log backupset
channel t1: specifying archive log(s) in backup set
input archive log thread=1 sequence=77 recid=1 stamp=545945036
input archive log thread=1 sequence=78 recid=2 stamp=545945039
input archive log thread=1 sequence=79 recid=3 stamp=545945099
channel t1: starting piece 1 at 26-DEC-04
channel t1: finished piece 1 at 26-DEC-04
piece handle=C:\RMAN_BACKUPS\ARK9201\ARCH_ARK920_04G8KTGL_4 comment=NONE
channel t1: backup set complete, elapsed time: 00:00:37
channel t1: deleting archive log(s)
archive log filename=E:\ORA920\RDBMS\ARC00077.001 recid=1 stamp=545945036
archive log filename=E:\ORA920\RDBMS\ARC00078.001 recid=2 stamp=545945039
archive log filename=E:\ORA920\RDBMS\ARC00079.001 recid=3 stamp=545945099
Finished backup at 26-DEC-04
released channel: t1
RMAN>
rman on UNIX
rman works the same way on a UNIX server, using an appropriate directory format:
RMAN> run { allocate channel t1 type disk;
2> backup database format '/u01/oracle/archive/%d_%u_%s';
3> backup current controlfile format '/u01/oracle/archive/%d_%u_%s';
4> release channel t1;}
released channel: t1
RMAN> host ;
allocated channel: t1
channel t1: sid=26 devtype=DISK
released channel: t1
Here is a backup of archived log files
RMAN> run { allocate channel t1 type disk;
2> backup archivelog all format '/u01/oracle/archive/archive_%d_%u_%s' delete input;
3> release channel t1;}
allocated channel: t1
channel t1: sid=26 devtype=DISK
Starting backup at 14:42:00 18-jan-2005
current log archived
channel t1: starting archive log backupset
channel t1: specifying archive log(s) in backup set
input archive log thread=1 sequence=9 recid=1 stamp=547477014
input archive log thread=1 sequence=10 recid=2 stamp=547562627
input archive log thread=1 sequence=11 recid=3 stamp=547562680
input archive log thread=1 sequence=12 recid=4 stamp=547580133
input archive log thread=1 sequence=13 recid=5 stamp=547623518
input archive log thread=1 sequence=14 recid=6 stamp=547744760
input archive log thread=1 sequence=15 recid=7 stamp=547865707
input archive log thread=1 sequence=16 recid=8 stamp=547915324
channel t1: starting piece 1 at 14:42:08 18-jan-2005
channel t1: finished piece 1 at 14:43:03 18-jan-2005
piece handle=/u01/oracle/archive/archive_ORA920_06gah1hv_6 comment=NONE
channel t1: backup set complete, elapsed time: 00:00:56
channel t1: deleting archive log(s)
archive log filename=/optware/oracle/admin/ORA920/arch/ORA920_1_9.arc recid=1
stamp=547477014
archive log filename=/optware/oracle/admin/ORA920/arch/ORA920_1_10.arc recid=2
stamp=547562627
archive log filename=/optware/oracle/admin/ORA920/arch/ORA920_1_11.arc recid=3
stamp=547562680
archive log filename=/optware/oracle/admin/ORA920/arch/ORA920_1_12.arc recid=4
stamp=547580133
archive log filename=/optware/oracle/admin/ORA920/arch/ORA920_1_13.arc recid=5
stamp=547623518
archive log filename=/optware/oracle/admin/ORA920/arch/ORA920_1_14.arc recid=6
stamp=547744760
archive log filename=/optware/oracle/admin/ORA920/arch/ORA920_1_15.arc recid=7
stamp=547865707
archive log filename=/optware/oracle/admin/ORA920/arch/ORA920_1_16.arc recid=8
stamp=547915324
Finished backup at 14:43:04 18-jan-2005
Starting Control File Autobackup at 14:43:04 18-jan-2005
piece handle=/optware/oracle/9.2.0.1/dbs/c-2554142925-20050118-02 comment=NONE
Finished Control File Autobackup at 14:43:09 18-jan-2005
released channel: t1
RMAN>
allocated channel: t1
channel t1: sid=25 devtype=DISK
released channel: t1
Care is needed for rman restores because they will normally overwrite existing datafiles; before taking any action it is
imperative to understand why a restore is needed and how to proceed.
In our opinion it is better to explain basic rman concepts with understandable examples.
Example 1: a restoration is needed because a datafile is lost.
1. In order to restore a database or a data file some kind of backup must have been taken; in our exaple, let's suppose that our
database consists of three datafiles and that a backup is taken on Mar 10th 2005 in the afternoon.
">
The stand of the datafiles can differ because in general it is not guaranteed that the very last changes in the database have
actually been written to disk. This is why the timestamps 15:09 and 15:15 have been used in the picture.
2. During the week archive log backups are taken daily, for example to tape using the command:
run {
allocate channel t1 type 'sbt_tape';
backup archivelog all delete input;
release channel t1;
}
3. A week later a disk crashes and the database file number 3 is lost:
In this example, it must be understood that only the DBFile3 has to be restored, without overwriting the datafiles that have not
been affected by the crash, or a weeek's work would be lost.
The tablespace containing the damaged file should be put offline with the SQLPLUS command:
SQLPLUS / AS SYSDBA
ALTER TABLESPACE this_tbs OFFLINE IMMEDIATE;
It is now obvious that we have a mish-mash of contents, with tablespace up-to-date and a tablespace my_tbs with contents as
of one week before. In this situation, Oracle will refuse to bring the tablespace online, probably with the error message 'datafile
'DBFIle3' needs to be recovered'. How is it possible to bring the tablespace my_tbs at the same stand as for the other
tablespaces? It is possible because we have the archive logs backups, that contain all the changes to the database made
between Mar 10th and Mar 17th.
The command needed is:
run {
allocate channel t1 type 'sbt_tape';
recover database;
release channel t1;
}
During the execution of this command, rman will restore the archived redo logs and apply them to the damaged tablespace. At
the end of the process the tablespace can be brought online and the database is back to normal.
About DBA Queries DBA Scripts Quick Guides Nooleus Other Stuff Contact
Clone an Oracle database using RMAN duplicate (same server)
tnsManager - Distribute tnsnames the easy way and for free!
This procedure will clone a database onto the same server using RMAN duplicate.
This will backup the database and archive logs. The format string defines the location of the
backup files. Alter it to a suitable location.
The new pfile will need to be edited immediately. If the cloned database is to have a different
name to the source, this will need to be changed, as will any paths. Review the contents of the
file and make alterations as necessary.
Because in this example the cloned database will reside on the same machine as the source,
Copyright© 2007-2010 Andrew Barry
Full Backups A full backup reads the entire file and copies all blocks into the backup set, only skipping datafile blocks that have
never been used.
About Incremental Backups Rman create backup only changed block since a previous backup. You can use RMAN to create
incremental backups of datafiles, tablespaces, or the whole database.
How Incremental Backups Work
Each data block in a datafile contains a system change number (SCN), which is the SCN at which the most recent change was made to
the block. During an incremental backup, RMAN reads the SCN of each data block in the input file and compares it to the checkpoint
SCN of the parent incremental backup. RMAN reads the entire file every time whether or not the blocks have been used.
The parent backup is the backup that RMAN uses for comparing the SCNs. If the current incremental is a differential backup at level
n, then the parent is the most recent incremental of level n or less. If the current incremental is a cumulative backup at level n, then the
parent is the most recent incremental of level n-1 or less. If the SCN in the input data block is greater than or equal to the checkpoint
SCN of the parent, then RMAN copies the block.
Multilevel Incremental Backups
RMAN can create multilevel incremental backups. Each incremental level is denoted by an integer, for example, 0, 1, 2, and so forth.
A level 0 incremental backup, which is the base for subsequent incremental backups, copies all blocks containing data. The only
difference between a level 0 backup and a full backup is that a full backup is never included in an incremental strategy.
If no level 0 backup exists when you run a level 1 or higher backup, RMAN makes a level 0 backup automatically to serve as the base.
The benefit of performing multilevel incremental backups is that RMAN does not back up all blocks all of the time.
Differential Incremental Backups
In a differential level n incremental backup, RMAN backs up all blocks that have changed since the most recent backup at level n or
lower.
For example, in a differential level 2 backups, RMAN determines which level 2 or level 1 backup occurred most recently and backs up
all blocks modified after that backup. If no level 1 is available, RMAN copies all blocks changed since the base level 0 backup. If no
level 0 backup is available, RMAN makes a new base level 0 backup for this file.
Case 1: if you want to implement incremental backup strategy as a DBA in your organization:
Use Command for incremental Level Backup
RMAN> backup incremental level 0 database tag="SUNDAY";
RMAN> backup incremental level 3 database tag="MONDAY";
RMAN> backup incremental level 3 database tag="TUESDAY";
RMAN> backup incremental level 3 database tag="WEDNESDAY";
RMAN> backup incremental level 2 database tag="THURSDAY";
RMAN> backup incremental level 3 database tag="FRIDAY";
RMAN> backup incremental level 3 database tag="SATURDAY";
Backup Example ( You can view your incremental Backup Details by using following Query)
select incremental_level, incremental_change#, checkpoint_change#, blocks from v$backup_datafile;
Result of above Query:
INC_LEVEL INC_CHANGE# CHECKPOINT_CHANGE# BLOCKS
0 0 271365 59595
3 271365 271369 2
3 271369 271371 1
3 271371 271374 2
2 271365 271378 2
3 271378 271380 1
3 271380 271383 2
Cumulative Incremental Backups
RMAN provides an option to make cumulative incremental backups at level 1 or greater. In a cumulative level n backup, RMAN
backs up all the blocks used since the most recent backup at level n-1 or lower.
For example, in cumulative level 2 backups, RMAN determines which level 1 backup occurred most recently and copies all blocks
changed since that backup. If no level 1 backups is available, RMAN copies all blocks changed since the base level 0 backup.
Cumulative incremental backups reduce the work needed for a restore by ensuring that you only need one incremental backup from
any particular level. Cumulative backups require more space and time than differential backups, however, because they duplicate the
work done by previous backups at the same level.
Case 1: if you want to implement Cumulative backup strategy as a DBA in your organization:
Use Command for Cumulative Level Backup
backup incremental level=0 database tag='base';
backup incremental level=2 cumulative database tag='monday';
backup incremental level=2 cumulative database tag='tuesday';
backup incremental level=2 cumulative database tag='wednesday';
backup incremental level=2 cumulative database tag='thursday';
backup incremental level=2 cumulative database tag='friday';
backup incremental level=2 cumulative database tag='saturday';
backup incremental level=1 cumulative database tag='weekly';
Incremental backup implementation
RMAN will determine the incremental SCN for each datafile
Find the backup with highest checkpoint scn that