Database Technologies‎ > ‎Oracle‎ > ‎

RMAN

RMAN its an utility (executable) provided by oracle located at <ORACLE_HOME>/BIN
directory, it is used to manage the backup,restore and recovery operations on Oracle
Databases.
 
We could have RMAN to operate in two different modes Catalog and Non Catalog
  
 
1) Non-Catalog           :  Here RMAN stores the backup related information in control files
                                   of the target database
 
2) Catalog                  : Here a separate database for rman is created to keep the information
                                   about the target database's, here you could store multiple database's
                                   entry inside the rman's database 
 
 
Note  :  Keyword target specifies the database on which operation such as BACKUP,
           RESTORE,RECOVERY are to be done
 
 
Let see the above two mode in action
 
Non-Catalog Mode :
 
Steps

1) set oracle_sid of the target database
2) execute the following rman nocatalog target "sys/<password>"
    OR rman nocatalog "sys/<password>@<target_db_service_name>
    Thats it !,  and you are connected to target database through RMAN
 

Catalog Mode

 
1)  Create a database purely for RMAN purposes, lets call it to be rman

2)  Create user with following privileges
      resource,connect,recover_catalog_owner lets call the user to be rmanuser

3)  Execute rman rmanuser/<password>@rman, and execute create catalog

4)  Set oracle_sid of the target database let it be philips

5)  execute the following rman catalog rman/rman@rman target sys/oracle

6)  Here you are connected to target database through rman

7)  Register the target database with the rman;s database through this command
      register database
 
 
 
  RMAN Configuration :
 
 To see the various RMAN configuration Parameters issue show all; at the RMAN
 command prompt.
 
 
RETENTION POLICY                             : When set to 3, atleast 3 backup of database is retained;
                                                             RMAN retains all the backups and copies of datafiles,control files
                                                             and archived redo log files that are need to recover the database to
                                                             a point in the last 3 days

BACKUP OPTIMIZATION                        : ON | OFF, when it is set to on and you issue backup when
                                                               there is already one backup taken it wont bother to take
                                                               another backup

DEFAULT TYPE                                     : DISK | SBT , whether to go on disk or tape (sequential backup tape)

CONTROLFILE AUTOBACKUP                : Whenever backup is taken control file and spfile are
                                                               automatically backed up

CONTROL FILE AUTO BACKUP FORMAT : Format of the backupset

DEVICE TYPE DISK PARALLELISM         : When set to 1 process is started for backup

BACKCUP COPIES                                  : Copy of datafiles same as os level copy

MAXSIZE                                                 : Limit cap on backupset

ENCRYPTION                                          : Encryption of backupset
 
 
 
 
 
 
Features :
 
1) We could have incremental backup,  i.e only the blocks that have been modified since last backup (For better performance we could enable block change tracking at database level "alter database enable block change tracking using file '/path/to/trackingfile';"
 
2) Keep tracks of your backups, list backup summary list all your backup
 
Channel Allocation
 
A channel represent  one stream of data  to a device type each Allocated Channel
establishes a connection from RMANto a target database instance, we need at least
one channel for every backup,copy,restore, or recover command
 
For backup to happen on disk , you have to specify device type disk, for backup to
happen on tape device, the type is SBT (Sequential Backup Tape)
 
Allocation multiple channels allows 'simultaneously to read and write multiple backupsets/copies.
Means each allocated channels works on seprate backupset.
 

Shell > SET ORACLE_SID=<SID>
Shell > RMAN TARGET /

RMAN>

CONFIGURE CONTROLFILE AUTOBACKUP ON;
run {
allocate channel t1 type disk;
backup
format 'S:\rmanbackup/DB%d_t%t_s%s_p%p' database;
BACKUP spfile format 's:\rmanbackup/spfile%d';
release channel t1;
allocate channel t2 device type disk format 'S:\rmanbackup/ARC%d_t%t_s%s_p%p';
BACKUP ARCHIVELOG ALL;
release channel t2;
}

To Backup particular Sequnce or archivelog;

RMAN> BACKUP ARCHIVELOG FROM LOGSEQ 93 UNTIL  LOGSEQ 97 TO DESTINATION 'Z:\';
 
 
To check the Status of backup i.e how much % completed
 
SELECT SID, SERIAL#, CONTEXT, SOFAR, TOTALWORK,
ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE"
FROM V$SESSION_LONGOPS
WHERE OPNAME LIKE 'RMAN%'
AND OPNAME NOT LIKE '%aggregate%'
AND TOTALWORK != 0
AND SOFAR <> TOTALWORK
;

The backup is now taken

Restoration

RUN
{
  SET NEWNAME FOR DATAFILE 1 TO 'E:\SAMSUNGDB\DATAFILE\SYSTEM.DBF';
  SET NEWNAME FOR DATAFILE 2 TO 'E:\SAMSUNGDB\DATAFILE\UNDO1.DBF';
  SET NEWNAME FOR DATAFILE 3 TO 'E:\SAMSUNGDB\DATAFILE\\SYSAUX.DBF';
    SQL "ALTER DATABASE RENAME FILE ''E:\PHILIPSDB\REDO\REDO01.LOG''
      TO ''E:\SAMSUNGDB\REDO\REDO01.LOG'' ";
  SQL "ALTER DATABASE RENAME FILE ''E:\PHILIPSDB\REDO\REDO02.LOG''
     TO ''E:\SAMSUNGDB\REDO\REDO02.LOG''";
  SQL "ALTER DATABASE RENAME FILE ''E:\PHILIPSDB\REDO\REDO03.LOG''
     TO ''E:\SAMSUNGDB\REDO\REDO03.LOG'' ";
  RESTORE DATABASE;
  SWITCH DATAFILE ALL;
  RECOVER DATABASE;
}


RMAN Backup Format

%d   =  Name of the Database
%p   =  Piece number in backup set
%s   =  Backup set number
%t    =  Time Stamp
%T    =  Just YYYYMMDD
%u    =  8-character name represent backup-set no and timestamps
%c    =  1 for single backup, 2 for duplex backup
%U    =  Short For  %u_%p_%c, rman uses %U by default.
%Y    =  YYYY


RMAN Configuration Parameters
>rman target /
>show all;


switch datafile all : Updates the control file to use the new names as mentioned in the
set newname command

obsolete, any backup outside the retention policy is obsolete
expired, showing in catalog but not in disk

Report schema.
show all;

retention policy :
to 1, atlease one backup
backup optimization :
on | off, no backup if taken earlier
parallelism =1, only one backup process
backupset | copy , copy as it is

backup
backup archivelog all tag='ddddg';
crosscheck : if available on disk
report : the datafile of target
list :  list the backed up catalog
list backup summary
catalog : register a backup set

rman>backup database plus archivelog
rman>list bakcup summary
rman>list copy                                         // To list every thing that has been backed up as copy
rman>list backup by file