RMAN examples


WHAT IS RMAN
Recovery Manager (RMAN) is an Oracle tool that allows you to back up, copy, restore, and recover datafiles, control files, and archived redo logs. You can invoke RMAN as a command line utility from the O/S prompt or use the GUI-based Enterprise Manager Backup Manager.

HOW RMAN WORKS
• The RMAN user session starts on the client.
• RMAN creates two default server sessions that connect to the target database. The target database is the database that you want to back up or restore.
• If you perform I/O on disk or tape, RMAN requires that you allocate one channel for each disk or device. A channel corresponds to a server session.
• If you connect to a recovery catalog, RMAN creates a server session on the recovery catalog database.
• When you use RMAN to connect to your target database, RMAN uses server sessions to perform the backup and recovery operations through a PL/SQL interface. RMAN physically stores its backups and copies on disk or, if you use media management software, on tape.
To use media management software, such as Netbackup, you need to link libobk.so to the netbackup’s libobk.so in the ORACLE_HOME/lib directory and prior to running the backup, the BACKUP variables specifying BACKUP_CLASS, MEDIA SERVER, and TAPE LIBRARY need to be set.

RMAN CATALOG:
RMAN stores metadata about its backup and recovery operations in the recovery catalog, which is a centralized repository of information, or exclusively in the control file. Typically, the recovery catalog is stored in a separate database. If you do not use a recovery catalog, RMAN uses the control file as its repository of metadata.

CONCEPT OF CHANNELS:
Paralellism:
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;

Channel limitations:
Specify limits on I/O bandwidth consumption (set limit channel ... readrate).
Specify limits on the size of backup pieces (set limit channel ... kbytes).
Specify limits on the number of concurrently open files (set limit channel ...
maxopenfiles).

Non interactive mode:
man target / catalog rman/rman@rcat @b_whole_l0.rcv log rman_log.f
or
rman @mike.rcv log mike.out
in this case you will need to specify connection within the mike.rcv command file

 

TYPES OF BACKUP:

Backup Type  

Definition  

Full

A backup that is non-incremental, i.e., it backs up all used data blocks in the datafiles.
Note: A full backup is different from a whole database backup, which is a backup of all datafiles and the current control file.

Incremental  

A backup of datafiles that includes only the blocks that have changed since a previous incremental backup. Incremental backups require an incremental level 0 backup to serve as a basis. Full backups cannot be included in an incremental strategy, although an RMAN copy made with the level parameter can be included

On-line

A backup of any part of the target database when it is open.
Note: Do not put a tablespace in hot backup mode with the ALTER TABLESPACE BEGIN BACKUP statement. RMAN uses a different method to guarantee consistency in hot backups.  

Off line

A backup of any part of the target database when it is mounted but not open. Closed backups can be consistent or inconsistent. Note: If you use a recovery catalog, the catalog database must be open.

Consistent  

A backup taken when the database is mounted (but not open) and was not crashed or shut down with the ABORT option prior to mounting. The checkpoint SCNs in the datafile headers match the header information in the control file and none of the datafiles has changes beyond its checkpoint. Consistent backups can be restored without recovery.  

Inconsistent  

A backup of any part of the target database when:

  • It is open.
  • It crashed prior to mounting.
  • It was shut down with the ABORT option prior to mounting.

An inconsistent backup requires recovery to become consistent.  In other words, database needs to be recovered after the restore, using archive logs


RMAN EXAMPLES:
Database backup:
run
{
allocate channel d1 type DISK format '/backupdir/%d_rman_full_%t_%s_%p.rman ';
setlimit channel d1 kbytes 4000000 maxopenfiles 8 ;
allocate channel d2 type DISK format '/backupdir/%d_rman_full_%t_%s_%p.rman ';
setlimit channel d2 kbytes 4000000 maxopenfiles 8 ;
allocate channel d3 type DISK format '/backupdir/%d_rman_full_%t_%s_%p.rman ';
setlimit channel d3 kbytes 4000000 maxopenfiles 8 ;
allocate channel d4 type DISK format '/backupdir/%d_rman_full_%t_%s_%p.rman ';
setlimit channel d4 kbytes 4000000 maxopenfiles 8 ;

change archivelog all validate;
backup database include current controlfile
filesperset 8
tag = rman_daily_backup;
release channel d1 ;
release channel d2 ;
release channel d3 ;
release channel d4 ;
sql 'alter system switch logfile';
sql 'alter system switch logfile';
sql 'alter system switch logfile';
sql 'alter system switch logfile';
sql 'alter system switch logfile';
sql 'alter system switch logfile';
sql 'alter system switch logfile';
sql 'alter system switch logfile';
allocate channel d1 type disk format ' /backupdir/%d_rman_arch_%t_%s_%p.rman ';
setlimit channel d1 kbytes 4000000 maxopenfiles 8 ;
backup archivelog all;
release channel d1 ;
allocate channel d1 type DISK format '/ backupdir/%d_rman_ctl_%t_%s_%p.rman ';
backup current controlfile;
release channel d1 ;
}

