Total Pageviews

Thursday 13 September 2012

Restore datafiles to a non-default location !!

You have just experienced a serious media failure and won't be able to restore datafiles to their original locations.In other words you need to restore to a non default location.

Use the set newname and switch commands to restore datafiles to nondefault locations.Both these commands will run from within RMAN run {} block.The below example changes the location of datafiles 4 and 5,which are in the data_ts tablespace.

SQL> set line 300
col file_name for a100
set heading off
select 'set newname for datafile ' || file_id || ' to ''/ora01_new_location/db/ora01_new_location/' ||
substr(file_name,instr(file_name,'/',-1)+1) || ''';'

from dba_data_files;SQL> SQL> SQL>   2    3



RMAN>connect target /
RMAN>startup mount
RMAN> run{
  > set newname for datafile 4 to '/ora01/db/data_file_new_name.dbf';
  > set newname for datafile 5 to /ora01_new_location/db/data_file_name.dbf';
  >restore tablespace data_ts;
  >switch datafile all #Updates repository with new datafile location
  >recover tablespace data_ts;
  >alter database open;
 }

If the database is open you can place the datafile offline and then set their new names for restore and recovery:

RMAN>  run{
  >SQL 'Alter database datafile 4,5 offline';
  > set newname for datafile 4 to '/ora01/db/data_file_new_name.dbf';
  > set newname for datafile 5 to /ora01_new_location/db/data_file_name.dbf';
  >restore datafile 4,5;
  >switch datafile all  # Updates repository with new datafile location
  >recover tablespace data_ts;
  > SQL 'Alter database datafile 4,5 online;
 }




No comments:

Post a Comment