Posted by: Monish | August 6, 2008

Recovery Manager (RMAN)

What is RMAN?

Recovery Manager as it is popularly called RMAN is a platform independent Oracle utility for coordinating Backup and Restoration procedure. This is integrated as a part of Oracle server software. RMAN binary resides at $ORACLE_HOME/bin/rman. RMAN is the Oracle recommended tool to take database backups. It can be used to backup datafiles and datafile image copies, control file and control file image copies, archived redo logs, spfile and RMAN backup pieces.

RMAN Architecture:

RMAN operates via server sessions connecting to target databases which are the databases that need to be backed up. The collection of information about the target database such as its schema information, backup copy information, configuration settings, backup and recovery scripts is called the RMAN repository. RMAN uses this metadata about the target databases to perform its backup and recovery activity. RMAN periodically retrieves information from the target database control file and saves it in the recovery catalog. Brief listings of entities that enable RMAN to perform its function are given below:


Target database:

This is the database that RMAN needs to back up. RMAN server sessions running in the target database perform backup and recovery operations.


RMAN Repository:

This is RMAN’s metadata about backup’s, archived redologs, and its own activities. The control file of each database is the primary storage for RMAN repository.

Recovery Catalog schema:

This is the database schema in the recovery catalog database that owns the RMAN backup and recovery metadata (the RMAN repository).

RMAN Client :

RMAN operations can be managed through RMAN client sessions. It is a CLI(command line interface) through which backup, recover ,sql, special RMAN commands are issued. Commands communicate with RMAN server and operations are performed. The client starts RMAN server sessions on target databases and directs them to perform backup and recovery operations. The RMAN client uses Oracle Net to connect to the target database. RMAN client can be located on any host that connects to the target host through Oracle Net.


RMAN executable:

This is the actual program that manages all backup and recovery operations. RMAN executable resides at $ORACLE_HOME/bin directory. It performs backup and recovery operations and records the results in the control file and optional recovery catalog.

Server Processes:

These are the background processes that facilitate the communication between the RMAN executable and the target database. The server process performs the real work of reading and writing to disk devices and tape drives during backup and recovery.
Apart from this there are three optional entities including flash recovery area, the recovery catalog database(and the recovery catalog schema) and the media management software.

Media Management Software :

RMAN cannot backup directly to tape drives. An interface called MML(Media Management Layer) comes to picture and the software used for this purpose is the media management software.

Rman Recovery Catalog:

Oracle recommends the usage of recovery catalog with RMAN. Recovery catalog is a metadata repository that stores details on the backup sets of datafiles, control files, archived redo logs backups, spfile of the target databases. Recovery catalog is needed for efficient backup of any number of databases.

We can use the control file to store details on database backup. The space allocated in control file is a constraint when the amount of metadata increases.

RMAN scripts can be stored only in the recovery catalog not in the control file.

Why use RMAN :

  • No Extra Costs. It is available free.
  • RMAN introduced in Oracle 8 it has become simpler with new version and easier that user managed backups.
  • Proper Security
  • You are 100% sure your database has been backed up .
  • It contains details of backup taken in the central repository
  • Facility of Testing validity of backups also command like cross check to check the status of backup.
  • Oracle 10g has got further optimized incremental backups with has resulted in improvement of performance during backup and recovery time
  • Parallel operation are supported
  • Better Querying facility for knowing different details of backup.
  • No Extra redo generated when backup is taken. compared to online backup
  • Maintains repository of backup metadata.
  • Remembers backup locations
  • Knows what needs backup set locations
  • Knows what needs to be backed up
  • Knows what is required for recovery
  • Knows what backups are redundant
  • It handles database corruptions

Difference between RMAN and User-managed Backups:

A traditional User-managed backup uses operating system (OS) utilities to copy database files to relevant locations and/or tapes. On the other hand RMAN backups up the database files from with in the database with the help of Oracle database server.

RMAN performs incremental backups, which back up only those data blocks that changed after a previous backup where as user-managed method Backs up all blocks, not just the changed blocks.

During Backing up and restoring Rman checks for corrupt blocks but user-method does not provide any error checking.

Backup Using RMAN:

Create Recovery Catalog:

First create a user to hold the recovery catalog:

— Create tablepsace to hold repository

SQL> create tablespace mrman datafile ‘/u01/app/oradata/anand/mram.dbf’

2 size 6m autoextend on next 2m maxsize 100m;

Tablespace created.

— Create rman schema owner

SQL> create user mrman identified by mrman

2 temporary tablespace temp

3 default tablespace mrman

4 quota unlimited on mrman;

User created.

SQL> grant connect, resource, recovery_catalog_owner to mrman;

Grant succeeded.

Create the recovery catalog:

$ rman catalog=mrman/mrman@anand

Recovery Manager: Release 10.2.0.3.0 – Production on Mon Aug 4 13:18:22 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to recovery catalog database