Datafile Restore:
connect target;
run {
resync catalog;
allocate channel t1 type 'SBT_TAPE';
setlimit channel t1 kbytes 2097150 maxopenfiles 32;
restore datafile <file#>;
recover datafile <file#>;
sql 'alter database datafile <file#> online';
release channel t1;
}

Database Restore:
When you restore the database you can also change the location of the datafiles using the set newname clause:
connect target /
run{
set until time '27-OCT-2004 14:00:00';
allocate channel ch1 type disk;
allocate channel ch2 type disk;
allocate channel ch3 type disk;
allocate channel ch4 type disk;
allocate channel ch5 type disk;
allocate channel ch6 type disk;
allocate channel ch7 type disk;
set newname for datafile '/fap/db/ORFAPP/data/idx02/usr_idx32m_02.dbf' to '/fap/db/ORFAPP/data/idx07/usr_idx32m_02.dbf';
restore database;
sql 'alter database rename file "/fap/db/ORFAPP/data/idx02/usr_idx32m_02.dbf" to "/fap/db/ORFAPP/data/idx07/usr_idx32m_02.dbf"';
recover database;
}

Database Duplication:
In the duplication process, the connectivity to the new database being created needs to be done via tns names, and the new database has to be started up in the no mount mode. There is a metalink document specifically for the database duplication: 73912.1.
The backup directory of the source server must be net mounted to the target server.

Prior to duplicating the database, the following 3 shell variables need to be set:
export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
export NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS'
export TNS_ADMIN=/opt/oracle/adm/rman

RMAN command file example:
connect target /;
connect catalog rman10g/rman10g_81@OREMGRP1;
connect auxiliary sys/XXXXXX@ORTSTXX ;
run{
set until time '02-APR-2006 21:36:54';
allocate auxiliary channel ch1 type disk;
allocate auxiliary channel ch2 type disk;
allocate auxiliary channel ch3 type disk;
set newname for datafile 1 to '/tsg/db/ORTSTXX/data/dat01/system_01.dbf';
set newname for datafile 2 to '/tsg/db/ORTSTXX/data/rbs01/undotbs_01.dbf';
set newname for datafile 3 to '/tsg/db/ORTSTXX/data/dat01/sysaux_01.dbf';
set newname for datafile 4 to '/tsg/db/ORTSTXX/data/dat01/dat_01.dbf';
set newname for datafile 5 to '/tsg/db/ORTSTXX/data/idx01/idx_01.dbf';
set newname for datafile 6 to '/tsg/db/ORTSTXX/data/dat01/tools_01.dbf';
set newname for datafile 7 to '/tsg/db/ORTSTXX/data/dat01/maxtrad_data_01.dbf';
set newname for datafile 8 to '/tsg/db/ORTSTXX/data/idx01/maxtrad_indx_01.dbf';
set newname for datafile 9 to '/tsg/db/ORTSTXX/data/dat01/lcbtts_data_01.dbf';
set newname for datafile 10 to '/tsg/db/ORTSTXX/data/idx01/lcbtts_indx_01.dbf';
set newname for datafile 11 to '/tsg/db/ORTSTXX/data/dat01/lcbtts_data_02.dbf';
set newname for datafile 12 to '/tsg/db/ORTSTXX/data/dat01/maxtrad_data_02.dbf';
set newname for datafile 13 to '/tsg/db/ORTSTXX/data/dat01/maxtrad_data_03.dbf';
set newname for datafile 14 to '/tsg/db/ORTSTXX/data/dat01/pss_data_01.dbf';
set newname for datafile 15 to '/tsg/db/ORTSTXX/data/idx01/pss_indx_01.dbf';
set newname for datafile 16 to '/tsg/db/ORTSTXX/data/dat01/lcbtts_data_03.dbf';
duplicate target database to ORTSTXX logfile
group 1 ('/tsg/db/ORTSTXX/data/redoA/redo01_01.dbf',
'/tsg/db/ORTSTXX/data/redoB/redo01_02.dbf') size 150M,
group 2 ('/tsg/db/ORTSTXX/data/redoA/redo02_01.dbf',
'/tsg/db/ORTSTXX/data/redoB/redo02_02.dbf') size 150M,
group 3 ('/tsg/db/ORTSTXX/data/redoA/redo03_01.dbf',
'/tsg/db/ORTSTXX/data/redoB/redo03_02.dbf') size 150M,
group 4 ('/tsg/db/ORTSTXX/data/redoA/redo04_01.dbf',
'/tsg/db/ORTSTXX/data/redoB/redo04_02.dbf') size 150M;
}





Copyright © 2007, All rights reserved by RudnikConsulting Inc