Nethence NSBH Laboratory Webmail Your IP BBDock
New Software Burns in Hell print | donate | html/css | terms of use
Home | Unix | Windows | Oracle | Obsolete | Hardware | Mechanics | Scripts | Configs | Private

Oracle RMAN -- Clone a database
 
 
Duplicate from scratch in brief
- prepare the directories
- get and adapt the pfile
- switch redo logs and backup archivelogs
- share the backuppieces
- clone the database
- switch to spfile
- clean up
 
 
Duplicate update in brief
- shut down the database
- check spfile is there
- start nomount, create a pfile, shutdown the database
- add _convert statements to the pfile
- start nomount
- duplicate target
- switch to spfile
- eventually disable archivelogs
 
 
Prepare the directories
As root, eventually prepare /usr/local/oracle for redundant controlfile and redo logs,
mkdir /usr/local/oracle
chown oracle:oinstall /usr/local/oracle
chmod 750 /usr/local/oracle
 
As oracle, prepare the directories,
export ORACLE_SID=dbname2

cd $ORACLE_BASE/admin
mkdir $ORACLE_SID
chmod 750 $ORACLE_SID
cd $ORACLE_SID
mkdir adump dpdump pfile scripts
#mkdir bdump cdump udump
chmod 750 *

cd /u02/oradata
mkdir $ORACLE_SID
chmod 750 $ORACLE_SID

cd /usr/local/oracle
mkdir $ORACLE_SID
chmod 750 $ORACLE_SID
 
 
Get and adapt the pfile
On srv1, make a pfile,
. oraenv
sqlplus / as sysdba
create pfile from spfile;
and send it to srv2,
cd $ORACLE_HOME/dbs
scp initdbname.ora srv2:~/
#rm -f initdbname.ora
 
On srv2, rename the pfile accordingly,
cd ~/
mv initdbname.ora $ORACLE_HOME/dbs/initdbname2.ora
edit the pfile,
cd $ORACLE_HOME/dbs
cp initdbname2.ora initdbname2.ora.dist
vi initdbname2.ora
then :
- remove the first lines
- :%s/dbname/dbname2/g
(-) :%s/\/pathonsrv1/\/pathonsrv2/g
- define the path conversions,
db_file_name_convert=(/u02/oradata/dbname/,/u02/oradata/dbname2/)
log_file_name_convert=(/u02/oradata/dbname/,/u02/oradata/dbname2/)
log_file_name_convert=(/usr/local/oracle/dbname/,/usr/local/oracle/dbname2/)
 
Generate the orapw file to authenticate as sys without even having any controlfile nor datafile,
cd $ORACLE_HOME/dbs
orapwd file=orapwdbname2 password=PASSWORD entries=10
note. entries means how many simultanate sys sessions are autorized.
fix perms,
chmod 640 orapwdbname2
 
 
Oratab, listener and tnsnames for both
Edit listener,
cd $ORACLE_HOME/network/admin
vi listener.ora
add into SID_LIST,
(SID_DESC =
(GLOBAL_DBNAME = dbname2)
(ORACLE_HOME = /u01/product/10.2.0/ora1020)
(SID_NAME = dbname2)
)
apply,
lsnrctl stop
lsnrctl start

Edit tnsnames,
vi tnsnames.ora
add,
dbname2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = srv2.example.net)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dbname2)
)
)

dbname =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = srv1.example.net)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dbname)
)
)
 
Add dbname2 to the oratab,
vi /etc/oratab
 
 
Switch redo logs and backup archivelogs
On srv1, switch the redo logs,
. oraenv
sqlplus / as sysdba
alter system switch logfile;
and backup the archivelogs,
_backup incr
 
 
Share the backuppieces
Make sure the backup dir is also available on srv2, either by NFS, or just copy the backuppieces.
 
 
Clone the database
Start dbname2 nomount (with the _convert pfile),
cd ~/
. oraenv
sqlplus / as sysdba
startup nomount
 
Make sure you got access to those databases through TNS,
- dbname on srv1 through srv2 TNS
- dbname2 on srv2 itself
- rcat on srv2 itself
 
Duplicate,
rman target sys/PASSWORD@dbname catalog cat/CATPASSWD@rcat auxiliary sys/PASSWORD@dbname2
duplicate target database to dbname2;
note. disconnect from your previous sql prompt on ORCLDEV, otherwise the rman duplicate process will be waiting.
note. carefull here, startup/shutdown applies on the target, not the auxillary
note. eventually add this to the rman command to debug,
#rman ... debug trace rman.trc log rman.log
and watch what's going on in the dbname2 alert log,
tail -F /u01/admin/dbname2/bdump/alert_dbname2.log
 
Once finished, check everything is fine on dbname2,
. oraenv
sqlplus / as sysdba
select instance_name, host_name, startup_time, status
from v$instance;
also as user through TNS,
sqlplus USERNAME/PASSWORD@dbname2
select * from table1;
 
 
Switch to spfile
As sys, switch to spfile,
create spfile from pfile;
shutdown immediate
eventually remove the pfile,
cd $ORACLE_HOME/dbs
rm initdbname2.ora
and start the database with the spfile,
startup
 
Now that the clone is built, we no longer need the file_name_convert settings,
alter system reset db_file_name_convert scope=spfile sid='*'
/
alter system reset log_file_name_convert scope=spfile sid='*'
/
and eventually disable archivelogs,
  archive log list
shutdown immediate
startup mount
alter database noarchivelog;
alter database open;
 
 
Finish up
Eventually remove the TNS entry for the target database (dbname),
cd $ORACLE_HOME/network/admin
vi tnsnames.ora
 
 
References
Metalink 228257.1
http://www.shutdownabort.com/quickguides/clone_rman.php
http://repettas.wordpress.com/2008/10/24/duplicating-a-database-using-oracle-11g-rman/
http://www.dba-oracle.com/t_how_to_create_a_duplicate_database_oracle.htm
 

Last update: Jun 28, 2010
Copyright © 2007-2014 Pierre-Philipp Braun