Skip to content

Metabolomics Fiehn Lab

Sections
Personal tools
You are here: Home » Members » Gert Wohlgemuth » oracle » duplicate database

duplicate database

Document Actions
this is a small script to duplicate an oracle database to a remote host
################################################
#
# this programm is for duplicating an oracle
# datbase in an automated way.
#
# - creates needed file structure
# - creates database
# - duplicates database
#
# requires:
#
# - oracle 10g
# - rman catalog
# - shared directory for access of files and
# and backups
# - configured listners
#
#
# contact: wohlgemuth@ucdavis.edu
################################################

################################################
#you need to modify these options so that they
#fit for your enviorment
################################################

CONNECT_SQL=/
CONNECT_RMAN=/

ORACLE_SID=<name of the duplicated instance>
CATALOG=<name of the backup catalog>
TO_DUPLICATE=<name of the database to duplicate>
SHARED_DIRECTORY=<shared directory for configfile generation and backups. must be accessable from all instances!>
ORACLE_BASE=<base directory of your oracle installation>

################################################
#path settings don't change it. it should work

ORACLE_HOME=$ORACLE_BASE/10g
ORACLE_DATA=$ORACLE_BASE/oradata/$ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH:.

LD_LIBRARY_PATH=$ORACLE_HOME/lib


###############################################
#where to create the pfile must be accesable
#from the target and the auxiallary database.
#The best is a share directory
#the backups also must be available so you need
#to mount the directory in the location where the
#backup files are

PFILE=$SHARED_DIRECTORY/$ORACLE_SID.ora

sqlplus $CONNECT_SQL@$TO_DUPLICATE AS sysdba <<EOF
create pfile='$PFILE' from spfile;
exit;
EOF

#create needed directorys as specified in the init file

cat $PFILE | while read LINE; do
result=`echo $LINE | grep dest | grep -v size | awk '{split($0,a,"="); print a[2]}'`

if [ -n "$result" ]; then
#chop and cut the first and last char
result=`echo ${result:1:${#result}-2}`
mkdir -pv $result
fi
done

mkdir -p $ORACLE_DATA

#mv to create init file
cp -v $PFILE $ORACLE_HOME/dbs/init$ORACLE_SID.ora

################################################
#bring database into nomount state

sqlplus /nolog <<EOF

connect $CONNECT_SQL AS sysdba;
shutdown immediate;
startup force nomount;
exit;

EOF

###############################################
#rman script to duplicate the database

rman catalog $CONNECT_RMAN@$CATALOG target $CONNECT_SQL@$TO_DUPLICATE AUXILIARY $CONNECT_SQL <<EOF

run{
duplicate target database to $ORACLE_SID
PFILE = $PFILE
NOFILENAMECHECK;
}
exit;

EOF

##############################################
#create temp tablespace for new database
#cause the old one is not comp anymore

sqlplus /nolog <<EOF

connect $CONNECT_SQL AS sysdba;

CREATE TEMPORARY TABLESPACE tempNew TEMPFILE '$ORACLE_DATA/temp.dbf' SIZE 100M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE unlimited;
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE tempNew;
exit;

EOF
Created by zwluxx
Last modified 2006-10-27 12:44 AM
 

Powered by Plone

This site conforms to the following standards: