DOYENSYS Knowledge Portal




We Welcome you to visit our DOYENSYS KNOWLEDGE PORTAL : Doyensys Knowledge Portal




Thursday, March 31, 2016

RMAN Automation script to clone the database from DR site





#!/bin/ksh
##  Script to auto clone DOYENDB based on RMAN Duplicate
## Created by M.GANGAINATHAN
/bin/mailx -s "RPT:-DOYENDB CLONING PROCESS Started at :-`date` " $NOTIFY_LIST <$LOGFILE
NOTIFY_LIST="gnathan@1800flowers.com"
LOGFILE=/u03/oracle/CLONE/DOYENDB/logs/DOYENDB_CLONE.txt
LOGFILE1=/u03/oracle/CLONE/DOYENDB/logs/rman_clone.txt
echo "Start of DOYENDB CLONE  CREATION  at `date +%D-%T`">$LOGFILE
echo "Beginning Maintenance Window for OEM DOYENDB  at `date +%D-%T`">>$LOGFILE
. /orahome/env/oracle_Agent12C_env
cd $ORACLE_HOME/bin
./emctl start blackout DOYENDB_CLONE DOYENDB
echo "Ending Maintenance Window for OEM DOYENDB  at `date +%D-%T`">>$LOGFILE

# ENV file
. /orahome/env/oracle_DOYENDB_11g_env

# Stopping Listeners For preparation of Cloning
echo "Stopping LISTENER DOYENDB PROCESS  at `date +%D-%T`">>$LOGFILE
sh -x /u03/oracle/CLONE/DOYENDB/stop_listener.sh
cat /u03/oracle/CLONE/DOYENDB/logs/stop_DOYENDB_LISTENER.txt >>$LOGFILE
echo "Stopping LISTENER DOYENDB PROCESS  at `date +%D-%T`">>$LOGFILE

