Wednesday, January 24, 2007

Procedure of using RMAN duplicate command to create a new GEN3C from the backup of GEN3S

Procedure of using RMAN duplicate command to create a new GEN3C from the backup of GEN3S

Reference

MetaLink Note 73912.1: RMAN: Creating a Duplicate Database

Prerequisite:

GEN3C and GEN3S are located in the same server, there are enough disk space.

Procedure:

  1. Obtain a backup of GEN3S

# cold_backup.sh

Notes: As GEN3S is operated in nonarchivelog mode, only rman cold backup is possible

Script location: /ora01/orabkup/GEN3S/rman/scripts

=============== start of script cold_backup.sh========= ======

#!/usr/bin/ksh

# backup for database

# Denis Sun, 8/4/2006

. /oracle/.profile_old

export ORACLE_SID=GEN3S

. oraenv ${ORACLE_SID}

LOGDATE=`date +\%m\-%d\-\%Y\_\%H\:\%M`

LOG=/ora01/orabkup/GEN3S/rman/log/rman_cold_${ORACLE_SID}_${LOGDATE}.log

START_TIME=`date`

$ORACLE_HOME/bin/sqlplus /nolog <<EOD

connect / as sysdba

shutdown immediate

startup mount

exit

EOD

echo " Now in mount state"

$ORACLE_HOME/bin/rman target / nocatalog cmdfile cold_backup_disk.rmn log $LOG

echo " finish: `date` " tee -a $LOG

echo " start : ${START_TIME} " tee -a $LOG

echo "Examine RMAN log at $LOG for any error."

~

============== end of script cold_backup.sh===============================

============== start of script cold_backup_disk.rmn ===========

run {

# allocate channel. Important: this must be done after

# database has been mounted !!!

# cold backup to disk destination

allocate channel d1 type disk;

allocate channel d2 type disk;

backup

format '/ora01/orabkup/GEN3S/rman/rman_cold_%d_%p_%s.dbf'

database include current controlfile;

sql 'alter database open';

release channel d1;

release channel d2;

}

============== end of script cold_backup_disk.rmn ===========

  1. Copy and edit init.ora file

If initGEN3C.ora does not exist (not in this case), we need to copy from initGEN3S.ora. The parameters such as

db_name

instance_name

control_files

*_dump

etc should be modified accordingly

  1. Create a RMAN script file: dup_gen3c.rmn which specifies the new names of all data files and redo log file:

First, the datafile name , log files group and member size of GEN3S should be obtained in order to edit this script:

====================== start of dup_gen3c.rmn ========================

run {

# allocate at least one auxiliary channel of type disk or tape

allocate auxiliary channel c1 type disk;

allocate auxiliary channel c2 type disk;

# set new filenames for the datafiles

set newname for datafile 1 to '/ora02/oradata/GEN3C/gen3c_system01.dbf';

set newname for datafile 2 to '/ora02/oradata/GEN3C/gen3c_audit_rdbs01.dbf';

set newname for datafile 3 to '/ora01/oradata/GEN3C/gen_data_01.dbf';

set newname for datafile 4 to '/ora02/oradata/GEN3C/gen_data_02.dbf';

set newname for datafile 5 to '/ora01/oradata/GEN3C/gen_data_03.dbf';

set newname for datafile 6 to '/ora02/oradata/GEN3C/gen_data_04.dbf';

set newname for datafile 7 to '/ora01/oradata/GEN3C/gen_data_05.dbf';

set newname for datafile 8 to '/ora02/oradata/GEN3C/gen_data_06.dbf';

set newname for datafile 9 to '/ora01/oradata/GEN3C/gen_data_07.dbf';

set newname for datafile 10 to '/ora02/oradata/GEN3C/gen_data_08.dbf';

set newname for datafile 11 to '/ora01/oradata/GEN3C/gen_data_09.dbf';

set newname for datafile 12 to '/ora02/oradata/GEN3C/gen_data_10.dbf';

set newname for datafile 13 to '/ora01/oradata/GEN3C/gen_data_11.dbf';

set newname for datafile 14 to '/ora01/oradata/GEN3C/gen_data_12.dbf';

set newname for datafile 15 to '/ora01/oradata/GEN3C/gen_indx_01.dbf';

set newname for datafile 16 to '/ora02/oradata/GEN3C/gen_indx_02.dbf';

set newname for datafile 17 to '/ora01/oradata/GEN3C/gen_indx_03.dbf';

set newname for datafile 18 to '/ora02/oradata/GEN3C/gen_indx_04.dbf';

set newname for datafile 19 to '/ora01/oradata/GEN3C/gen_indx_05.dbf';

set newname for datafile 20 to '/ora02/oradata/GEN3C/gen_indx_06.dbf';

set newname for datafile 21 to '/ora01/oradata/GEN3C/gen_indx_07.dbf';

set newname for datafile 22 to '/ora02/oradata/GEN3C/gen_indx_08.dbf';

set newname for datafile 23 to '/ora01/oradata/GEN3C/genp_indx01.dbf';

set newname for datafile 24 to '/ora02/oradata/GEN3C/genp_rbs01.dbf';

set newname for datafile 25 to '/ora01/oradata/GEN3C/genp_rbs02.dbf';

set newname for datafile 26 to '/ora01/oradata/GEN3C/genp_temp01.dbf';

set newname for datafile 27 to '/ora02/oradata/GEN3C/genp_temp02.dbf';

set newname for datafile 28 to '/ora01/oradata/GEN3C/genp_tools01.dbf';

set newname for datafile 29 to '/ora02/oradata/GEN3C/genp_users01.dbf';

set newname for datafile 30 to '/ora01/oradata/GEN3C/gen_rep_data_01.dbf';

set newname for datafile 31 to '/ora02/oradata/GEN3C/gen_rep_data_02.dbf';

set newname for datafile 32 to '/ora01/oradata/GEN3C/gen_rep_data_03.dbf';

set newname for datafile 33 to '/ora02/oradata/GEN3C/gen_rep_data_04.dbf';

# issue the duplicate command

duplicate target database to GEN3C

logfile

group 1 ('/ora01/oraredo/GEN3C/gen3c_redo01a.log','/ora02/oraredo/GEN3C/gen3c_redo01b.log') size 52428800,

group 2 ('/ora01/oraredo/GEN3C/gen3c_redo02a.log','/ora02/oraredo/GEN3C/gen3c_redo02b.log') size 52428800,

group 3 ('/ora01/oraredo/GEN3C/gen3c_redo03a.log','/ora02/oraredo/GEN3C/gen3c_redo03b.log') size 52428800,

group 4 ('/ora01/oraredo/GEN3C/gen3c_redo04a.log','/ora02/oraredo/GEN3C/gen3c_redo04b.log') size 52428800,

group 5 ('/ora01/oraredo/GEN3C/gen3c_redo05a.log','/ora02/oraredo/GEN3C/gen3c_redo05b.log') size 52428800,

group 6 ('/ora01/oraredo/GEN3C/gen3c_redo06a.log','/ora02/oraredo/GEN3C/gen3c_redo06b.log') size 52428800;

release channel c1;

release channel c2;

}

