Saturday 26 November 2011

Restore RMAN full backup to different server with different directory structure

Restore RMAN full backup to different server with same database name but different directory structure::


In this article we are going to learn, how to restore RMAN full backup to a different server with same database name but different directory structure.



Overview:
This article is a comprehensive guide for restoring RMAN full backup to a different server with same database name but different directory structure.
Please do keep in mind that this article should not be considered a substitution of the official guide from Oracle (http://www.oracle.com). The below mentioned link can be used to download the official documentation for RMAN Recovery Techniques.
Names used in this article:
 Name  Value
 Database Name  mydb
 Backup Folder on Node1  c:\rman_bck
 Backup Folder on Node2  c:\rman_bck
 Database (Datafile/Controlfile/redolog) Folder on Node1  ORACLE_BASE\oradata\mydb
 Database (Datafile/Controlfile/redolog) Folder on Node2  ORACLE_BASE\oradata\mydbtest





 Connect to the database:

Open command prompt and type the below mentioned:
cmd> set ORACLE_SID=mydb
cmd> sqlplus / as sysdba
Create initialization parameter file (pfile).
sql>create pfile from spfile ;



Take Full Backup of Database using RMAN:
Open command prompt and type the below mentioned:
cmd> rman target /
We can configure the backup location (if not configured earlier). For configuring backup location type the following command:
RMAN> configure channel device type disk format 'C:\rman_bck\mydb_%U' ;


For taking backup of the database, fire the below mentioned command:
RMAN> backup database plus archivelog ;


  For the screenshots of the procedure please visit the link::: http://www.sensehaze.com


Copy the required files to the other node:
Copy the below mentioned files to the other node:
--The backup pieces generated using RMAN.
--The initalization parameter file( created above).
--The password file( We can create it also on the other node).


Create database directory structure on other node:
Create "oradata/mydbtest" directory on the other node ( for storing controlfiles,datafiles,redo logfiles ). Also create Archive Destination Directory.



Create Service/instance on other node:
Note:This step needs to be performed only on Windows O/S.
Create a service( Here in my case my datbase name -- mydb ).For creating service use "oradim" utility. As mentioned below:
cmd> oradim -new -sid mydb -intpwd sys -startmode manual

 After creating the service, change its startmode to automatic. For doing so go to "windows services" and change its startmode to automatic.


Edit PFILE on the other node:
Edit the PFILE and change the location of control_files/audit_file_dest as per the new directory structure on the other node.


Start the database in nomount mode on other node:
Open command prompt and type the below mentioned commands:
cmd> set ORACLE_SID=mydb
cmd> sqlplus / as sysdba
Start database with PFILE:
sql> startup nomount pfile='full_path_of_pfile' ;




Invoke RMAN on other node:
Open command prompt and type the below mentioned:
cmd> rman target /
Restore Controlfile:
Restore the controlfile from the backup pieces as mentioned below:
RMAN> restore controlfile from 'full_path_control_file_bck_piece' ;


Mount the Database:
After restoring the controlfile from the backuppieces mount the database :
RMAN> alter database mount ;

Rename the Redologfiles:
After mounting the database, Rename the Redologfiles,so that they can be created in new locations when the database is opened with resetlogs option, For renaming the redologs open a new command prompt and connect to the database from that prompt, as mentioned below:

On the second Node (Node2)
SQL> alter database rename file 'redo_file_loc_first_node\redo01.log' to 'redo_file_loc_second_node\redo01.log';
SQL> alter database rename file 'redo_file_loc_first_node\redo02.log' to 'redo_file_loc_second_node\redo02.log';
.....................
SQL> alter database rename file 'redo_file_loc_first_node\redoN.log' to 'redo_file_loc_second_node\redoN.log';

  For the screenshots of the procedure please visit the link::: http://www.sensehaze.com


Get the Datafile Info of Node 1:
Connect to the database of Node 1 and query the "DBA_DATA_FILES" for datafiles info, as mentioned below:
SQL> select file_id , file_name from dba_data_files ;


Restore and Recover the Database:
After collecting datafile information of Node 1, Now restore the datafiles to new locations and recover ( On Node2 ), as mentioned below:
RMAN> run {
set newname for datafile 1 to 'datafile_loc_node2\system01.dbf' ;
set newname for datafile 2 to 'datafile_loc_node2\sysaux01.dbf' ;
set newname for datafile 3 to 'datafile_loc_node2\undotbs01.dbf' ;
set newname for datafile 4 to 'datafile_loc_node2\user01.dbf' ;
set newname for datafile 5 to 'datafile_loc_node2\tools.dbf' ;
................ //mention all the datafiles

restore database ;
switch datafile all ;
recover database ;
}



If it show error ("media recovery requesting unknown archived log") that means, it requires the new archivelogs, copy the new archivelogs from node1 to node2 and rerurn the above command "recover database". (We can ignore this error).

Open the Database with Resetlogs:
After that, open the database with resetlogs options. As mentioned below:
RMAN> alter database open resetlogs;


Connect to the database & create spfile:
After that, Connect to the database and create spfile. As mentioned below:
cmd> sqlplus / as sysdba
SQL> create spfile from pfile='pfile_location';


This finishes restoring RMAN full backup to a different server with same database name but different directory structure.









6 comments:

  1. hi, Question is your backup (database backup on the same location or different location in this process, i was trying to do the same thing, but in my case it throws the error backup expired.

    Jaskirat Singh
    jaskirat.1982@gmail.com

    ReplyDelete
    Replies
    1. Hi Jaskirat,

      In this article my backup location directory structure of both the nodes are same.

      For the screenshots of the steps you can go to the below link:
      http://www.sensehaze.com/index.php/oracle-database/81-backup-recovery/95-rman-rstr-diff-dirstruct

      If you are getting the same error again, then please share the error message(s).

      Delete
  2. Hi,

    I read ur article and its good. I have one doubt In my Prod DB around 150 datafiles are present and its running in ASM. Every month we did DB refresh from other environment and its running Non-ASM using this prod backup.So Its very hard to type set newname command for each and every datafiles.Is there any other alternative way like using DB_file_name_convert and log_file_name_convert parameter Instead of set newname..? But I've used this parameter only RMAN cloning.

    ReplyDelete
    Replies
    1. Vinothkanna, did you try?

      BACKUP AS COPY DATABASE FORMAT '+DISK_GROUP_ABC';
      switch database to copy;

      Delete
  3. RMAN> alter database mount

    RMAN-03002: failure of alter db command at 10/26/2017 16:56:24
    ORA-01103: database name 'ORCL' in control file is not 'NEWDB'

    ReplyDelete
  4. Hi, I followed your post and was able to recover database.
    Thank you

    ReplyDelete