RMAN Recovery Scenarios Related To Database
RMAN Recovery Scenarios Related To Database
RMAN Recovery Scenarios Related To Database
Patil)
RMAN Page 1
RMAN Recovery All Scenarios (Santosh
Patil)
$ rman
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights
reserved.
RMAN Page 2
RMAN Recovery All Scenarios (Santosh
Patil)
database opened
Note: Remember that RMAN will look in older backups if it can’t find a backup piece
or if corruption is detected. RMAN will search through backup history until it locates
a good backup or until it exhausts all possibilities. This feature is called restore
failover.
NOTE: By default, the restore command skips datafiles associated with read-only
tablespaces. If you want read-only tablespaces restored, then you must use the check
readonly command.
RMAN Page 3
RMAN Recovery All Scenarios (Santosh
Patil)
Temporary Tablespaces:
You don’t have to restore or re-create missing locally managed temporary
tablespace tempfiles. When you open your database for use, Oracle automatically
detects and re-creates locally managed temporary tablespace tempfiles.
If you wanna restore form some specific backups which you tagged:
You can also tell RMAN to restore datafiles from a point in the past using the until
clause of the restore command in one of the following ways:
A) Until SCN
If you know the SCN in a backup piece that you want to restore from
Example:
B) Until sequence
If you know the log sequence number that you want to restore up to
If you’ve created restore points, then you can also use the restore point name
D) Until time
You can also specify a point in time from which you want RMAN to restore an
older backup. RMAN> restore database until time ‘sysdate – 5?;
RMAN Page 4
RMAN Recovery All Scenarios (Santosh
Patil)
You are required to open your database with the open resetlogs command anytime
you use a backup control file during a recovery operation.
RMAN Page 5
RMAN Recovery All Scenarios (Santosh
Patil)
For Oracle Database 10g or Oracle9i Database, use the blockrecover command
to perform block media recovery.
As for Oracle Database 11g or newer, we will use the recover datafile … block
command as shown below:
ONLY FOR TESTING FIRST WE CREATED SOME DB BLOCK CORRUTION :)
HEADER_BLOCK
————
146
RMAN Page 6
RMAN Recovery All Scenarios (Santosh
Patil)
RMAN Page 7
RMAN Recovery All Scenarios (Santosh
Patil)
In V$DATABASE_BLOCK_CORRUPTION view:
Using DBV:
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights
reserved.
RMAN Page 8
RMAN Recovery All Scenarios (Santosh
Patil)
RMAN CAN NOT perform block-level recovery on block 1 (datafile header) of the
datafile.
C) VERIFY
no rows selected
RMAN Page 9
RMAN Recovery All Scenarios (Santosh
Patil)
RMAN Page 10
RMAN Recovery All Scenarios (Santosh
Patil)
B) MOUNT DATABASE
$ rman
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights
reserved.
Oracle
instance
started
database
mounted
RMAN Page 11
RMAN Recovery All Scenarios (Santosh
Patil)
C) RESTORE DATAFILE
RMAN> restore datafile 4;
D) RECOVER DATAFILE
E) OPEN DATABASE
database opened
RMAN Page 12
RMAN Recovery All Scenarios (Santosh
Patil)
Here we will use datafile image copy from Flash Recovery Area (FRA), if it is enabled.
This is FASTER WAY to recover a datafile.
So ‘users’ datafile is file#4 and we are assuming that this file got damaged somehow.
RMAN Page 13
RMAN Recovery All Scenarios (Santosh
Patil)
=======================
RMAN Page 14
RMAN Recovery All Scenarios (Santosh
Patil)
You see the database is now using file#4 from the flash recovery area
When you bring the datafile back online, the tablespace will be brought online as
well. The tablespace is now operational. But we don’t want to leave the database
using a file in the flash recovery area, though, especially not for the long term.
In below steps we will move back the data file to its original location.
$ /u01/oracle/DB11G/oradata/brij
$ mv users01.dbf users01.dbf.bkp
RMAN Page 15
RMAN Recovery All Scenarios (Santosh
Patil)
H) Create an image copy of the file & place it in the file’s original location
RMAN Page 16
RMAN Recovery All Scenarios (Santosh
Patil)
As a best practice, you should now create a fresh image copy of the file and place it in
the flash recovery area:
RMAN> backup as copy datafile 4;
RMAN Page 17
RMAN Recovery All Scenarios (Santosh
Patil)
piece
handle=/u01/oracle/DB11G/fast_recovery_area/BRIJ/autobackup/2014_02_11/o1_m
f_s_ 839242357_9hnwcp10_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 11-FEB-2014 10:52:40
For non-system and non-undo datafiles, you have the option of keeping the database
open while performing the recovery. When your database is open, you’re required to
take offline any datafiles you’re attempting to restore and recover.
$ RMAN
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights
reserved.
RMAN Page 18
RMAN Recovery All Scenarios (Santosh
Patil)
NOTE: When using the RMAN sql command, if there are single quote marks within
the SQL statement, then you are required to use double quotes to enclose the entire
SQL statement and then also use two single quote marks where you would ordinarily
just use one quote mark.
RMAN Page 19
RMAN Recovery All Scenarios (Santosh
Patil)
If you want to put the restored datafile to new location, use below RMAN commands
instead
RMAN>run
{
sql “alter database datafile
”/u01/oracle/DB11G/oradata/brij/users01.dbf” offline”; set newname
for datafile ‘/u01/oracle/DB11G/oradata/brij/users01.dbf’ to
‘/backups/users01.dbf';
restore datafile
‘/u01/oracle/DB11G/oradata/brij/users01.dbf';
switch datafile all;
recover datafile ‘/backups/users01.dbf';
sql “alter database datafile ”/backups/users01.dbf” online”;
}
FILE_NAME
——————————————————–
/u01/oracle/DB11G/oradata/brij/users02.dbf
/u01/oracle/DB11G/oradata/brij/system02.dbf
/u01/oracle/DB11G/oradata/brij/undotbs02.dbf
/backups/users01.dbf
/u01/oracle/DB11G/oradata/brij/undotbs01.dbf
/u01/oracle/DB11G/oradata/brij/sysaux01.dbf
/u01/oracle/DB11G/oradata/brij/system01.dbf
/u01/oracle/DB11G/oradata/brij/example01.dbf
8 rows selected.
If only one datafiles had error, we would have gone for datafile level recovery but
since all datafiles associated with have corruption so it is better to go for tablespace
level recovery.
RMAN Page 20
RMAN Recovery All Scenarios (Santosh
Patil)
There are two data files in this tablespace and both got corrupted somehow.
Below were the errors that were encountered in alert log because of this corruption:
$ RMAN
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights
reserved.
RMAN Page 21
RMAN Recovery All Scenarios (Santosh
Patil)
RMAN Page 22
RMAN Recovery All Scenarios (Santosh
Patil)
database opened
Sometimes it is not possible to take the database down. You can take a tablespace
offline, restore, and recover it while your database is open. This works for any
tablespace except the system and undo tablespaces.
This example takes users offline and then restores and recovers before bringing it
back online:
RMAN Page 23
RMAN Recovery All Scenarios (Santosh
Patil)
Here also we got the same error in users tablesace as showin in scenario 1 forcing us
to go for restore/recover of users tabespace.
$ RMAN
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights
reserved.
RMAN Page 24
RMAN Recovery All Scenarios (Santosh
Patil)
RMAN Page 25
RMAN Recovery All Scenarios (Santosh
Patil)
alter tablespace
users online
Completed: alter tablespace users online
RMAN Page 26
RMAN Recovery All Scenarios (Santosh
Patil)
We will start Oracle instance without parameter file for retrieval of spfile
[stextbox id="grey"]
$ RMAN
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights
reserved.
RMAN Page 27
RMAN Recovery All Scenarios (Santosh
Patil)
RMAN Page 28
RMAN Recovery All Scenarios (Santosh
Patil)
$ rman
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights
reserved.
RMAN Page 29
RMAN Recovery All Scenarios (Santosh
Patil)
NOTE: If our spfile autobackup was in default location, we could have used
below command:
RMAN Page 30