Tuesday 11 December 2012

RMAN CLONING 10g /11g

10G Same Machine But Different Directories 

create a directory to the destination location like

Source Directory D:\oracle\product\10.2.0\oradata\orcl
DBNAME: ORCL

Destination Directory E:\orcld\
DBNAME: ORCLD
bdump
cdump
adump
udump
Archive
flash_recovery_area

-----Source:-----
create pfile from spfile;

rman target 'sys/oracle@orcl'
backup database plus archivelog;

-----Destination-----
change the dbname & destination in pfile

create a service of destination database ORCLD
oradim -new -sid orcld -startmode manual -initpwd oracle

listener & services create

sqlplus sys/oracle@orcld as sysdba
create spfile from pfile=' ';
startup nomount

rman target 'sys/oracle@orcl' nocatalog auxiliary='sys/oracle@orcld'
duplicate target database to orcld;


========================================================================

Without Connection To Target DataBase like(not tns configure etc.)
Clone Two Different Machine But Both Side Are Same Platform

In linux create NFS first because same location backup.

I'll give you small demontration on
1st Windows Server 2003 (192.168.xx.1) DBNAME: orcl
2nd  Windows XP (192.168.xx.2) DBNAME: orcld

1.) Create full database on 1st machine with all setup listener & services
Some command perform its recommend because of any accident
alter database backup controlfile to tace as 'D:\Control.txt' ;
create pfile='D:\initorcl.ora' from spfile;

rman target 'sys/oracle@orcl'
configure channel device type disk format 'D:\Backup\%d_%U';
backup database;
sql 'alter system archive log current';
backup archivelog all;
backup current controlfile;
list backup

copy (D:\Backup) directory with backup & paste on target machine (D:\)
i.e 1st machine to 2nd machine location & same directory move the backup.

Configure  2nd machine service connection on 1st machine.


2.) Go 2nd machine
create a Pfile and change the location of some directories

Destination Directory E:\orcld\
DBNAME: ORCLD
bdump
cdump
adump
udump
Archive
flash_recovery_area

set two parameter in pfile its must
*.db_file_name_convert=('d:\oracle\product\10.2.0\oradata\orcl\','e:\orcld\')
*.log_file_name_convert=('d:\oracle\product\10.2.0\oradata\orcl\','e:\orcld\')


create a service of destination database ORCLD
oradim -new -sid orcld -startmode manual -initpwd oracle

Configure Listener & service

set oracle_sid=orcld
sqlplus sys/oracle@orcld as sysdba
create spfile from pfile='E:\initorcld.ora';
startup nomount

3.) 1.st machine
rman target 'sys/oracle@orcl' nocatalog auxiliary 'sys/oracle@orcld'
duplicate target database to orcld;

Enjoy with rman cloning.........?
12:36 AM 12/11/2012



========================================================================

11G



Unix system:

set IP source and target
vim /etc/host
192.168.xx.xx source.com source
192.168.xx.xx target.com target



·         Creating initialization Parameter file for the Duplicate database
If you are using spfile then only parameter required for the duplicate database is DB_NAME. Rest other parameters can be set in the duplicate command itself. If you are not using the spfile , then you need to set initialization parameters in the pfile.
Required parameters:





DB_NAME
CONTROL_FILES
DB_BLOCK_SIZE
DB_FILE_NAME_CONVERT
LOG_FILE_NAME_CONVERT
We will create a pfile with the above parameters for the duplicate database.Create an Oracle Password File for the Duplicate database.
I will make the Duplicate database  name as  “DUP”
Password file is must for the Active database duplication where as it is not required for backup-based duplication. For Active database duplication it connects directly to the auxiliary instance using the password file with the same SYSDBA password as target database. In case you are using password file make sure to have same SYSDBA password as the target database. In this case, RMAN copies the source database password file to the destination host and overwrites any existing password file for the auxiliary instance.


cd $ORACLE_HOME/dbs

orapwd password=ORCL file=orapwDUP

·         Establish Oracle Net Connectivity to the Auxiliary Instance
Auxiliary instance must be available through Oracle Net if you are duplicating from an ACTIVE database.
Add following entries into listener.ora file.
Edit the listener.ora and add following lines:








SID_LIST_LISTENER =
 (SID_LIST =
 )
 (SID_DESC =
 (SID_NAME = dup)
 (ORACLE_HOME = =/home/oracle/app/oracle/product/11.2.0/dbhome_1)
 (GLOBAL_DBNAME = dup.localdomain)
 )
 )
