#!/bin/ksh # oracle_shut.sh # This script does the following: # # 1. Identify the files comprising database # 2. Shutdown the database for cold backup # # Author : Biju Thomas # Date : 08/22/97 # # Variables if test $# -ne 1 then echo 'ORACLE_SID should be passed in as parameter' return 1 fi wdt=`date '+%m%d'` wreturncode=0 export ORACLE_SID=$1 export ORACLE_HOME=`find_ohome.sh ${ORACLE_SID}` export SHLIB_PATH=$ORACLE_HOME/lib:/usr/lib export TMPDIR=/tmp export LD_LIBRARY_PATH=$ORACLE_HOME/lib export SQLPLUS="$ORACLE_HOME/bin/sqlplus -s / " export SVRMGR=$ORACLE_HOME/bin/svrmgrl export wlogfile=oshut_log.$ORACLE_SID export werrfile=oshut_err.$ORACLE_SID export wbackupfiles=dbfiles.$ORACLE_SID export wtempfile=/tmp/tempfile.$ORACLE_SID # # Initialize log and err files # echo "**********************************************************************" > $werrfile echo "**********************************************************************" > $wlogfile # # Verify if Oracle is up # if test -f $ORACLE_HOME/dbs/sgadef$ORACLE_SID.dbf then echo "Oracle up and running" >> $wlogfile # # Get current sessions $SQLPLUS >> $wlogfile <> $wlogfile # # Get names of all controlfiles # $SQLPLUS > $wtempfile <> $werrfile echo "Cold backup will not be done for this instance" >> $werrfile wreturncode=1 else echo "Collected control file names form database" >> $wlogfile fi # # Separate the control file names # echo `cat $wtempfile | awk -F, '{print $1}' -` > $wbackupfiles echo `cat $wtempfile | awk -F, '{print $2}' -` >> $wbackupfiles echo `cat $wtempfile | awk -F, '{print $3}' -` >> $wbackupfiles # # Get names of all datafiles and redofiles # $SQLPLUS >>$wbackupfiles <> $werrfile echo "Cold backup will not be done for this instance" >> $werrfile wreturncode=1 else echo "Collected data and redo file names from database" >> $wlogfile fi # # Add init.ora and config.ora files # echo ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile/init${ORACLE_SID}.ora >> $wbackupfiles echo ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile/config${ORACLE_SID}.ora >> $wbackupfiles # # $wbackupfiles has all the physical files to be backed up # # Shutdown the database # echo "Shutdown immediate database for backup" >> $wlogfile $SVRMGR >>$wlogfile <> $werrfile echo "Please verify ${wlogfile} for current active sessions info" >> $werrfile #echo "Cold backup will not be done for this instance" >> $werrfile wreturncode=2 # # Kill the earlier shutdown process # for killflag in '11 10 9' do kill -${killflag} %% sleep 10 shut_complete=`jobs | wc -l` if [ $shut_complete -eq 0 ] then break fi done sleep 60 # # Could not shut down normally - do a shutdown abort # echo "Shutdown abort database for backup" >> $wlogfile $SVRMGR >>$wlogfile <> $wlogfile $SVRMGR >>$wlogfile <> $wlogfile $SVRMGR >>$wlogfile <> $wlogfile # else echo "Oracle Not Available $ORACLE_SID" >> $werrfile echo "Could not retreive current physical file names from db" >> $werrfile if test -f $wbackupfiles then echo "Cold backup will be done using old set of files" >> $werrfile echo "Please verify the datafiles against the file list in $wbackupfiles" >> $werrfile echo "If they do not match, please initiate cold backup again" >> $werrfile wreturncode=0 else echo "Could not find file list from earlier backup (also)" >> $werrfile echo "Cold backup will not be performed for $ORACLE_SID" >> $werrfile wreturncode=1 fi fi # # If there are errors during the above steps, inform dbaoc # if test `cat $werrfile | wc -l` -ne 1 then echo "**********************************************************************" >> $werrfile echo "Verify $wlogfile for more details" >> $werrfile echo "Date : "`date '+%m/%d/%y %X %A '` >> $werrfile echo "Database : "$ORACLE_SID >> $werrfile echo "Server : "`uname -n` >> $werrfile echo "**********************************************************************" >> $werrfile mailx -s "Errors while oracle shutdown for cold backup - $ORACLE_SID" "tbiju@hotmail.com" > /dev/null < $werrfile else echo "Successful completion of oracle shutdown for backup $ORACLE_SID" >> $wlogfile echo "No Errors / Alerts Encountered" >> $wlogfile echo "**********************************************************************" >> $wlogfile fi # # Shutdown for Backup End Date and Time. # echo Shutdown for Backup End Time `date '+%m/%d/%y %X %A'` >> $wlogfile # # end of script ##