Oracle RMAN 11g Backup and Recovery (99 page)

BOOK: Oracle RMAN 11g Backup and Recovery
13.15Mb size Format: txt, pdf, ePub

channel ORA DISK 1: restored backup piece 1

piece handle C:\ORACLE\PRODUCT\10.2.0\FLASH RECOVERY AREA\TESTOEM\

BACKUPSET\2005 12 26\O1 MF NNNDF TAG20051226T085336 1V00ZL3Y .BKP

tag TAG20051226T085336

channel ORA DISK 1: restore complete, elapsed time: 00:03:26

Finished restore at 26-DEC-05

RMAN> recover database;

Starting recover at 26-DEC-05

using channel ORA DISK 1

Finished recover at 26-DEC-05

RMAN> alter database open;

Well, we now have a happy bouncing baby database back again! Woo hoo!

NOTE

Use the
restore database noredo
command when your online redo
logs are not available. Use the
restore database
command without the
redo
parameter when your online redo logs are available during the
recovery.

Restoring to a Different Location

Of course, we don’t always have the luxury of restoring back to the original file system names that the Oracle files resided on. For example, during a disaster recovery drill, you might have one big file system to recover to, rather than six smaller-sized file systems. That can be a bit of a problem, because, by default, RMAN is going to try to restore your datafiles to the same location that they came from when they were backed up. So, how do we fix this problem?

Enter the
set newname for datafile
and
switch
commands. These commands, when used in concert with
restore
and
recover
commands, allow you to tell RMAN where the datafiles need to be placed.

The
set newname
command offers several options with respect to relocation of database datafiles. In Oracle Database 10
g
and earlier, you can set the new name for individual datafiles.

In Oracle Database 11
g,
new features include the ability to change the location for all datafiles in a tablespace or in the entire database.

In our first example, we have datafiles originally backed up to d:\oracle\data\recover, and we want to recover them to a different directory: e:\oracle\data\recover. To do this, we would first issue the
set newname for datafile
command for each datafile, indicating its old location and its new location. Here is an example of this command’s use:

set newname for datafile 'd:\oracle\data\recover\system01.dbf'

to 'e:\oracle\data\recover\system01.dbf';

This example would work for all versions of the Oracle Database when using RMAN. Note that we define both the original location of the file and the new location that RMAN should copy

284
Part II: Setup Principles and Practices

the file to. Once we have issued
set newname for datafile
commands for all of the datafiles that we want to restore to a different location, we proceed as before with the
restore database
and
recover database
commands. Finally, before we actually open the database, we need to indicate to Oracle that we really want to have it use the relocated datafiles that we have restored. We do this by using the
switch
command.

The
switch
command causes the datafile locations in the database control file to be changed so that they reflect the new location of the Oracle database datafiles. Typically, you use the
switch
datafile all
command to indicate to Oracle that you wish to switch all datafile locations in the control file. Alternatively, you can use the
switch datafile
command to switch only specific datafiles.

If you use the
set newname for datafile
command and do not switch all restored datafiles, then any nonswitched datafile will be considered a datafile copy by RMAN, and RMAN will not try to use that nonswitched datafile when recovering the database. Here is an example of the commands that you might use for a restore using the
set newname for datafile
command: startup nomount

restore controlfile from autobackup;

alter database mount;

run

{

set newname for datafile 'd:\oracle\oradata\recover\system01.dbf' to

'e:\oracle\oradata\recover\system01.dbf';

set newname for datafile

'd:\oracle\oradata\recover\recover undotbs 01.dbf' to

'e:\oracle\oradata\recover\recover undotbs 01.dbf';

set newname for datafile 'd:\oracle\oradata\recover\users01.dbf' to

'e:\oracle\oradata\recover\users01.dbf';

set newname for datafile 'd:\oracle\oradata\recover\tools01.dbf' to

'e:\oracle\oradata\recover\tools01.dbf';

set newname for datafile 'd:\oracle\oradata\recover\indx01.dbf' to

'e:\oracle\oradata\recover\indx01.dbf';

restore database;

recover database noredo;

switch datafile all;

alter database open resetlogs;

}

Note that if the recovery is not successful but the files were restored successfully, the datafiles restored will become datafile copies and will not be removed.

In Oracle Database 11
g,
we can make this restore even easier by using the
set newname
command with the
for database
command to rename all database files in one command. You can also use the
set newname for tablespace
command if you wish to just rename datafiles associated with a given tablespace.

Chapter 12: RMAN Restore and Recovery
285

In conjunction with these new
set newname
commands, you must use substitution variables to avoid any collisions with filenames that might occur during the movement of the datafiles. The substitution variables are seen in Table 12-1.

Here is an example of using the
set newname for database
command that will result in the renaming of all datafiles of that database:

RUN

{

shutdown abort;

startup mount;

SET NEWNAME FOR DATABASE TO 'C:\oradata1\%b';

Restore database;

Recover database;

switch datafile all;

Alter database open;

}

If you just wanted to rename the files for a specific tablespace, you would change the
set
newname
command slightly, as seen in this example:

RUN

{

shutdown immediate;

startup mount;

SET NEWNAME FOR TABLESPACE user data TO 'c:\oradatanew\users\user data%b.dbf'; Restore database;

switch datafile all;

Recover database;

Alter database open;

}

Variable

Meaning

%b

This will result in the full filename without any directory path information.

%f

This will result in the absolute file number for the datafile.

%U

This will result in a system-generated filename guaranteed to be unique.

%I

This will result in the DBID of the database.

%N

This will result in the tablespace name.

TABLE 12-1
set newname
Substitution Variables

286
Part II: Setup Principles and Practices

RMAN Workshop:
Recover Your NOARCHIVELOG Mode

Database

Workshop Notes

For this workshop, you need an installation of the Oracle software and an operational test Oracle database.

NOTE

For this workshop, the database is in NOARCHIVELOG mode.

Step 1.
Set the ORACLE_SID and then log into RMAN. Ensure that you have configured automated backups of your control files. Because this is an offline backup, you need to shut down and mount the database:

set oracle sid recover

rman target rman backup/password

configure controlfile autobackup on;

shutdown immediate;

startup mount;

Note that in this case, we are accepting that the control file backup set pieces will be created in the default location.

Step 2.
Complete a cold backup of your system. In this workshop, we assume that the backup is to a configured default device:

backup database;

Step 3.
Shut down your database:

shutdown immediate;

Step 4.
Rename all database datafiles. Also rename the online redo logs and control files.

(Optionally, you can remove these files if you don’t have the space to rename them and if you really can afford to lose your database, should something go wrong.)

Step 5.
Startup nomount your database and restore your control file: startup nomount;

set DBID ;

restore controlfile from autobackup;

alter database mount;

Step 6.
Recover your database with RMAN using the backup you took in Step 2: restore database;

recover database noredo;

alter database open resetlogs;

Step 7.
Complete the recovery by backing up the database again:

shutdown immediate;

startup mount;

backup database;

Chapter 12: RMAN Restore and Recovery
287

NOTE

Other books

Solo Star by Cindy Jefferies
Killer Knots by Nancy J. Cohen
Scimitar Sun by Chris A. Jackson
The Bridal Veil by Alexis Harrington
The Wraiths of War by Mark Morris
Surrender by Metsy Hingle