Add the Following entry in the tnsnames.ora
















prd =
 (DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
 (CONNECT_DATA =
 (SERVER = DEDICATED)
 (SERVICE_NAME = prd)
 )
 )

dup =
 (DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
 (CONNECT_DATA =
 (SERVER = DEDICATED)
 (SERVICE_NAME = dup)
 )
 )
·         Create the directories which are required for the duplicate database.


mkdir -p /home/oracle/app/oracle/oradata/dup
mkdir -p /home/oracle/app/oracle/fast_recovery_area/dup
mkdir -p /home/oracle/app/oracle/admin/dup/pfile

·         Create the parameter file (initdup.ora).






DB_NAME=dup
diagnostic_dest='/home/oracle/app/oracle'
DB_FILE_name_CONVERT=('/home/oracle/app/oracle/oradata/prd','/home/oracle/app/oracle/oradata/dup')
LOG_FILE_NAME_CONVERT=('/home/oracle/app/oracle/oradata/prd','/home/oracle/app/oracle/oradata/dup')
Memory_TARGET=262144000
CONTROL_FILES='/home/oracle/app/oracle/oradata/dup/control01.dbf'
COMPATIBLE= 11.2.0.0.0

·         Start the Auxiliary instance from Sqlplus
Use SQL*Plus to connect to the auxiliary instance using the above created pfile and start it in NOMOUNT mode.





















[oracle@localhost admin]$ export ORACLE_SID=dup
[oracle@localhost admin]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Fri Mar 1 12:40:21 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup nomount pfile=/home/oracle/app/oracle/admin/dup/pfile/initdup.ora

ORACLE instance started.

Total System Global Area 372449280 bytes
Fixed Size 1345044 bytes
Variable Size 234883564 bytes
Database Buffers 130023424 bytes
Redo Buffers 6197248 bytes

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 -
Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

·         Test connectivity to auxiliary and target instance from the Both Sides.



sqlplus sys/ORCL@PRD as sysdba

sqlplus sys/ORCL@DUP as sysdba

·         Using RMAN, Connect to the Database Instances

[oracle@localhost admin]$ rman target sys/ORCL@prd catalog rman/rman@prd

Recovery Manager: Release 11.2.0.3.0 - Production on Fri Mar 1 12:41:24 2013 
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. 
connected to target database: PRD (DBID=1867953957)
connected to recovery catalog database

RMAN> connect auxiliary sys/ORCL@DUP

connected to auxiliary database: DUP (not mounted)

RMAN> DUPLICATE TARGET DATABASE TO 'DUP' FROM ACTIVE DATABASE
 DB_FILE_NAME_CONVERT '/home/oracle/app/oracle/oradata/prd','/home/oracle/app/oracle/oradata/dup';

Starting Duplicate Db at 01-MAR-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK

contents of Memory Script:
{
 sql clone "create spfile from memory";
}
executing Memory Script

sql statement: create spfile from memory

contents of Memory Script:
{
 shutdown clone immediate;
 startup clone nomount;
}
executing Memory Script

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 372449280 bytes

Fixed Size 1345044 bytes
Variable Size 239077868 bytes
Database Buffers 125829120 bytes
Redo Buffers 6197248 bytes

contents of Memory Script:
{
 sql clone "alter system set db_name =
 ''PRD'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
 sql clone "alter system set db_unique_name =
 ''DUP'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
 shutdown clone immediate;
 startup clone force nomount
 backup as copy current controlfile auxiliary format
'/home/oracle/app/oracle/oradata/dup/control01.ctl';
 alter clone database mount;
}
executing Memory Script

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

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

Oracle instance shut down

Oracle instance started

Total System Global Area 372449280 bytes

Fixed Size 1345044 bytes
Variable Size 239077868 bytes
Database Buffers 125829120 bytes
Redo Buffers 6197248 bytes

Starting backup at 01-MAR-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 device type=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output file
name=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_prd.f
tag=TAG20130301T124259 RECID=9 STAMP=808922591
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:26
Finished backup at 01-MAR-13

