#!/bin/ksh # # Hot Backup Script # Biju Thomas - 04/29/1998 # # Find tablespace names from the given database name # Find the file names for each tablespace # Put the tablespace in backup mode # Backup the files # 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 SVRMGRL=$ORACLE_HOME/bin/svrmgrl export DSMC=cp export wlogfile=hb_log.$ORACLE_SID export werrfile=hb_err.$ORACLE_SID export wbackupfiles=files.$ORACLE_SID export wtempfile=/tmp/tempfile.$ORACLE_SID export wtsnames=tsnames.$ORACLE_SID # # Initialize log and err files # date > $werrfile date > $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 <$wtsnames <> $werrfile wreturncode=1 else echo "Collected tablespace names from $ORACLE_SID database" >> $wlogfile fi ###################################################################### # # For each tablespace do the backup cat $wtsnames | while read TABLESPACE_NAME do # # Get the datafile names associated with the tablespace # $SQLPLUS >$wbackupfiles <> $werrfile wreturncode=1 else echo "Collected data file names from database for $TABLESPACE_NAME" >> $wlogfile fi # # Make the tablespace in Begin backup mode # echo Tablespace $TABLESPACE_NAME Backup Begin Time `date '+%m/%d/%y %X %A'` >> $wlogfile # $SVRMGRL >> wlogfile <> $werrfile break fi done echo "Backups of datafiles for $TABLESPACE_NAME successful" >> $wlogfile # # Make the tablespace in End backup mode # echo Tablespace Backup End Time `date '+%m/%d/%y %X %A'` >> $wlogfile # $SVRMGRL >> wlogfile <> wlogfile < $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 # # Read control file names from $wbackupfiles and back up to ADSM # cat $wbackupfiles | while read FILENAME do # You may copy to an offline device here $DSMC $FILENAME /ora_backup/hotbackup/${ORACLE_SID}/ STATUS=$? if test $STATUS -ne 0 then echo "Backup returned ERROR $STATUS" >> $werrfile break fi done echo "Backup of controfiles successful" >> $wlogfile # else echo "Oracle Not Available $ORACLE_SID" >> $werrfile echo "Could not do hot backup at this time " >> $werrfile fi # # Backup the archive log files associated with this hot backup # echo "Initiated Archive Compress Job" >> $wlogfile #<> echo "Initiated Archive Files Copy job" >> $wlogfile #<> echo "Copying files to offline device from disk" >> $wlogfile # <> >> $wlogfile 2>>$werrfile # # 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 hot backup of $ORACLE_SID" "tbiju@hotmail.com" > /dev/null < $werrfile else echo "Successful completion of hot backup of $ORACLE_SID" >> $wlogfile echo "No Errors / Alerts Encountered" >> $wlogfile echo "**********************************************************************" >> $wlogfile fi # # Hotbackup End Date and Time. # echo Hotbackup End Time `date '+%m/%d/%y %X %A'` >> $wlogfile # # end of script ##