Pages

Wednesday, April 11, 2012

RMAN (Recovery Manager)

RMAN
(Recovery Manager)

Recovery Manager (RMAN) is a utility that can manage your entire Oracle backup and recovery activities.

Benefits:
 
1. Incremental backups that only copy data blocks that have changed since the last backup.
2. Tablespaces are not put in backup mode, thus there is noextra redo log generation during online backups.
3. Detection of corrupt blocks during backups.
4. Parallelization of I/O operations.
5. Automatic logging of all backup and recovery operations.
6. Built-in reporting and listing commands.

Components of RMAN:

1. RMAN executable
2.Server processes
3.Channels
4.Target database
5.Recovery catalog database (optional)
6.Media management layer (optional)
7.Backups, backup sets, and backup pieces

Architectural components:
 
1.RMAN executable
2.Server processes
3.Channels
4.Target database
5.Recovery catalog database (optional)
6.Media management layer (optional)
7.Backups, backup sets, and backup pieces

RMAN Executable:
 
The RMAN executable, usually named rman, is the program that manages all backup and recovery operations. You interact with the RMAN executable to specify backup and recovery operations you want to perform.

Server Processes:

RMAN server processes are background processes, started on the server, used to communicate between RMAN and the databases. When you connect the RMAN client to the target database server, RMAN allocates server sessions on the target instance and directs them to perform the backup and recovery operations. The RMAN client itself does not perform the backup, restore, or recovery.

Channels:
 
A channel is an RMAN server process started when there is a need to communicate with an I/O device, such as a disk or a tape. A channel is what reads and writes RMAN backup files. It is through the allocation of channels that you govern I/O characteristics such as:
  • Type of I/O device being read or written to, either a disk or an sbt_tape
  • Number of processes simultaneously accessing an I/O device
  • Maximum size of files created on I/O devices
  • Maximum rate at which database files are read
  • Maximum number of files open at a time
Target Database:
 
The target database is the database on which RMAN performs backup, restore, and recovery operations. This is the database that owns the datafiles, control files, and archived redo files that are backed up, restored, or recovered.

Note: That RMAN does not back up the online redo logs of the target database

Recovery Catalog Database:
 
The recovery catalog database is an optional repository used by RMAN to record information concerning backup and recovery activities performed on the target. This includes information such as:
  • Details about the physical structure of the target database
  • A log of backup operations performed on the target database's datafiles, control files, and archived redo log files
  • Stored scripts containing frequently used sequences of RMAN commands
Why is the catalog optional?
 
Because RMAN manages backup and recovery operations, it requires a place to store necessary information about the database. RMAN always stores this information in the target database control file. You can also store RMAN metadata in a recovery catalog schema contained in a separate database. The recovery catalog
schema must be stored in a database other than the target database. 

Contents of the Recovery Catalog
 
the recovery catalog contains information about RMAN operations, including:
  • Datafile and archived redo log backup sets and backup pieces
  • Datafile copies
  • Archived redo logs and their copies
  • Tablespaces and datafiles on the target database
  • Stored scripts, which are named user-created sequences of RMAN commands
  • Persistent RMAN configuration settings
Backups, Backup Sets, and Backup Pieces
 
when you issue an RMAN backup command, RMAN creates backup sets, which are logical groupings of physical files. The physical files that RMAN creates on your backup media are called backup pieces.

RMAN backup
 
A backup of all or part of your database. This results from issuing an RMAN backup command. A backup consists of one or more backup sets.

Backup set
 
A logical grouping of backup files -- the backup pieces -- that are created when you issue an RMAN backup command. A backup set is RMAN's name for a collection of files associated with a backup. A backup set is composed of one or more backup pieces.

Backup piece
 
A physical binary file created by RMAN during a backup. Backup pieces are written to your backup medium, whether to disk or tape. They contain blocks from the target database's datafiles, archived redo log files, and control files. When RMAN constructs a backup piece from datafiles, there are a several rules that it follows:

 A datafile cannot span backup sets
 A datafile can span backup pieces as long as it stays within one backup set
 Data files and control files can coexist in the same backup sets
 Archived redo log files are never in the same backup set as datafiles or control files RMAN is the only tool that can operate on backup pieces. If you need to restore a file from an RMAN backup, you must use RMAN to do it. There's no way for you to manually reconstruct database files from the backup pieces. You must use RMAN to restore files from a backup piece.