echo "Beginning Dropping Database DOYENDB  at `date +%D-%T`">>$LOGFILE
${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba" <<-EOF >>$LOGFILE
shutdown immediate;
startup nomount;
alter database mount exclusive;
alter system enable restricted session;
drop database;
EOF
echo "Finished Dropping Database  DOYENDB at `date +%D-%T`">>$LOGFILE

echo " Starting DB in nomount state " >>$LOGFILE
echo "Beginning Starting Database DOYENDB in MOUNT STATE  at `date +%D-%T`">>$LOGFILE
${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba" <<-EOF >>$LOGFILE
startup nomount pfile='/orahome/app/oracle/product/11204/DOYENDB/dbs/initDOYENDB.ora';
create spfile from pfile='/orahome/app/oracle/product/11204/DOYENDB/dbs/initDOYENDB.ora';
EOF
echo "End of Starting Database ATLLTRG in MOUNT STATE  at `date +%D-%T`">>$LOGFILE

# Starting CLONE Listeners For preparation of Cloning
echo "Starting LISTENER DOYENDB PROCESS  at `date +%D-%T`">>$LOGFILE
sh -x /u03/oracle/CLONE/DOYENDB/start_listener_CLONE.sh
cat /u03/oracle/CLONE/DOYENDB/logs/start_DOYENDB_LISTENER.txt >>$LOGFILE
echo "Starting LISTENER DOYENDB PROCESS  at `date +%D-%T`">>$LOGFILE


echo " Starting RMAN CLONE PROCESS at `date +%D-%T`">>$LOGFILE
$ORACLE_HOME/bin/rman target /@ATLPROD_DD_RESTORE auxiliary / CMDFILE /u03/oracle/CLONE/DOYENDB/SQL/rman_clone.sql LOG $LOGFILE1
echo " Starting RMAN CLONE PROCESS END at `date +%D-%T`">>$LOGFILE
echo " LOGS FOR RMAN CLONE DUMP "
echo "===================================================="
echo "===================================================="
cat /u03/oracle/CLONE/DOYENDB/logs/rman_clone.txt >>$LOGFILE
echo "===================================================="
echo "===================================================="
echo " LOGS FOR RMAN CLONE DUMP "

echo " Starting DB in nomount state at `date +%D-%T` " >>$LOGFILE
echo "Beginning Starting Database DOYENDB in FOR PFILE CREATION at `date +%D-%T`">>$LOGFILE
${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba" <<-EOF >>$LOGFILE
shutdown immediate;
startup mount;
alter database noarchivelog;
alter database open;
EOF
echo "End of Starting Database ATLLTRG in OPEN STATE  at `date +%D-%T`">>$LOGFILE

# Starting Listeners After Cloning
echo "Starting LISTENER DOYENDB PROCESS  at `date +%D-%T`">>$LOGFILE
sh -x /u03/oracle/CLONE/DOYENDB/start_listener.sh
cat /u03/oracle/CLONE/DOYENDB/logs/start_DOYENDB_LISTENER.txt >>$LOGFILE
echo "Starting LISTENER DOYENDB PROCESS Ended at `date +%D-%T`">>$LOGFILE

echo "Starting of POST CLONE Database ACTIVITY at `date +%D-%T`">>$LOGFILE
${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba" <<-EOF >>$LOGFILE
PROMPT DROPPING THE PUBLIC SYNONYNMS
@/u03/oracle/CLONE/DOYENDB/SQL/post_clone.sql
@/u03/oracle/CLONE/DOYENDB/SQL/list.sql
EOF

echo " Starting of POST CLONE Database ACTIVITY :- Dropping Private DB Links at `date +%D-%T`">>$LOGFILE
sh -x /u03/oracle/CLONE/DOYENDB/drop_dblink.sh /u03/oracle/CLONE/DOYENDB/SQL/list.log
cat /u03/oracle/CLONE/DOYENDB/logs/drop_dblink_unixscript.txt >> $LOGFILE
echo " Starting of POST CLONE Database ACTIVITY Finished :- Dropping Private DB Links at `date +%D-%T`">>$LOGFILE

echo "Starting of POST CLONE1 Database ACTIVITY at `date +%D-%T`">>$LOGFILE
${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba" <<-EOF >>$LOGFILE
PROMPT DROPPING THE PUBLIC SYNONYNMS
@/u03/oracle/CLONE/DOYENDB/SQL/post_clone1.sql
EOF

echo "LOGS for POST CLONE Database ACTIVITY at `date +%D-%T`">>$LOGFILE
cat /u03/oracle/CLONE/DOYENDB/logs/drop_dblink.txt >>$LOGFILE
cat /u03/oracle/CLONE/DOYENDB/logs/post_clone.txt >>$LOGFILE
echo "LOGS for POST CLONE Database ACTIVITY Ended at `date +%D-%T`">>$LOGFILE

# Stopping CLONE Listeners For preparation of Cloning
echo "Stopping LISTENER DOYENDB PROCESS  at `date +%D-%T`">>$LOGFILE
sh -x /u03/oracle/CLONE/DOYENDB/stop_listener_CLONE.sh
cat /u03/oracle/CLONE/DOYENDB/logs/stop_DOYENDB_LISTENER.txt >>$LOGFILE
echo "Stopping LISTENER DOYENDB PROCESS Ended at `date +%D-%T`">>$LOGFILE
echo "End of ATLLTRG CREATION  at `date +%D-%T`">>$LOGFILE

echo "Beginning Stopping Maintenance Window for OEM DOYENDB  at `date +%D-%T`">>$LOGFILE
. /orahome/env/oracle_Agent12C_env
cd $ORACLE_HOME/bin
./emctl stop blackout DOYENDB_CLONE
echo "Ending Maintenance Window for OEM DOYENDB  at `date +%D-%T`">>$LOGFILE

/bin/mailx -s "RPT:-DOYENDB CLONING PROCESS Ended at :-`date` " $NOTIFY_LIST <$LOGFILE

set `date`
cp $LOGFILE $LOGFILE.$2$3$4





#!/bin/sh
. /orahome/env/oracle_DOYENDB_11g_env
LOGFILE=/u03/oracle/CLONE/DOYENDB/logs/stop_DOYEN_LISTENER.txt
echo "LISTENER STOP PROCESS STARTED AT :-`date`" > $LOGFILE
echo " Stopping LISTENER_DOYENDB_OEM " >> $LOGFILE
lsnrctl << EOF
set current_listener LISTENER_DOYENDB_OEM
stop
exit
EOF
echo " Stopping LISTENER_DOYENDB_JOBS" >> $LOGFILE
lsnrctl << EOF
set current_listener LISTENER_DOYENDB_JOBS
stop
exit
EOF
echo "LISTENER STOP PROCESS ENDED AT :-`date`" >> $LOGFILE

 cat /home/oracle/CLONE/DOYENDB/SQL/
PROMPT DROPPING PRIVATE DBLINKS
@/export/home/oracle/CLONE/DOYENDB/SQL/drop_existin_dblink.sql
spool /export/home/oracle/CLONE/DOYENDB/logs/drop_dblink.txt
set echo on
@/export/home/oracle/CLONE/DOYENDB/SQL/drop_dblink.sql
spool off

oracle@dbatlbocoprod01:~/CLONE/DOYENDB$ cat /export/home/oracle/oraprocs/DOYENDB/logs/start_DOYENDB_LISTENER.txt
LISTENER STOP PROCESS STARTED AT :-Wednesday, March 30, 2016 03:00:16 PM
 Stopping LISTENER_DOYENDB_OEM
 Stopping LISTENER_DOYENDB_JOBS
LISTENER STOP PROCESS ENDED AT :-Wednesday, March 30, 2016 03:00:17 PM

1 comment:

Sridevi K said...


Regards
Sridevi Koduru (Senior Oracle Apps Trainer Oracleappstechnical.com)
LinkedIn profile - https://in.linkedin.com/in/sridevi-koduru-9b876a8b
Please Contact for One to One Online Training on Oracle Apps Technical, Financials, SCM, SQL, PL/SQL, D2K at training@oracleappstechnical.com | +91 - 9581017828.