Database Reference
In-Depth Information
Step 11. Rename and Restore the Data Files to Reflect New
Directory Locations
If your destination server has the exact same directory structure as the original server directories, you can issue the
RESTORE
command directly:
RMAN> restore database;
However, when restoring data files to locations that are different from the original directories, you'll have to use
the
SET NEWNAME
command. Create a file that uses an RMAN
run{}
block that contains the appropriate
SET NEWNAME
and
RESTORE
commands. I like to use an SQL script that generates SQL to give me a starting point. Here is a sample
script:
set head off feed off verify off echo off pages 0 trimspool on
set lines 132 pagesize 0
spo newname.sql
--
select 'run{' from dual;
--
select
'set newname for datafile ' || file# || ' to ' || '''' || name || '''' || ';'
from v$datafile;
--
select
'restore database;' || chr(10) ||
'switch datafile all;' || chr(10) ||
'}'
from dual;
--
spo off;
After running the script, these are the contents of the
newname.sql
script that was generated:
run{
set newname for datafile 1 to '/u01/dbfile/O12C/system01.dbf';
set newname for datafile 2 to '/u01/dbfile/O12C/sysaux01.dbf';
set newname for datafile 3 to '/u01/dbfile/O12C/undotbs01.dbf';
set newname for datafile 4 to '/u01/dbfile/O12C/users01.dbf';
restore database;
switch datafile all;
}
Then, modify the contents of the
newname.sql
script to reflect the directories on the destination database server.
Here is what the final
newname.sql
script looks like for this example:
run{
set newname for datafile 1 to '/ora01/dbfile/DEVDB/system01.dbf';
set newname for datafile 2 to '/ora01/dbfile/DEVDB/sysaux01.dbf';
set newname for datafile 3 to '/ora01/dbfile/DEVDB/undotbs01.dbf';
set newname for datafile 4 to '/ora01/dbfile/DEVDB/users01.dbf';
restore database;
switch datafile all;
}