#!/bin/ksh
## ---------------------------------------------------------------------
## script name : rman_bkup.ksh
## Author : Ramakrishna Nemani
##
##
## This script backsup the data files, archived log files and control
## file and spfile. It takes ORACLE_SID as an argument and backs up the
## files for the specified ORACLE_SID
## This script uses rman catalog.
##
##
## ---------------------------------------------------------------------
. ~/.profile
##
## Source the rman user ids and passwords from rmanids.sh
##
. /apps/oracle/admin/rman/rmanids.sh
##
## Make sure ORACLE_SID is passed as an argument
##
if (( $# < 1 ))
then
echo
echo Error Missing Arguement, Please supply Oracle Sid
echo
echo Usage: $0 ORACLE_SID
echo
exit
fi
export ORACLE_SID=$1
LOG_DIR="/apps/oracle/admin/rman"
LOCKFILE="${LOG_DIR}/$ORACLE_SID.lock"
EMAIL_INFO_FILE="${LOG_DIR}/${ORACLE_SID}_email.cfg"
SENDER="rman@`hostname"
CURR_DATE=`date +"%Y%m%d_%H%M%S"`
##
## using two seperate files instead of one for keeping the logs
## The LOGFILE will have log from just the latest run
## The LOGARCFILE will have the cumulative log
##
LOGFILE="${LOG_DIR}/rman_bkup.$ORACLE_SID.log"
LOGARCFILE="${LOG_DIR}/rman_bkup.$ORACLE_SID.log.arc"
##
## using two seperate files instead of one for keeping the errors
## The EMAILFILE will have errors if any from just the latest run
## The EMAILARCFILE will have the cumulative errors
##
EMAILFILE="${LOG_DIR}/rman_bkup.$ORACLE_SID.email"
EMAILARCFILE="${LOG_DIR}/rman_bkup.$ORACLE_SID.email.arc"
##
## Make sure no other rman process is running for this ORACLE_SID
##
echo --------------------------------------------------------- > $LOGFILE
date >> $LOGFILE
echo ---------------- rman_bkup.ksh started ------------------ >> $LOGFILE
while [ 1 ]
do
if [ -e $LOCKFILE ]
then
##
## Some rman process is running. Check again after 3 minutes
##
echo "$LOCKFILE exists. Will check again after 3 minutes" >> $LOGFILE
echo >> $LOGFILE
sleep 180
else
##
## No rman process is running. Create a lock file
##
echo Do not remove this file. This is a lock file for $ORACLE_SID > $LOCKFILE
break
fi
done
echo $ORACLE_SID >> $LOGFILE
whoami >> $LOGFILE
which rman >> $LOGFILE
##
## Backup database and archive logs
##
rman <<EOF >> $LOGFILE
CONNECT TARGET ${rmanid}/${rmanpw} ;
SHOW ALL ;
BACKUP DATABASE FILESPERSET 1 ;
BACKUP ARCHIVELOG ALL DELETE INPUT;
CONFIGURE DEVICE TYPE sbt PARALLELISM 4 ;
CONFIGURE CHANNEL DEVICE TYPE sbt
PARMS 'ENV=(TDPO_OPTFILE=/usr/tivoli/tsm/client/oracle/bin64/tdpo.opt)'
FORMAT '%u_%p_%c' ;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT TO '%F';
BACKUP DEVICE TYPE SBT BACKUPSET ALL ;
DELETE NOPROMPT OBSOLETE
RECOVERY WINDOW OF 15 DAYS
DEVICE TYPE SBT ;
CONFIGURE DEVICE TYPE sbt clear ;
CONFIGURE CHANNEL DEVICE TYPE sbt clear ;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT CLEAR ;
DELETE NOPROMPT OBSOLETE REDUNDANCY = 3 DEVICE TYPE = DISK ;
REPORT SCHEMA ;
REPORT UNRECOVERABLE ;
EOF
rmanstatus=$?
##
## Check rman exit status and email incase of a failure
##
if (( $rmanstatus > 0 ))
then
if [ ! -e $EMAIL_INFO_FILE ]
then
echo "To:rnemani@na.cokecce.com" > $EMAIL_INFO_FILE
fi
cat $EMAIL_INFO_FILE > $EMAILFILE
echo "Subject: The $0 script failed in the backup step for $ORACLE_SID !!!" >> $EMAILFILE
echo >> $EMAILFILE
date >> $EMAILFILE
echo "rman error!!! ..." >> $EMAILFILE
echo "Not removed the lock file : $LOCKFILE " >> $EMAILFILE
echo "Please fix the error and remove the lock file" >> $EMAILFILE
echo "before re-running the script again!!!" >> $EMAILFILE
echo >> $EMAILFILE
grep -i 'RMAN-' $LOGFILE >> $EMAILFILE
grep -i 'ORA-' $LOGFILE >> $EMAILFILE
grep -i 'sbt' $LOGFILE >> $EMAILFILE
grep -i 'tsm' $LOGFILE >> $EMAILFILE
sendmail -F "$SENDER" -t < $EMAILFILE
cat $EMAILFILE >> $EMAILARCFILE
exit 12
fi
##
## sync up the rman catalog
##
rman << EOF >> $LOGFILE
CONNECT TARGET ${rmanid}/${rmanpw} ;
CONNECT CATALOG ${catlid}/${catlpw}@${ORACLE_CATL} ;
RESYNC CATALOG;
EOF
rmanstatus=$?
##
## Check rman exit status and email in case of a failure
##
if (( $rmanstatus > 0 ))
then
if [ ! -e $EMAIL_INFO_FILE ]
then
echo "To:rnemani@na.cokecce.com" > $EMAIL_INFO_FILE
fi
cat $EMAIL_INFO_FILE > $EMAILFILE
echo "Subject: The $0 script failed in the resync step for $ORACLE_SID !!!" >> $EMAILFILE
echo >> $EMAILFILE
date >> $EMAILFILE
echo "rman error!!! ..." >> $EMAILFILE
echo "Not removed the lock file : $LOCKFILE " >> $EMAILFILE
echo "Please fix the error and remove the lock file" >> $EMAILFILE
echo "before re-running the script again!!!" >> $EMAILFILE
echo >> $EMAILFILE
grep -i 'RMAN-' $LOGFILE >> $EMAILFILE
grep -i 'ORA-' $LOGFILE >> $EMAILFILE
grep -i 'sbt' $LOGFILE >> $EMAILFILE
grep -i 'tsm' $LOGFILE >> $EMAILFILE
sendmail -F "$SENDER" -t < $EMAILFILE
cat $EMAILFILE >> $EMAILARCFILE
exit 12
fi
echo --------------------------------------------------------- >> $LOGFILE
date >> $LOGFILE
echo ---------------- rman_bkup.ksh completed ---------------- >> $LOGFILE
echo >> $LOGFILE
cat $EMAIL_INFO_FILE > $EMAILFILE
echo "Subject: The $0 script completed successfully for $ORACLE_SID !!!" >> $EMAILFILE
cat $LOGFILE >> $EMAILFILE
sendmail -F "$SENDER" -t < $EMAILFILE
cat $EMAILFILE >> $EMAILARCFILE
cat $LOGFILE >> $LOGARCFILE
##
## Remove lock file to allow other rman processs for
## this ORACLE_SID to run
##
rm $LOCKFILE
## --------------------------------------------------------------------
## End of rman_bkup.ksh
## --------------------------------------------------------------------
Subscribe to:
Post Comments (Atom)




1 comment:
Thank you so much for sharing this precious information with us.
Post a Comment