====================== end of dup_gen3c.rmn ========================

  1. Confirm that we can start the duplicate instance (GEN3C)

i. set ORACLE_HOME and ORACLE_SID

ii. create a password file as needed

iii. start the instance in nomount state

  1. configure and check SQL* Net connectivity

In this case, we already have GEN3S and GEN3C service name in the tnsname.ora.

# tnsping gen3s

# tnsping gen3c

  1. Starting the duplication

# .oraenv GEN3C

# dup_gen3c.sh

================== start of dup_gen3c.sh ===============================

#!/usr/bin/ksh

# Program name: dup_gen3c.sh

# This script is to create a duplicate database called GEN3C from GEN3S

# before executing this script, the GEN3C instance should be up (in nomount)

# i.e.

# SQL> conn / as sysdba

# SQL> startup nomount

. /oracle/.profile_old

. oraenv GEN3C

export ORACLE_SID=GEN3C

export ORACLE_HOME=/oracle/product/8.1.7.4

LOGDATE=`date +\%m\-%d\-\%Y\_\%H\:\%M`

LOG=/ora01/orabkup/GEN3S/rman/log/rman_dup_${ORACLE_SID}_${LOGDATE}.log

START_TIME=`date`

# rm datafiles of GEN3C

rm /ora02/oradata/GEN3C/*.*

rm /ora01/oradata/GEN3C/*.*

sqlplus /nolog <<_EOF_

connect / as sysdba

shutdown abort;

startup nomount;

_EOF_

${ORACLE_HOME}/bin/rman target sys/strik3out@gen3s nocatalog auxiliary / cmdfile=dup_gen3c.rmn log=${LOG}

echo "End rman duplicate : `date`" >> $LOG

echo "Start rman duplicate: ${START_TIME}" >> $LOG

======================== end of dup_gen3c.sh ==========================

Notes:

(a) RMAN backup of GEN3C using 2 channels takes about 10 min

Recovery Manager complete.

finish: Wed Dec 13 18:46:03 CST 2006

start : Wed Dec 13 18:36:16 CST 2006

(b) RMAN duplicate job using 2 channels takes about 10 min

Recovery Manager complete.

End rman duplicate : Wed Dec 13 19:49:46 CST 2006

Start rman duplicate: Wed Dec 13 19:39:09 CST 2006

(c) The password of GEN3C user schema will be same as those of GEN3S

(d) After creating the GEN3C, find the global_name value is GEN3S, issue following statement to change global_name:

alter database rename global_name to GEN3C.WORLD

SQL> select * from global_name;

GLOBAL_NAME

--------------------------------------------------------------------------------

GEN3C.WORLD

No comments: