Oracle Database Cloning Using Rman Utility
-----------------------------------------------------
Prerequisites
-------------
1)OEL Oracle enterprise Linux server
2)Oracle installed with out database
Activity Flow
-------------
1)Take source backup using Rman
2)move pfile,Controlfile,backup pieces, to target server
3)Start the Instance in Mount Stage and Restore from backup pieces
4)Open the database as source SID
5)Rename the Database
Trigger Backup on source
------------------------
$ RMAN> backup database plus archivelog delete input;
$ RMAN> restore controlfile to '/tmp/prod_control.ctl';
Move files to Target server
----------------------------
parameter file pfile
edit pfile change SID except for DB_NAME parameter keep it source
create directories as per new pfile
$ RMAN> rman target /catalog rman-rc/rman-rc@rca
$ RMAN>backup database plus archivelog delete input;
$ RMAN>list backup of database summary;
$ RMAN>restore controlfile to '/tmp/prod_control.ctl';
$ RMAN>exit
$ cd ORACLE_HOME/dbs
$ ls -lrt
initproddb.ora
i want to copy the initproddb.ora to the target server using scp
$ scp initproddb.ora oracle@192.168.0.100:$ORACLE_HOME/dbs (it will ask password promt enter the password remote target server and enter it)
initproddb.ora (you will prompt the 100% complete)
Target server
-------------
$ cd ORACLE_HOME/dbs
$ ls -lrth
initproddb.ora
open this file in VI editor
replace with
%s/proddb/testdb/
save and exit the file
(source db is proddb and target db is testdb create the directories as per new file)
(after that open the parameter file initproddb.ora in cat command we need to create directories)
$ cat initproddb.ora
$ mkdir -p /u01/app/oracle/admin/testdb/adump
$ mkdir -p /u01/app/oracle/oradata/testdb/
$ mkdir -p /u01/app/oracle/fast_recovery_area/testdb/
$ mkdir -p /u01/app/oracle/fast_recovery_area
scp/tmp/prod_control.ctl ---> target server control location move files to target server
$ cd /tmp
$ ls -lrth
source server
----------------
$ scp prod_control.ctl oracle@ 192.168.0.100:/u01/app/oracle/oradata/testdb/control01.ctl
$ scp prod_control.ctl oracle@ 192.168.0.100:/u01/app/oracle/oradata/testdb/control02.ctl
Target Server
-------------
$ ls -lrth
$ /u01/app/oracle/oradata/testdb/control01.ctl
$ /u01/app/oracle/oradata/testdb/control02.ctl
database backup pieces ---> same location as source
$ rman target /catalog rman -rc/rman_rc@rcat
conneceted target database :proddb (DBID=674237234)
connecteed to recovery catalog database
$ RMAN> list backup of database summary; (it will show like this key ty lv device type and tag)
key --> 2949 ty--->B LV--->A Device type---> disk Tag ---> TAG202012t105306 (tag is the important using tag only we can perform restore and recovery in backup)
$ RMAN> list backup TAG202012t105306;
list of backup piece name :/u01/app/oracle/fast_receovery_area/proddb/backupset/2020-07-20/TAG202012t105306.bkp
$ scp/u01/app/oracle/fast_recovery_area/proddb/backupset/2020-07-20/TAG202012t105306.bkp oracle@192.168.0.100:/u01/app/oracle/fast_recovery_area/proddb/backupset/2020-07-20/
Target server
--------------
$ mkdir-p /u01/app/oracle/fast_recovery_area/proddb/backupset/2020-07-20 (target server directory may not exist create this directory)
archive backup pieces ---> same location as source
$ scp/u01/app/oracle/fast_recovery_area/proddb/backupset/2020-07-20/TAG202012t105306.bkp oracle@192.168.0.100:/u01/app/oracle/fast_recovery_area/proddb/backupset/2020-07-20/
Start cloning
------------------
export environment variables connect to rman
Target Server
-------------
$ env |grep ora
ORACLE_SID =proddb
ORACLE_HOME= '/u01/app/oracle/product/11.2.0/db_home-1
$ rman target /
connected to target database (not started)
$ RMAN> startup mount;
get the last scn available in the archive log backup
$RMAN> list backup of archivelog all;
last archive log--> 6 next scn---.> 960034
-Rename the DB redolog files so they can be created in new location
--------------------------------------------------------------------
sql> alter database rename file '/u01/app/oracle/oradata/proddb/redo01.log' to '/u01/app/oracle/oradata/testdb/redo01.log';
Target server
-------------
sql> select member from v$logfle;
member
-------
/u01/app/oracle/oradata/proddb/redo03.log
/u01/app/oracle/oradata/proddb/redo02.log
/u01/app/oracle/oradata/proddb/redo01.log
we have to change the datafile proddb to testdb redo03,02,01
Restore the datafiles to new location
----------------------------------------
run {
set newname for datafile1 to '/u01/app/oracle/oradata/testdb/system01.dbf';
set newname for datafile1 to '/u01/app/oracle/oradata/testdb/sysaux01.dbf';
set newname for datafile1 to '/u01/app/oracle/oradata/testdb/undotbs01.dbf';
set newname for datafile1 to '/u01/app/oracle/oradata/testdb/user01.dbf';
set newname for datafile1 to '/u01/app/oracle/oradata/testdb/example01.dbf';
restore datafile from TAG202012t105306;
switch datafile all;
recover database untill scn 960034;
alter database open resetlogs;
}
Renaming Database after cloning
--------------------------------
sql> select name,open_mode from v$database;
name--->proddb open_mode->read_write
hostname dctest.chaitanya.com
( we have to rename the proddb to testdb we are in the testserver)
Take control file backup to trace with resetlog options
--------------------------------------------------------
sqlplus '/as sysdba'
sql> alter database backup controlfile to trace as'/tmp/ create_ctrol_file.sql';
sql> database altered
sql> shut immedaite ;
sql>exit
create pfile for new dbid
-------------------------
$cd $ORACLE_HOME/dbs
$ ls -ltr
initproddb.ora
$ mv initproddb.ora inittestdb.ora
$ vi inittestdb.ora (one parameter db_name =proddb change to testdb db_name=testdb save and exit vi editor)
$ export ORACLE_SID= testdb
sqlplus '/as sysdba'
startup instance in nomount stage
---------------------------------
sql>startup nomount;
exit
$ cd/tmp
ls -lrt
create_ctrolfile.sql (copy the create_ctrolfile.sql to new note pad and paste it)
$ cat create_ctrolfile.sql
Edit the control file in trace location with new sid
-----------------------------------------------------
create control file set database "testdb" resetlogs archivelog
remove reuse and set change norestlogs to resetlogs
it look like this when u open file
maxlogfile
--
---
---
log file
--
--
group1 /u01---
group2 /u01---
group3 /u01---
datafile
------/u01
---
---
---
---
character set WE8MSWIN1252
$cd $ ORACLE_HOME/dbs (remove the oldcontrol file)
$ ls -lrt
$ inittestdb.ora
cat inittsetdb.ora
$ rm-rf /u01/app/oracle/oradata/testdb/control01.ctl /u01/app/oracle/oradata/testdb/control02.ctl
Create controlfiles for new instance
------------------------------------
sqlplus '/as sysdba'
sql> select instance_name ,status from v%instance;
instance_name -->testdb
status--->started
we have created control statement create_ctrol.sql and run
it will display controlfile created
sql> alter database open resetlogs
sql>select name,open_mode from v$database;
name---> testdb
open_mode---> read,write
sql> select name from v$ controlfile;
sql>select member from v$ logfile;
cloning is done
Note: it will differ in your environment it may be u r development or testing or production and also directory structure in linux mountpoints and IP address but the process is same.
THANK YOU FOR VIEWING FOR MORE UPDATES VISIT MY BLOG
http://chaitanyaoracledba.blogspot.com/