Wednesday, August 13, 2014

RMAN Restore and Recovery Scenarios


Restore and Recovery Scenarios

 

Full Database Restore

 

$ORACLE_HOME/bin/rman target / nocatalog

RMAN> shutdown abort;

RMAN> startup mount;

RMAN> restore database;

RMAN> recover database;

RMAN> alter database open;

database opened

 

Tablespace Restore (online)

 

$ORACLE_HOME/bin/rman target / nocatalog

RMAN> sql 'alter tablespace users offline';

RMAN> restore tablespace users;

RMAN> recover tablespace users;

RMAN> sql 'alter tablespace users online';

* A SYSTEM tablespace cannot be recovered with the database online.

 

 

Tablespace Restore (offline)

 

$ORACLE_HOME/bin/rman target / nocatalog

RMAN> shutdown abort;

RMAN> startup mount;

RMAN> restore tablespace users;

RMAN> recover tablespace users;

RMAN> alter database open;

database opened

 

Restoring a Specific Datafile

 

$ORACLE_HOME/bin/rman target / nocatalog

RMAN> shutdown abort;

RMAN> startup mount;

RMAN> restore datafile '/oradata/DB1/dbf/users01.dbf';

RMAN> recover datafile '/oradata/DB1/dbf/users01.dbf';

RMAN> alter database open;

database opened

 

Control File Restoration

 

Prerequisite: In your rman backup directory determine the latest control file backup.

Default Format: c-nnnnnnnnnn-nnnnnnnn-nn

 

$ORACLE_HOME/bin/rman target / nocatalog

RMAN> shutdown abort;

RMAN> startup nomount;

RMAN> set dbid = 1184749195

RMAN> restore controlfile from '/oradata/DB1/rman/c-1184749195-20060626-02'

RMAN> alter database mount;

RMAN> restore database;

RMAN> recover database;

RMAN> alter database open resetlogs;

database opened



Database Point-In-Time-Recovery (PITR)
Also known as time-based incomplete recovery.

 

$ORACLE_HOME/bin/rman target / nocatalog

RMAN> shutdown abort;

RMAN> startup mount;

RMAN> restore database until time "to_date('09/03/07 13:00:00', 'MM/DD/YY HH24:MI:SS')";

RMAN> recover database until time "to_date('09/03/07 13:00:00', 'MM/DD/YY HH24:MI:SS')";

RMAN> alter database open resetlogs;

database opened

* Make sure you perform a full backup after this operation!



 



Restore to Another System
Prerequisites

Ideally ensure destination system configured exactly like source.

Same OS version and patch level.

Same drives (C:, D:, S: etc.).

CPU and RAM same or better.

The same version of Oracle is installed on the target system as the source.

Ensure the ORACLE_HOME and ORACLE_SID environment variables are set.

Ensure the listener is running.

 

Copy RMAN backupset files to the destination system rman directory.

 

If Windows:

Create the password file.

orapwd file=orapwDB1 password=mypassword

Creates the file %ORACLE_HOME%\dbs\orapwDB1

Copy %ORACLE_HOME%\dbs\orapwDB1 to %ORACLE_HOME%\database.

In some instances of a restore like this it may look for the file here.

Create or start the Windows database instance service.

oradim -new -sid DB1 -intpwd mypassword -startmode MANUAL

Creates the file: %ORACLE_HOME%\database\PWDDB1.ORA

Ensure the drive\path to the admin (adump,bdump,cdump,udump), data and redo directories on the source and destination systems are identical.

Example:

Admin Dump Directories

mkdir C:\oracle\product\10.2.0\admin 

mkdir C:\oracle\product\10.2.0\admin\DB1 

mkdir C:\oracle\product\10.2.0\admin\DB1\adump 

mkdir C:\oracle\product\10.2.0\admin\DB1\bdump 

mkdir C:\oracle\product\10.2.0\admin\DB1\cdump 

mkdir C:\oracle\product\10.2.0\admin\DB1\udump 

 

 

Data Directories

mkdir D:\oradata

mkdir D:\oradata\DB1

 

 

