Recovery manager



                                            
The RMAN environment consists of the utilities and databases that play a vital role in backing up our data. At a minimum, the environment for RMAN must include the following.
The target database to be backed up:
The RMAN client, which interprets backup and recovery commands, directs server sessions to execute those commands, and records our backup and recovery activity in the target database control file
Some environments will also use these optional components:
A flash recovery area, a disk location in which the database can store and manage files related to backup and recovery.
Media management area, required for RMAN to interface with backup devices such as tape drives.
A recovery catalog database, a separate database schema used to record RMAN activity against one or more target databases.
The RMAN client is started by issuing the RMAN command at the command prompt of our operating system.
RMAN must connect to a target database (with SYSDBA privileges) to perform backup and recovery tasks.
This command illustrates connecting RMAN to a target database and a recovery catalog at startup.
To take backup rman with no catalog:à
$rman target /
Backup database;
To configure RMAN with catalog:à
*configure listener and tnsnames(refer to networking)##netca = network configuration assistant utility.
$lsnrctl start orcl, $lsnrctl start dev.
$tnsping orcl, $tnsping dev.
*create password files catalog and target database.($ orapwd file=orapwdev password=oracle entries=20) # make sure we are at $ORACLE_HOME/dbs
*create tablespace for RMAN on catalog database.
* catalog must be latest version or equal to target database.
Target> select instance_name, version from v$instance;
Catalog>select instance_name, version from v$instance;
Sql>create tablespace rman_tbs datafile ‘/location/datafile.dbf’ size 40M autoextend on;
Create a user account for RMAN and grant the privileges.
Privs: connect, recovery_catalog_owner
Sql>create user rman identified by rman default tablespace rman_tbs quota unlimited on rman_tbs;
Sql>grant   connect ,resource, recovery_catalog_owner to rman;
From catalog:
$rman catalog rman/rman
Rman>create catalog;
To drop catalog
Rman>drop catalog; #don’t do it. It’s for information.
To resync catalog
Rman>resync catalog;
$rman target system/manager catalog rman/rman@rman
To register a database
Rman>register database;
Backup database
Rman>backup database;
To list the backup files.
Rman> list backup of database;
Backup database along with current controlfile
Rman>backup database include current controlfile;
To clear the screen.
Rman>host “clear”;
Backup database and archivelog.
Rman>backup database plus archivelog;
Rman> backup database tag ‘orcl backup’;
To specify a non default location for backup: (from 10g onwards)
Rman>backup database format=’/data/oracle/rmanbackup/abc_%u’;
To have multiple copies of backup:
Rman>backup device type disk copies 2 database format ‘/data/oracle/rmanbackup/1_%u’,’/data/oracle/rmanbacup/2_%u’;
How to take backup which is not backed up:
Rman>backup database not backed up;
How to take spfile backup:
Rman>backup spfile;
How come we know to take the backup or not:
Rman>report need backup;
To know restorable or not:
Rman>validate backupset number;
To check whether we have the backup or not:
Crosscheck backup of database;
Individual backups:
Rman>Backup tablespace ‘SYSTEM’;
Rman>backup datafile 4,5;
How to enable auto controlfile backup.( whenever we take any backup it will include controlfile).
Rman>show all;
Rman>configure controlfile autobackup on;
Rman>backup datafile 5;
Rman>configure retention policy to recovery window of 7 days;
To enable:
Rman>configure backup optimization on;
To disable:
Rman>configure backup optimization off;
Deleting backup:
Rman> delete backupset number;
                                                               Flash recovery area with rman
Target>show parameter db_recovery;
$mkdir infer
$cd infer
$mkdir recov
Target>alter system set db_recovery_file_dest_size=2G scope=both;
Target>alter system set db_recovery_file_dest=’/data/oracle/infer/recov’ scope=both;
Target>show parameter db_recovery;
$rman target system/manager@dev catalog rman/rman@rman;
Rman>list backup of database;
Rman>backup database;
Catalog>desc  rc_database;
Catalog>select name, dbid from rc_database;
How to create backup script?
Rman>create script fulldb
{
Backup database include current controlfile plus archivelog
;}
Catalog>desc rc_stored_script;
Catalog>select db_name, script_name from rc_stored_script;
Rman>print script fulldb;
Rman>run
2>{
3>execute script fulldb;
}
Delete the script:
Rman>delete script fulldb;
Making incremental baackups:
After starting RMAN, run the backup incremental command at the RMAN prompt. This example makes a level 0 incremental backup of the database:
Rman>backup incremental level 0 database;
The following command performs a level 1 differential incremental backup of the database:
Rman> backup incremental level 1 database;
If no level 0 backup is available, then the behavior depends upon the compatibility mode setting. If compatibility is >=10.0.0, rman copies all blocks changed since the file was created, and stores the results as a level 1 backup. In other words, the SCN at the time the incremental backup is taken is the file creation SCN. If compatibility <10.0.0, rman generates a level 0 backup of the file contents at the time of the backup, to be consistent with the behavior in previous releases.

                                                        RMAN Restore & Recover
How to recover a datafile?
First we need to take backup.
Rman> backup database include current controlfile plus archivelog;
Target>!rm /path/system.dbf
Rman> startup force;
Rman>restore datafile datafilenumber;
Rman>recover datafile datafilenumber;
Rman>sql ‘alter database open’;
How to recover online redo’s?
Target>select member from v$logfile;
Target>archive log list;
Target>select group#, sequence#, status from v$log;
Target>!
$cd  dev/log/log/
$rm –rf *
Rman>startup mount force;
Rman> restore database force;
Rman>list backup of archivelog all;
Rman>recover database until logseq number;
Rman>sql ‘alter database open resetlogs’;
Rman>reset database;
target>archive log list;
rman>delete backupset number;
Disaster Recover:--
rman>backup database include current controlfile plus archivelog;
rman>backup spfile;
target> select name from v$datafile;
$rm  dev/data/*
Sql>select member from v$logfile;
$rm  dev/log/log/*
Sql>select name from v$controlfile;
$rm  dev/control/*
$rm  $ORACLE_HOME/dbs/spfiledev.ora
$rm $ORACLE_HOME/dbs/initdev.ora
Rman>startup nomount force;
Rman>restore spfile;
Rman>startup nomount force;
Rman>restore controlfile;
Rman>sql ‘alter database mount’;
Rman>restore database;
Rman>list backup of database;
Rman>list backup of archivelog all;
Rman>recover database until logseq number;
Rman>sql ‘alter database open resetlogs’;
How to recover from block corruption?
Before corrupting blocks we should take the backup.
Rman>backup database include current controlfile plus archivelog;
Tar$cd  dev/data/
$vi datafile.dbf
Add something it will automatically corrupt.
Rman>backup validate database;
Rman>startup force;
$dbv file=datafile.dbf
Rman>sql ‘alter database datafile 4 offline’;
Rman>restore datafile 4;
Rman>recover datafile 4;
Rman>sql ‘alter database open’;
Rman>sql ‘alter database datafile 4 online’;