Thursday, June 13, 2013

RMAN Recovery Scenarios (Complete)

Previewing Backups Needed for Restore:

Normal more:  
RMAN> restore tablespace system preview;
RMAN> restore database preview;
RMAN> restore database from tag TAG20060927T183743 preview;
RMAN> restore datafile 1, 2, 3, 4 preview;
RMAN> restore archivelog all preview;
RMAN> restore archivelog from time 'sysdate - 1' preview;
RMAN> restore archivelog from scn 3243256 preview;
RMAN> restore archivelog from sequence 29 preview;

Summary more: 
RMAN> restore database preview summary;


Block Corruption:

A DB block gets corrupted, when an invalid data is written to it and committed. Oracle throws a Block Corruption error only when it tries to access the block for some purpose.

Physical corruption:   The block itself is not recognized.
Logical corruption:    The contents of the block is logically inconsistent.

Verify the availability and integrity of backup pieces, before RESTORE operation:

  • You can use either the restore ... validate or validate command
  • You can additionally specify the check logical clause to instruct RMAN to check for logical corruption
restore ... validate:
RMAN> restore database validate;
RMAN> restore database from tag MON_BCK validate;
RMAN> restore datafile 1 validate;
RMAN> restore archivelog all validate;
RMAN> restore controlfile validate;
RMAN> restore tablespace users validate;

validate:
RMAN> validate backupset 193;


RMAN’s behavior of searching sequentially back through backups until a good backup is found is
called restore failover.



Performing Database level recovery:

All database files lost. Online redolog files are there - Perform complete recovery.
Performing DB-Level Recovery:

RMAN> connect target /
RMAN> startup mount; ----> using current controlfile
RMAN> restore database;   
RMAN> recover database;
RMAN> alter database open;


RMAN> connect target /
RMAN> startup nomount;
RMAN> restore controlfile from autobackup; -----> using FRA autobackup controlfile
RMAN> alter database mount;
RMAN> restore database;
RMAN> recover database;
RMAN> alter database open resetlogs;

--------------

Performing Tablespace-Level Recovery:

Offline-tablespace:

RMAN> connect target /
RMAN> startup mount;
RMAN> restore tablespace user_data, user_index;
RMAN> recover tablespace user_data, user_index;
RMAN> alter database open;

Online-tablespace:

RMAN> connect target /
RMAN> sql 'alter tablespace data_ts offline immediate';
RMAN> restore tablespace data_ts;
RMAN> recover tablespace data_ts;
RMAN> sql 'alter tablespace data_ts online';


----------

Performing Datafile-Level Recovery:

Offline-Datafile:

RMAN> connect target /
RMAN> startup mount;
RMAN> restore datafile '/ora01/brdstn/system_01.dbf';
RMAN> recover datafile '/ora01/brdstn/system_01.dbf';
RMAN> alter database open;

Online-Datafile:

RMAN> connect target /
RMAN> sql 'alter database datafile 3, 4 offline';
RMAN> restore datafile 3, 4;
RMAN> recover datafile 3, 4;
RMAN> sql 'alter database datafile 3, 4 online';

[OR]

RMAN> sql "alter database datafile ''/ora01/BRDSTN/data_ts01.dbf'' offline";
RMAN> restore datafile '/ora01/BRDSTN/data_ts01.dbf';
RMAN> recover datafile '/ora01/BRDSTN/data_ts01.dbf';
RMAN> sql "alter datafile ''/ora01/BRDSTN/data_ts01.dbf'' online";



Restoring Datafiles to Nondefault Locations (SRSR = Setnewname, Restore, Switch, Recover)
-----------------------------------------------------------------------------------------------------------------------

DB is OFFLINE:
==============

RMAN> connect target /
RMAN> startup mount;
RMAN> run{
2> set newname for datafile 4 to '/ora01/BRDSTN/data_ts01.dbf';
3> set newname for datafile 5 to '/ora01/BRDSTN/data_ts02.dbf';
4> restore tablespace data_ts;
5> switch datafile all; # Updates repository with new datafile location.    [switch datafile 4 also ok]
6> recover tablespace data_ts;
7> alter database open;
8> }


DB is ONLINE:
==============

RMAN> run{
2> sql 'alter database datafile 4, 5 offline';
3> set newname for datafile 4 to '/ora01/BRDSTN/data_ts01.dbf';
4> set newname for datafile 5 to '/ora01/BRDSTN/data_ts02.dbf';
5> restore datafile 4, 5;
5> switch datafile all; # Updates repository with new datafile location.
6> recover datafile 4, 5;
7> sql 'alter database datafile 4, 5 online';
8> }


[OR]

RMAN> run{
2> sql "alter database datafile ''/ora02/BRDSTN/data_ts01.dbf'' offline';
3> set newname for datafile '/ora02/BRDSTN/data_ts01.dbf'
4> to '/ora01/BRDSTN/data_ts01.dbf';
5> restore datafile '/ora02/BRDSTN/data_ts01.dbf';
6> switch datafile all; # Updates repository with new datafile location.
7> recover datafile '/ora01/BRDSTN/data_ts01.dbf';
8> sql "alter database datafile ''/ora01/BRDSTN/data_ts01.dbf'' online";
9> }

Performing Block-Level Recovery

  • Block-level corruption is rare and is usually caused by some sort of I/O error.
  • RMAN will automatically detect corruption in blocks whenever a backup or backupvalidate command is issued.
  • Your database must be in archivelog mode for performing block-level recoveries

When RMAN detects corrupt blocks, it writes an error to the trace files/alert.log file and also populates the V$DATABASE_BLOCK_CORRUPTION view. You can instruct RMAN to recover the
blocks listed as corrupt in that view as follows:

You can instruct RMAN to recover blocks in two ways:
• Use the corruption list clause.
• Specify individual datafiles and blocks.


RMAN> blockrecover corruption list; -----> 10g 
[OR]
RMAN> recover corruption list;  ----> 11g

The other way to recover blocks is to specify particular datafiles and blocks. Here are several
examples:
RMAN> recover datafile 5 block 24;
RMAN> recover datafile 7 block 22 datafile 8 block 43;
RMAN> recover datafile 5 block 24 from tag=tues_backup;
RMAN> recover datafile 6 block 89 restore until sequence 546;
RMAN> recover datafile 5 block 32 restore until 'sysdate-1';
RMAN> recover datafile 5 block 65 restore until scn 23453;






No comments:

Post a Comment

Oracle row type vs PostgreSQL record

The Oracle row type concept can be accomplished with the record type in PostgreSQL. Example: Oracle: CURSOR travel_cur IS  SELECT  c.travel_...