Redo and Archive Log Directories

mkdir D:\oradata\DB1\recovery1

mkdir D:\oradata\DB1\recovery2

 

 

Procedure

 

Restore SPFILE and Control File

%ORACLE_HOME%\bin\rman target / nocatalog 

RMAN> set dbid 161080442 

RMAN> startup nomount; 

      Creates the file: %ORACLE_HOME%\database\hc_db1.dat

RMAN> restore spfile from 'R:\rman\C-161080442-20080313-00'; 

      Creates the file: %ORACLE_HOME%\database\SPFILEDB1.ORA

RMAN> startup force nomount

RMAN> restore controlfile from 'R:\rman\C-161080442-20080313-00'; 

RMAN> shutdown immediate 

RMAN> exit 

 

 

Restore and Recover the Data

 

%ORACLE_HOME%\bin\rman target / nocatalog 

RMAN> startup mount; 

RMAN> restore database; 

      For a large database this step may take some time.

RMAN> recover database; 

      If you do not have\need the very last log(s) you can disregard any error messages.

      ORA-00310: archived log contains sequence 100; sequence 101 required...

RMAN> alter database open resetlogs; 

      database opened

RMAN


=====================================================
RMAN Configuration Parameters
=====================================================


Topic :  Description of few parameters in the RMAN Configuration settings


CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
CONFIGURE BACKUP OPTIMIZATION OFF; CONFIGURE DEFAULT DEVICE TYPE TO DISK; CONFIGURE CONTROLFILE AUTOBACKUP OFF; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO %Ff;
CONFIGURE DEVICE TYPE DISK PARALLELISM 1; CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE MAXSETSIZE TO UNLIMITED; CONFIGURE SNAPSHOT CONTROLFILE;


Solution:
RMAN CONFIGURATION PARAMETERS

RMAN has several configuration parameters, which are set to their default values when you first use RMAN. Use show all command to see the default values

RMAN>show all;
By using the V$RMAN_CONFIGURATION view you can view the current configuration values of all the RMAN parameter
By using configure command we can change RMAN configuration parameters

Backup Retention Polity

A backup retention policy tells RMAN to consider backups of datafiles and log files obsolete. You can set a retention policy by using either of two methods: the default redundancy option or recovery window

The Redundancy Option

The Redundancy option lets you specify how many copies of the backups you want to retain
The default is one
You set retention policy this way

RMAN>configure retention policy to REDUNDANCY 2;

The previous RMAN command specifies the RMAN keep only two backups of each database files

The Recovery Window Option

The recovery window refers to a time frame in which all backups will be kept, regardless of how many backups are taken you can set recovery window as follows

RMAN>configure retention policy

To recovery window of 14 days
If you set your policy to a erecovery window of 14 days then all the backups less than 14days old would be retained, and all backups older than 14days would be marked for deletion

Default Device Type

The default device for backups is disk; that is RMAN will automatically backup files to file system on you server. If you want to backup to tape, you configure the default device type of sbt

RMAN>configure default device to type to sbt;
If you wish to switch the default device back to disk then
RMAN>configure default device type to disk;

Channel Configuration

An RMAN session must use some kind of a connection to the server to perform backup and recovery work, and channels represent those connection
If you have four channels configured, four connections will be made to target database to open four separate server sessions
The following example configures two channels with channel 1 backup to the backup directory under /test01 and channel 2 backing up to backup directory under /test02

RMAN>configure channel 1 device type disk format e/test01/app/oracle/oradata/backup/%Uf;

RMAN>configure channel 2 device type disk format e/test02/app/oracle/oradata/backup/%Uf;

Degree of Parallelism

When two or more channels are allocated for single backup operation this is reffered to parallelization. The degree of parallelism denotes the number of channels that RMAN open during a backup or recovery. The time taken to complete the backup or recovery will decrease as you increase degree of parallelism

RMAN>configure device type disk parallelism4;

Backup optimization

The backup optimization option ensure that RMAN doesnft perform a file backup if it has already backed up identical versions of the file
RMAN>configure backup optimization ON;

Control File Auto backup