RMAN> create catalog tablespace “MRMAN”;

recovery catalog created

RMAN> exit

Recovery Manager complete.

$

Register Database:

Each database to be backed up by RMAN must be registered:

$ rman catalog mrman/mrman@anand target sys/sys@monish

Recovery Manager: Release 10.2.0.3.0 – Production on Mon Aug 4 13:29:55 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to target database: MONISH (DBID=2166643499)

connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog

starting full resync of recovery catalog

full resync complete

RMAN>

To Backup automatic controlfile & spfile:

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters are successfully stored

starting full resync of recovery catalog

full resync complete

To see all the parameters:

RMAN> show all;

RMAN configuration parameters are:

CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default

CONFIGURE BACKUP OPTIMIZATION OFF; # default

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘%F’; # default

CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE MAXSETSIZE TO UNLIMITED; # default

CONFIGURE ENCRYPTION FOR DATABASE OFF; # default

CONFIGURE ENCRYPTION ALGORITHM ‘AES128’; # default

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default

CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/u01/app/oracle/dbs/snapcf_monish.f’; # default

Run the following sql command to see the database recovery file destination is configured or not.

SQL> show parameter db

……

…..

NAME TYPE VALUE

———————————— ———– —————————-

db_keep_cache_size big integer 0

db_name string monish

db_recovery_file_dest string /u02/monish/backup

…..

….

If it’s not configured then run the following:

–to set the controlfile backup location

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/u01/%F’;

new RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/u01/%F’;

new RMAN configuration parameters are successfully stored

–to set the database backup location

RMAN>CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT = ‘/u01/bkp/df0_%d_%s_%t’;

To take the Backup:

run

{

CROSSCHECK BACKUPSET; # To check available and expired backup sets.

CROSSCHECK ARCHIVELOG ALL; # To check available and expired Archive Logs

DELETE NOPROMPT EXPIRED BACKUP; # It will delete expired(old/not exists physicaly) backups

DELETE NOPROMPT EXPIRED ARCHIVELOG ALL; # It will delete expired archive logs

SQL ‘ALTER SYSTEM ARCHIVE LOG CURRENT’; # Switch Log

BACKUP DATABASE PLUS ARCHIVELOG; # Backup the whole Database plus archive files

DELETE NOPROMPT OBSOLETE; # It will remove old backups according to the redundancy period.

}

# End of Backup

Restore & Recovery using RMAN :

SQL> shut abort

ORACLE instance shut down.

SQL>

SQL> startup mount

ORACLE instance started.

Total System Global Area 603979776 bytes

Fixed Size 1263176 bytes

Variable Size 385878456 bytes

Database Buffers 209715200 bytes

Redo Buffers 7122944 bytes

Database mounted.

SQL>

If the Datafile is crashed then do the following:

RMAN> restore datafile 1;

Starting restore at 04-AUG-08

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to /u02/monish/system.dbf

channel ORA_DISK_1: reading from backup piece

/u02/monish/backup/MONISH/backupset/2008_08_04/o1_mf_nnndf_TAG20080804T155512_49fp88pw_.bkp

channel ORA_DISK_1: restored backup piece 1

piece handle=/u02/monish/backup/MONISH/backupset/2008_08_04/o1_mf_nnndf_TAG20080804T155512_49fp88pw_.bkp

tag=TAG20080804T155512

channel ORA_DISK_1: restore complete, elapsed time: 00:01:06

Finished restore at 04-AUG-08

RMAN>

RMAN> recover database;

Starting recover at 04-AUG-08

using channel ORA_DISK_1

starting media recovery

media recovery complete, elapsed time: 00:00:06

Finished recover at 04-AUG-08

RMAN> alter database open;

database opened

RMAN>

Examples: ~

Restore and recover the whole database:

RMAN> STARTUP FORCE MOUNT;

RMAN> RESTORE DATABASE;

RMAN> RECOVER DATABASE;

RMAN> ALTER DATABASE OPEN;

Restore and recover a tablespace:

RMAN> SQL ‘ALTER TABLESPACE users OFFLINE’;

RMAN> RESTORE TABLESPACE users;

RMAN> RECOVER TABLESPACE users;

RMAN> SQL ‘ALTER TABLESPACE users ONLINE’;

Restore and recover a datafile:

RMAN> SQL ‘ALTER DATABASE DATAFILE 64 OFFLINE’;

RMAN> RESTORE DATAFILE 64;

RMAN> RECOVER DATAFILE 64;

RMAN> SQL ‘ALTER DATABASE DATAFILE 64 ONLINE’;

>>> Please leave your comment on the above post….

Advertisements

Responses

  1. kEEKA kEV keeka.,,,,,,sUPERooooooooooo
    …..i LIKED IT…..

  2. Thank you very much Mr. Monish

  3. i like ur website too informative. I have one query could u please tell query to know the growth of database on daily basis


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Categories

%d bloggers like this: