Sunday, January 27, 2013

Step by Step - Duplicating Oracle Database using RMAN Backup with connection to Target database


Step by Step Duplicating Oracle Database using RMAN Backup with connection to Target database:-
Details:

Oracle EE 11.2 on RHEL5
Target Server: 192.168.195.128
Clone Server: 192.168.195.137

As we are duplicating to a different we can use same SID for both Source and Clone. My source DBID is HCL

Step1. Put your target database in Archive log mode.

Step2. Start RMAN at Target and Configure CONTROLFILE AUTOBACKUP ON
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

Take Backup of Target database
RMAN> BACKUP DATABASE PLUS ARCHIVELOG

Step3. Configure tnsnames and listener at source and clone server as below:

At Source Server
--------------------------------------------------------------------
HCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.137)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = HCL)
    )
  )
---------------------------------------------------------------------
At Clone Server
----------------------------------------------------------------------
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = HCL)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = HCL)
    )
  )


LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.195.137)(PORT = 1521))
  )
------------------------------------------------------------------------

Step4: create orapwd file at clone server's dbs directory
orapwd file=orapwHCL password=oracle entries=10

Step5. Create pfile of Target database and copy pfile to Clone Server's dbs directory
SQL> create pfile from spfile;

Copy pfile to Clone Server
scp oracle@192.168.195.128:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initHCL.ora /u01/app/oracle/product/11.2.0/dbhome_1/dbs/

Step6. Create required directories at Clone server. Here I'm using same filesystem as source so no need to use DB_FILE_NAME_CONVERT

mkdir -p /u01/app/oracle/oradata/HCL
mkdir -p /u01/app/oracle/flash_recovery_area/HCL
mkdir -p /u01/app/oracle/admin/HCL
cd /u01/app/oracle/admin/HCL
mkdir adump dpdump

Step7. Copy backupfile to Clone Server from Source Server
scp -r oracle@192.168.195.128:/u01/app/oracle/flash_recovery_area/HCL/ /u01/app/oracle/flash_recovery_area/

Step8. At Remote Server set ORACLE_SID=HCL and start the Clone Server in NOMOUNT mode
SQL> STARTUP NOMOUNT;

Step9: start RMAN at source and connect RMAN to clone as well
At Source
RMAN TARGET /
connect auxiliary sys/oracle@HCL

***Make sure your Souce Database is in OPEN mode and Clone DB is in NOMOUNT Mode

Now run the Duplicate command # See the response as well

RMAN> DUPLICATE TARGET DATABASE TO HCL
NOFILENAMECHECK;2>

Starting Duplicate Db at 27-JAN-13
using channel ORA_AUX_DISK_1

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''HCL'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''HCL'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile;
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''HCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''HCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     631914496 bytes

Fixed Size                     1338364 bytes
Variable Size                377488388 bytes
Database Buffers             247463936 bytes
Redo Buffers                   5623808 bytes

Starting restore at 27-JAN-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=18 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/HCL/autobackup/2013_01_27/o1_mf_s_805812962_8j9onctk_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/HCL/autobackup/2013_01_27/o1_mf_s_805812962_8j9onctk_.bkp tag=TAG20130127T125602
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/app/oracle/oradata/HCL/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/HCL/control02.ctl
Finished restore at 27-JAN-13

database mounted

contents of Memory Script:
{
   set until scn  763666;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/HCL/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/HCL/sysaux01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/HCL/undotbs01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/HCL/users01.dbf";
   restore
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 27-JAN-13
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/HCL/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/HCL/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/HCL/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/HCL/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/HCL/backupset/2013_01_27/o1_mf_nnndf_TAG20130127T125432_8j9okjyl_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/HCL/backupset/2013_01_27/o1_mf_nnndf_TAG20130127T125432_8j9okjyl_.bkp tag=TAG20130127T125432
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:22
Finished restore at 27-JAN-13

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=805814774 file name=/u01/app/oracle/oradata/HCL/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=805814774 file name=/u01/app/oracle/oradata/HCL/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=805814774 file name=/u01/app/oracle/oradata/HCL/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=805814774 file name=/u01/app/oracle/oradata/HCL/users01.dbf

contents of Memory Script:
{
   set until scn  763666;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 27-JAN-13
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oracle/flash_recovery_area/HCL/archivelog/2013_01_27/o1_mf_1_4_8j9on8j1_.arc
archived log file name=/u01/app/oracle/flash_recovery_area/HCL/archivelog/2013_01_27/o1_mf_1_4_8j9on8j1_.arc thread=1 sequence=4
media recovery complete, elapsed time: 00:00:00
Finished recover at 27-JAN-13

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
   sql clone "alter system set  db_name =
 ''HCL'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     631914496 bytes

Fixed Size                     1338364 bytes
Variable Size                377488388 bytes
Database Buffers             247463936 bytes
Redo Buffers                   5623808 bytes

sql statement: alter system set  db_name =  ''HCL'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     631914496 bytes

Fixed Size                     1338364 bytes
Variable Size                377488388 bytes
Database Buffers             247463936 bytes
Redo Buffers                   5623808 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "HCL" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1  SIZE 50 M ,
  GROUP  2  SIZE 50 M ,
  GROUP  3  SIZE 50 M
 DATAFILE
  '/u01/app/oracle/oradata/HCL/system01.dbf'
 CHARACTER SET WE8MSWIN1252


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/HCL/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/HCL/sysaux01.dbf",
 "/u01/app/oracle/oradata/HCL/undotbs01.dbf",
 "/u01/app/oracle/oradata/HCL/users01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/HCL/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/HCL/sysaux01.dbf RECID=1 STAMP=805814812
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/HCL/undotbs01.dbf RECID=2 STAMP=805814812
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/HCL/users01.dbf RECID=3 STAMP=805814812

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=805814812 file name=/u01/app/oracle/oradata/HCL/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=805814812 file name=/u01/app/oracle/oradata/HCL/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=805814812 file name=/u01/app/oracle/oradata/HCL/users01.dbf

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 27-JAN-13

RMAN>





4 comments:

  1. nice work done it is very helpful for me.............

    ReplyDelete
  2. Hi, it was nice I have one doubt suppose I am doing cloning due some reason stop how start any procedure please let me know.

    ReplyDelete
  3. Such a nice blog, I really like what you write in this blog, I also have some relevant Information about Best HR Training In Hyderabad | Hr training institute in Hyderabad! if you want more information.
    Workday Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training
    Oracle Fusion Financials Online Training

    ReplyDelete