Note: we can configure RMAN in two modes:
    1. Catalog mode
    2. Nocatalog mode
Oracle strongly recommends you to configure rman in catalog mode.
In no catalog mode information about configuration parameters and backupsets will be stored in target database control file.
In catalog mode information about configuration parameters and backupsets will be stored in separate database.

RMAN Configuration in catalog mode:

Configuration at Target database side:

Go to Target database (prd) (200.200.0.1)
$ cd $ORACLE_HOME/dbs
$ orapwd file = orapwprd password = ******* force = y
$cd $ORACLE_HOME/network/admin
$ vi listener.ora

:wq!
$lsnrctl start targetprd

Catalog database creation:

--> Create new database (catdb)
-->Create separate tablespace to hold rman metadata
-->Create separate user and grant connect, resource and recovery_catalog_owner to rman user
-->Create catalog
-->And register target database in to the catalog

Configuration at catalog database side (catdb) (200.200.0.2):

$export ORACLE_SID=catdb
$sqlplus ‘/as sysdba’
Sql>startup
Sql>create tablespace rman_ts datafile ‘/Oracle/oradata/catdb/rman.dbf’ size = 300m;
Sql>grant connect, resource, recovery_catalog_owner to rman identified by rman;
Sql>alter user rman default tablespace rman_ts;
Sql>conn rman/rman
Sql>select * from tab;
---no rows----
 
$ cd $ORACLE_HOME/netrowk/admin
$ vi tnsnames.ora


$ tnsping to_targetprd
$rman catalog rman/rman
Rman>create catalog;
Rman>exit
$ sqlplus rman/rman
Sql>select count(*) from tab;
--In 10g 90-99 tables and views created—
--In 11g 142 tables and views created—
Sql>select * from rc_database;
--no rows selected—
This query gives us what are all the database registered in catalog database

Registering target database (prd)

$ rman catalog rman/rman target sys/****@to_targetprd
Rman>register database;
Rman>show all;



RMAN Cold Backup

$ rman catalog rman/rman target sys/****@to_targetprd
Connected to target database
Rman>show all;
Rman>list backup;
Rman>list backup summary;
Rman>shutdown immediate;
Rman>startup mount;
Rman>backup full database;
Rman>backup current controlfile;

Note: In Rman cold backup database must be in mount stage.

RMAN Restore using RMAN COLD Backup

I have taken RMAN COLD Backup in my last post, In this post I am going to delete datafile and then I will try to open a database. I will write some steps to recover/restore datafile/database.

At Server Side: (prd)

$sqlplus ‘/as sysdba’

Sql>startup

ORACLE instance started.
Total System Global Area 612368384 bytes
Fixed Size 1250428 bytes
Variable Size 226495364 bytes
Database Buffers 377487360 bytes
Redo Buffers 7135232 bytes
Database mounted.

ORA-01157: cannot identify/lock data file 7 - see DBWR trace file
ORA-01110: data file 7: '/ORACLE/ORADATA/PRD/INDX.DBF'

SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

At Client side:

$ rman catalog rman/rman target sys/****@to_targetprd
Connected to target database (not started)
RMAN> startup nomount;
Oracle instance started
Total System Global Area 612368384 bytes
Fixed Size 1250428 bytes
Variable Size 226495364 bytes
Database Buffers 377487360 bytes
Redo Buffers 7135232 bytes
RMAN> sql 'alter database mount';
RMAN> restore tablespace indx;
RMAN> recover tablespace indx;
RMAN> recover database;
RMAN> alter database open resetlogs;
Database opened

RMAN Hot Backup

As the name implies, an online backup allows you to backup the database while users are working. Some newer DBA’s are a little afraid of online backups, and that somehow they might not work. We assure you that I’ve yet to see a correctly done online backup fail to be recoverable. Most shops these days use online backups at least for their production systems. For a large number of shops online backups are the only backups they ever make.

In this section we will walk you through doing an online backup. First, you will need to put your database in ARCHIVELOG mode as discussed earlier in chapter three of this book.
Then you should configure your database and RMAN as we describe in the above section of this book titled “Configure the Database and RMAN for our Backup”. Once that is done, you are ready to do an online backup with RMAN.

RMAN>backup database plus archivelog;

Clone/Refresh database using Rman:



Edit the pfile with new database name and edit directories and create directories






No comments:

Post a Comment