database mounted

contents of Memory Script:
{
 set newname for datafile 1 to
 "/home/oracle/app/oracle/oradata/dup/system01.dbf";
 set newname for datafile 2 to
 "/home/oracle/app/oracle/oradata/dup/sysaux01.dbf";
 set newname for datafile 3 to
 "/home/oracle/app/oracle/oradata/dup/undotbs01.dbf";
 set newname for datafile 4 to
 "/home/oracle/app/oracle/oradata/dup/users01.dbf";
 set newname for datafile 5 to
 "/home/oracle/app/oracle/oradata/dup/example01.dbf";
 set newname for datafile 6 to
 "/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf";
 backup as copy reuse
 datafile 1 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/system01.dbf" datafile
 2 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/sysaux01.dbf" datafile
 3 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/undotbs01.dbf" datafile
 4 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/users01.dbf" datafile
 5 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/example01.dbf" datafile
 6 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf" ;
 sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 01-MAR-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001
name=/home/oracle/app/oracle/oradata/prd/system01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/system01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:06:38
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002
name=/home/oracle/app/oracle/oradata/prd/sysaux01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/sysaux01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:06:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005
name=/home/oracle/app/oracle/oradata/prd/example01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/example01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:05:18
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003
name=/home/oracle/app/oracle/oradata/prd/undotbs01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/undotbs01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006
name=/home/oracle/app/oracle/oradata/prd/rmantbs01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:04
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004
name=/home/oracle/app/oracle/oradata/prd/users01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/users01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 01-MAR-13

sql statement: alter system archive log current

contents of Memory Script:
{
 backup as copy reuse
 archivelog like
"/home/oracle/app/oracle/fast_recovery_area/PRD/archivelog/2013_03_01/o1_mf_1_26_8m0pf583_.arc"
auxiliary format
 "/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf"
;
 catalog clone archivelog
"/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf";
 switch clone datafile all;
}
executing Memory Script

Starting backup at 01-MAR-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=26 RECID=26 STAMP=808923777
output file
name=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf
RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:07
Finished backup at 01-MAR-13

cataloged archived log
archived log file
name=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf
RECID=26 STAMP=808923794

datafile 1 switched to datafile copy
input datafile copy RECID=9 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=10 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=11 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=13 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/example01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=14 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf

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

executing command: SET until clause

Starting recover at 01-MAR-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK

starting media recovery

archived log for thread 1 with sequence 26 is already on disk as file
/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf
archived log file
name=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf
thread=1 sequence=26
media recovery complete, elapsed time: 00:00:02
Finished recover at 01-MAR-13
Oracle instance started

Total System Global Area 372449280 bytes

Fixed Size 1345044 bytes
Variable Size 239077868 bytes
Database Buffers 125829120 bytes
Redo Buffers 6197248 bytes

contents of Memory Script:
{
 sql clone "alter system set db_name =
 ''DUP'' 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

sql statement: alter system set db_name = ''DUP'' 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 372449280 bytes

Fixed Size 1345044 bytes
Variable Size 239077868 bytes
Database Buffers 125829120 bytes
Redo Buffers 6197248 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS
ARCHIVELOG
 MAXLOGFILES 16
 MAXLOGMEMBERS 3
 MAXDATAFILES 100
 MAXINSTANCES 8
 MAXLOGHISTORY 292
 LOGFILE
 GROUP 1 ( '/home/oracle/app/oracle/oradata/dup/redo01.log' ) SIZE 50 M
REUSE,
 GROUP 2 ( '/home/oracle/app/oracle/oradata/dup/redo02.log' ) SIZE 50 M
REUSE,
 GROUP 3 ( '/home/oracle/app/oracle/oradata/dup/redo03.log' ) SIZE 50 M
REUSE
 DATAFILE
 '/home/oracle/app/oracle/oradata/dup/system01.dbf'
 CHARACTER SET AL32UTF8
contents of Memory Script:
{
 set newname for tempfile 1 to
 "/home/oracle/app/oracle/oradata/dup/temp01.dbf";
 switch clone tempfile all;
 catalog clone datafilecopy
"/home/oracle/app/oracle/oradata/dup/sysaux01.dbf",
 "/home/oracle/app/oracle/oradata/dup/undotbs01.dbf",
 "/home/oracle/app/oracle/oradata/dup/users01.dbf",
 "/home/oracle/app/oracle/oradata/dup/example01.dbf",
 "/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf";
 switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /home/oracle/app/oracle/oradata/dup/temp01.dbf in
control file

cataloged datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/dup/sysaux01.dbf
RECID=1 STAMP=808923861
cataloged datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/dup/undotbs01.dbf
RECID=2 STAMP=808923861
cataloged datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/dup/users01.dbf
RECID=3 STAMP=808923861
cataloged datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/dup/example01.dbf
RECID=4 STAMP=808923861
cataloged datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf
RECID=5 STAMP=808923861

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=808923861 file
name=/home/oracle/app/oracle/oradata/dup/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=808923861 file
name=/home/oracle/app/oracle/oradata/dup/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=808923861 file
name=/home/oracle/app/oracle/oradata/dup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=808923861 file
name=/home/oracle/app/oracle/oradata/dup/example01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=808923861 file
name=/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf

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

database opened
Finished Duplicate Db at 01-MAR-13
Duplicate database is successfully created.


NOTE: If You are not connect to target node and no catalog database use the following  some step




– CREATE PFILE FROM SOURCE DATABASE

SQL>CREATE PFILE=’/home/oracle/stage/initsource.ora’    FROM SPFILE;

*****************
 on the target host.
*****************

– Make a staging folder for backups and pfile
oracle@dest$mkdir -p /home/oracle/stage

– create other required  folders
 $mkdir -p /u01/app/oracle/oradata/orclt
  mkdir -p /u01/app/oracle/flash_recovery_area/orclt
  mkdir -p /u01/app/oracle/admin/orclt/adump
  mkdir -p /u01/app/oracle/admin/orclt/dpdump

– Copy backup files from the source host
 # scp source:/home/oracle/stage/*.bak /home/oracle/stage/

– Copy pfile of source database (orcl)
 # scp source:/home/oracle/stage/initsource.ora /home/oracle/stage/inittarget.ora

– Copy the password file as well 
$ scp /u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl  /u01/app/oracle/product/11.2.0/db_1/dbs/orapworclt

– Add a line in the file /etc/oratab to reflect the database instance you are going to  copy:
orclt:/u01/app/oracle/product/11.2.0/db1:N

– Edit the initialization parameter file from the main database.
$vi /home/oracle/stage/inittarget.ora



DB_NAME
CONTROL_FILES
DB_BLOCK_SIZE
DB_FILE_NAME_CONVERT
LOG_FILE_NAME_CONVERT


– Now set the Oracle SID as the duplicated database SID:
$ . oraenv
ORACLE_SID = [orclt] ?

– Startup the target database in nomount mode using modified parameter file
$sqlplus sys/oracle as sysdba
SQL> startup nomount pfile=’/u01/app/oracle/oradata/orclt/inittarget.ora';
     create spfile from pfile=’/u01/app/oracle/oradata/orclt/inittarget.ora';

- Using RMAN  connect to the  duplicate database (orclt) as auxiliary instance
$. oraenv
   orclt
$rman auxiliary /

– duplicate the database orcl to orclt
– the command performs the following steps:
    * Creates an SPFILE
    * Shuts down the instance and restarts it with the new spfile
    * Restores the controlfile from the backup
    * Mounts the database
    * Performs restore of the datafiles. In this stage it creates the files in the
      converted names.
    * Recovers the datafiles up to the time specified and opens the database

– If duplicate database has the same directory structure as source (on a different host)
RMAN>duplicate target database to orclt backup location ‘/home/oracle/stage/’ nofilenamecheck;
OR

– If duplicate database has different directory structure from source
RMAN>duplicate target database to orclt backup location ‘/home/oracle/stage/’ ;
– check that duplicate database is up
$sqlplus / as sysdba
sql>conn hr/hr
    select * from tab;

– Note that  DBID is different from the main database so it can be backed up
   independently and using the same catalog as well.
SQL> select dbid from v$database;
     conn sys/oracle@orcl as sysdba
     select dbid from v$database;




 Reference:


http://oraclegurukul.blogspot.in/2015/12/database-refresh-cloning.html
http://www.pythian.com/blog/duplicate-from-active-database-using-rman-step-by-step/