You are on page 1of 11

Cloning

1 Cold Cloning
1> Shutdown production database.
SQL> shut immediate

2> Copy the datafile to cold backup location.


$ cp *.dbf /u02/app/cold

3> Create the new server or directory structure.


$ mkdir alpha1
$ cd alpha1
$ mkdir admin oradata
$ cd admin
$ mkdir diag arch scripts

4> Start the production database.


SQL> startup;

5> Create the parameter file from clone database (alpha1)


$ cd $ORACLE_HOME/dbs
$ cp initalpha.ora initalpha1.ora
$ vi initalpha1.ora
compatible='11.2.0.4.0'
control_files='/u02/app/alpha1/oradata/control01.ctl','/u02/app/alpha1/oradata/control02.ctl'
db_block_size=8192
db_domain=''
db_name='alpha1'
diagnostic_dest='/u02/app/alpha1/admin/diag'
dispatchers='(PROTOCOL=TCP) (SERVICE=alphaXDB)'
log_archive_dest_1='LOCATION=/u02/app/alpha1/admin/arch'
memory_target=419430400
open_cursors=300
processes=150
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'

6> Take controlfile tarce backup and edit the controlfile trace backup.
SQL> alter database backup controlfile to trace as '/u02/app/cold/alpha1.ctl';
$ cd /u02/app/cold/
$ vi alpha1.ctl for cloning always take RESETLOGS portion
CREATE CONTROLFILE SET DATABASE "ALPHA1" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u02/app/alpha1/oradata/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u02/app/alpha1/oradata/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u02/app/alpha1/oradata/redo03.log' SIZE 50M BLOCKSIZE 512
DATAFILE
'/u02/app/alpha1/oradata/system01.dbf',
'/u02/app/alpha1/oradata/sysaux01.dbf',
'/u02/app/alpha1/oradata/undotbs01.dbf',
'/u02/app/alpha1/oradata/users01.dbf'
CHARACTER SET WE8MSWIN1252
;

7> Copy the backup to the new server or new directory structure on same server.
$ cp *.dbf /u02/app/alpha1/oradata

8> Startup nomount the clone database (alplha1)


SQL> startup nomount;

9> Run the trace file from clone database (alpha1)


SQL> @/u02/app/cold/alpha1.ctl

10> Open the database in resetlogs.


SQL> alter database open resetlogs;
SQL> select name,open_mode from v$database;

NAME OPEN_MODE
--------- --------------------
ALPHA1 READ WRITE
SQL> select file_name from dba_data_files;

11> Create the temp file/tablespace

2 Hot Cloning

1> Database must be in archivelog mode.

2> Create the new server or directory structure on the same server.
$ mkdir alpha2
$ cd alpha2
$ mkdir admin oradata
$ cd admin
$ mkdir arch diag scripts

3> Put the database in backup mode.


SQL> alter database begin backup;
4> Copy the datafile to hot backup location.
$ cp /u02/app/oracle/oradata/alpha/*.dbf .

5> End the backup mode


SQL> alter database end backup;
SQL> alter system archive log current;

6> Take controlfile tarce backup and edit the controlfile trace backup.
SQL> alter database backup controlfile to trace as '/u02/app/hot/alpha2.ctl';
$ vi alpha2.ctl
CREATE CONTROLFILE SET DATABASE "ALPHA2" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u02/app/alpha2/oradata/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u02/app/alpha2/oradata/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u02/app/alpha2/oradata/redo03.log' SIZE 50M BLOCKSIZE 512
DATAFILE
'/u02/app/alpha2/oradata/system01.dbf',
'/u02/app/alpha2/oradata/sysaux01.dbf',
'/u02/app/alpha2/oradata/undotbs01.dbf',
'/u02/app/alpha2/oradata/users01.dbf'
CHARACTER SET WE8MSWIN1252
;

7> Create parameter file for clone database i.e alpha2.


$ cp initalpha1.ora initalpha2.ora
$ vi initalpha2.ora
compatible='11.2.0.4.0'
control_files='/u02/app/alpha2/oradata/control01.ctl','/u02/app/alpha2/oradata/control02.ctl'
db_block_size=8192
db_domain=''
db_name='alpha2'
diagnostic_dest='/u02/app/alpha2/admin/diag'
dispatchers='(PROTOCOL=TCP) (SERVICE=alphaXDB)'
log_archive_dest_1='LOCATION=/u02/app/alpha2/admin/arch'
memory_target=400m
open_cursors=300
processes=150
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'

8> Copy the backup to the new server or new directory structure on same server.
$ cp /u02/app/hot/*.dbf .
9> Copy the archive log file to clone database.
$ cd /u02/app/oracle/arch
$ cp *.* /u02/app/alpha2/admin/arch

10> Startup nomount database.


SQL> startup nomount;

11> Create controlfile by using trace file.


SQL> @/u02/app/hot/alpha2.ctl

12> Recover database as it is hot backup.


SQL> recover database using backup controlfile until cancel;
Keep on giving the archive log.
After all archive finished then give CANCEL

13> Open the database


SQL> alter database open resetlogs;
SQL> select name, open_mode from v$database;
NAME OPEN_MODE
--------- --------------------
ALPHA2 READ WRITE
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/u02/app/alpha2/oradata/users01.dbf
/u02/app/alpha2/oradata/undotbs01.dbf
/u02/app/alpha2/oradata/sysaux01.dbf
/u02/app/alpha2/oradata/system01.dbf

14> Create the temp file/tablespace

3 RMAN Cloning with DUPLICATE command

1>Take RMAN full backup of production database.


$ rman target /
RMAN> backup database include current controlfile plus archivelog format '/u02/app/rman/%U';

2> Create the new server or directory structure on the same server.
$ cd /u02/app
$ mkdir alpha3
$ cd alpha3
$ mkdir oradata admin
$ cd admin
$ mkdir arch scripts rman
3> Create parameter file for clone database i.e alpha3.
$ cp initalpha1.ora initalpha3.ora
$ vi initalpha3.ora
compatible='11.2.0.4.0'
control_files='/u02/app/alpha3/oradata/control01.ctl','/u02/app/alpha3/oradata/control02.ctl'
db_block_size=8192
db_domain=''
db_name='alpha3'
diagnostic_dest='/u02/app/alpha3/admin/diag'
dispatchers='(PROTOCOL=TCP) (SERVICE=alphaXDB)'
log_archive_dest_1='LOCATION=/u02/app/alpha3/admin/arch'
memory_target=400m
open_cursors=300
processes=150
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
db_file_name_convert=
log_file_name_convert=

4> Create listener and start the same and also create tnsentry
ALPHA3 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.112)(PORT = 1521))
)
SID_LIST_ALPHA3 =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = alpha3)
(ORACLE_HOME = /u02/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = alpha3)
)
)
$ lsnrctl start alpha3

ALPHA3 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.112)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = alpha3)
)
)
$ tnsping alpha3

5> Create password file


$ orapwd file=orapwalpha3 password=critical entries=4
6> Startup nomount the clone database i.e alpha3
SQL> startup nomount;

7> On production
$ export ORACLE_SID=alpha
$ rman target / auxiliary sys/critical@alpha3
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Oct 17 01:57:10 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ALPHA (DBID=2652216798)
connected to auxiliary database: ALPHA3 (not mounted)

8> RMAN> duplicate target database to alpha3;


Starting Duplicate Db at 17-OCT-16
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 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 417546240 bytes
Fixed Size 2253824 bytes
Variable Size 327158784 bytes
Database Buffers 83886080 bytes
Redo Buffers 4247552 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''ALPHA'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''ALPHA3'' 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 = ''ALPHA'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''ALPHA3'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 417546240 bytes
Fixed Size 2253824 bytes
Variable Size 327158784 bytes
Database Buffers 83886080 bytes
Redo Buffers 4247552 bytes
Starting restore at 17-OCT-16
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 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 /u02/app/oracle/product/11.2.0/dbhome_1/dbs/03rii19k_1_1
channel ORA_AUX_DISK_1: piece handle=/u02/app/oracle/product/11.2.0/dbhome_1/dbs/03rii19k_1_1 tag=TAG20161017T011851
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:08
output file name=/u02/app/alpha3/oradata/control01.ctl
output file name=/u02/app/alpha3/oradata/control02.ctl
Finished restore at 17-OCT-16
database mounted
contents of Memory Script:
{
set until scn 990002;
set newname for datafile 1 to
"/u02/app/alpha3/oradata/system01.dbf";
set newname for datafile 2 to
"/u02/app/alpha3/oradata/sysaux01.dbf";
set newname for datafile 3 to
"/u02/app/alpha3/oradata/undotbs01.dbf";
set newname for datafile 4 to
"/u02/app/alpha3/oradata/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 17-OCT-16
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 /u02/app/alpha3/oradata/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u02/app/alpha3/oradata/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u02/app/alpha3/oradata/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u02/app/alpha3/oradata/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/app/oracle/product/11.2.0/dbhome_1/dbs/02rii17r_1_1
channel ORA_AUX_DISK_1: piece handle=/u02/app/oracle/product/11.2.0/dbhome_1/dbs/02rii17r_1_1 tag=TAG20161017T011851
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 17-OCT-16
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy


input datafile copy RECID=5 STAMP=925437626 file name=/u02/app/alpha3/oradata/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=925437626 file name=/u02/app/alpha3/oradata/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=925437626 file name=/u02/app/alpha3/oradata/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=925437626 file name=/u02/app/alpha3/oradata/users01.dbf
contents of Memory Script:
{
set until scn 990002;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 17-OCT-16
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 7 is already on disk as file /u02/app/oracle/arch/1_7_925330721.dbf
archived log file name=/u02/app/oracle/arch/1_7_925330721.dbf thread=1 sequence=7
media recovery complete, elapsed time: 00:00:01
Finished recover at 17-OCT-16
Oracle instance started
Total System Global Area 417546240 bytes
Fixed Size 2253824 bytes
Variable Size 327158784 bytes
Database Buffers 83886080 bytes
Redo Buffers 4247552 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''ALPHA3'' 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 = ''ALPHA3'' 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 417546240 bytes

Fixed Size 2253824 bytes


Variable Size 327158784 bytes
Database Buffers 83886080 bytes
Redo Buffers 4247552 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ALPHA3" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u02/app/alpha3/oradata/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ( '/u02/app/alpha3/oradata/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ( '/u02/app/alpha3/oradata/redo03.log' ) SIZE 50 M REUSE
DATAFILE
'/u02/app/alpha3/oradata/system01.dbf'
CHARACTER SET WE8MSWIN1252

contents of Memory Script:


{
set newname for tempfile 1 to
"/u02/app/alpha3/oradata/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u02/app/alpha3/oradata/sysaux01.dbf",
"/u02/app/alpha3/oradata/undotbs01.dbf",
"/u02/app/alpha3/oradata/users01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME

renamed tempfile 1 to /u02/app/alpha3/oradata/temp01.dbf in control file

cataloged datafile copy


datafile copy file name=/u02/app/alpha3/oradata/sysaux01.dbf RECID=1 STAMP=925437656
cataloged datafile copy
datafile copy file name=/u02/app/alpha3/oradata/undotbs01.dbf RECID=2 STAMP=925437656
cataloged datafile copy
datafile copy file name=/u02/app/alpha3/oradata/users01.dbf RECID=3 STAMP=925437656

datafile 2 switched to datafile copy


input datafile copy RECID=1 STAMP=925437656 file name=/u02/app/alpha3/oradata/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=925437656 file name=/u02/app/alpha3/oradata/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=925437656 file name=/u02/app/alpha3/oradata/users01.dbf

contents of Memory Script:


{
Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 17-OCT-16

SQL> select name,open_mode from v$database;

NAME OPEN_MODE
--------- --------------------
ALPHA3 READ WRITE

SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
/u02/app/alpha3/oradata/system01.dbf
/u02/app/alpha3/oradata/sysaux01.dbf
/u02/app/alpha3/oradata/undotbs01.dbf
/u02/app/alpha3/oradata/users01.dbf

4> RMAN Cloning without DUPLICATE command


1 Connect to rman
configure channel 1 device type disk format /path
2 RMAN> backup database include current controlfile plus archivelog all format ‘path’;
3 Create directory structure or server for clone database alpha4
4 create pfile from prod db keep the db name as it is.
5 copy the all the backup piece of datafile,controlfile,archivelog to the new location e.i clone location
u01/app/alpha4/admin/rman
6 Find the backup piece of controlfile
7> startup nomount the alpha4 clone db
8> connect to rman target /
RMAN> restore controlfile from '/u02/app/alpha4/admin/rman/05risf8d_1_1';
9> RMAN> alter database mount;
RMAN> run
{
catalog backuppiece '/u02/app/alpha4/admin/rman/06risf8f_1_1';
catalog backuppiece '/u02/app/alpha4/admin/rman/0drisknk_1_1';
catalog backuppiece '/u02/app/alpha4/admin/rman/0criskng_1_1';
catalog backuppiece '/u02/app/alpha4/admin/rman/0erisknl_1_1';
catalog backuppiece '/u02/app/alpha4/admin/rman/0friskpc_1_1';
catalog backuppiece '/u02/app/alpha4/admin/rman/0griskpf_1_1';
set newname for datafile 1 to '/u02/app/alpha4/oradata/system01.dbf';
set newname for datafile 2 to '/u02/app/alpha4/oradata/sysaux01.dbf';
set newname for datafile 3 to '/u02/app/alpha4/oradata/undotbs01.dbf';
set newname for datafile 4 to '/u02/app/alpha4/oradata/users01.dbf';
restore database;
switch datafile all;
recover database;
}
RMAN> alter database open resetlogs;

10to change the db name


SQL> shut immediate;
SQL> startup mount;
[oracle@test2 rman]$ nid TARGET=/ as sysdba DBNAME=alpha4 SETNAME=Y

DBNEWID: Release 11.2.0.4.0 - Production on Fri Oct 21 02:19:54 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Password: / as sysdba
Connected to database ALPHA (DBID=2652570477)

Connected to server version 11.2.0

Control Files in database:


/u02/app/alpha4/oradata/control01.ctl
/u02/app/alpha4/oradata/control02.ctl

Change database name of database ALPHA to ALPHA4? (Y/[N]) => Y

Proceeding with operation


Changing database name from ALPHA to ALPHA4
Control File /u02/app/alpha4/oradata/control01.ctl - modified
Control File /u02/app/alpha4/oradata/control02.ctl - modified
Datafile /u02/app/alpha4/oradata/system01.db - wrote new name
Datafile /u02/app/alpha4/oradata/sysaux01.db - wrote new name
Datafile /u02/app/alpha4/oradata/undotbs01.db - wrote new name
Datafile /u02/app/alpha4/oradata/users01.db - wrote new name
Datafile /u02/app/alpha/oradata/alpha/temp01.db - wrote new name
Control File /u02/app/alpha4/oradata/control01.ctl - wrote new name
Control File /u02/app/alpha4/oradata/control02.ctl - wrote new name
Instance shut down

Database name changed to ALPHA4.


Modify parameter file and generate a new password file before restarting.
Succesfully changed database name.
DBNEWID - Completed succesfully.

modify the pfile and change the database name from alpha4
$ orapwd file=orapwalpha4 password=critical entries=4
SQL> startup;
SQL> select name from v$database;
SQL> select instance_name from v$instance;

You might also like