Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: RMAN HOTBACKUP AUTOMATED SCRIPT
Hi Seema, I use this script. I have added comments so it should not be difficult to understand. Let me know if you need any clarification:
the usage is --> exec_restore.ksh -d [SID] -f [rman_cmdfile]
Deepak
PS: i have not included command file as i think probably need only the wrapper.
#!/usr/bin/ksh
#set -xv
#################################################################################
#
#
# TITLE : exec_restore.ksh #
#
#
# REQUIREMENT : Define $LOG_BASE directory to
specify Log Location #
#
#
# PARAMETERS : -d specifies the SID of the target
database to restore #
# -f specifies the command file for
RMAN Restore #
#
#
# USAGE : exec_rman.ksh [-d SID] [-f
command_file] #
#
#
# OUTPUTS : Returns a -1 value if it encounters
an error else returns 0 #
#
#
: #
# - Validate arguments passed in
from command line #
# - Define Notification List and
add email id's of DBA's #
# - Abort if restore is already
in progress for SID passed#
# - Performs restore using RMAN
interface #
# - Checks log files and sends
appropriate notifications #
#
#
#################################################################################
#
*
# * DEFINE LOG FILES AND SPECIFY DEFAULT LOCATION FOR
$LOGBASE *
# *
*
sync;sync;sync
export LOG_BASE=
export LOG_BASE=/opt/oracle/product/admin/sql/rman/log
export EXECRMAN_LOG=$LOG_BASE/exec_restore.ksh.`date
+%m.%d.%Y:%H:%M:%S`.log
export
WORKFILE_MULTI_CALLS=$LOG_BASE/rman_multi_call_detector.$$.log
export WORKFILE_LOGFILE=$LOG_BASE/rman_logfile.`date
+%m.%d.%Y:%H:%M:%S`.log
touch $EXECRMAN_LOG # Main Wrapper LogFile touch $WORKFILE_LOGFILE # RMAN Generated Batch LogFile touch $WORKFILE_MULTI_CALLS # Multi Invoke DetectMechanism
#
*
# * DEFINE NOTIFICATION LIST (comma separated)
*
# *
*
RMAN_NOTIFY='dthapliyal_at_ea.com,deepakthapliyal_at_yahoo.com'
#
*
# * DEFINE USAGE FOR SCRIPT AND GENERIC VARIABLES
*
# *
*
HOSTID=`hostname`
#Host Identity
SENDALERT=/usr/bin/mailx
#Mailing Interface
export ORATAB=/var/opt/oracle/oratab
#Oratab Location
USAGE="\nUsage: $0 [-d SID] [-f rman_cmdfile]\n"
#Usage of Wrapper
#
*
# * ACCEPT AND VALIDATE COMMAND-LINE ARGUMENTS
*
# *
*
while getopts :d:f: arguments
do
case $arguments in
d)
RMAN_TARGSID=$OPTARG ;; f) RMAN_CMDFILE=$OPTARG ;; \?) print "\n$OPTARG is not a valid argument" print $USAGE exit -1
#
*
# * VERIFY THAT A DATABASE INSTANCE WAS GIVEN AS AN
ARGUMENT AND IS VALID *
# *
*
if [ "$RMAN_TARGSID" = "" ]; then
print $USAGE
exit -1
fi
grep -i "^$RMAN_TARGSID:" $ORATAB > /dev/null 2>&1 if [ $? != 0 ]; then
print "\nTarget Database $RMAN_TARGSID is not valid"
print $USAGE
exit -1
fi
#
*
# * VERIFY THAT A READABLE COMMAND FILE WAS GIVEN AS
AN ARGUMENT *
# *
*
if [ "$RMAN_CMDFILE" = "" ]; then
print $USAGE
exit -1
fi
if [ ! -r $RMAN_CMDFILE ]; then
print "\nSuppplied Command File $RMAN_CMDFILE is not valid"
print $USAGE
exit -1
fi
#
*
# * SOURCE IN ORACLE/RMAN ENVIRONMENT VARIABLES
*
# *
*
export ORACLE_USER=oracle export ORACLE_SID=$RMAN_TARGSID export ORACLE_HOME=/opt/oracle/product/816export PATH=$ORACLE_HOME/bin:$PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH export NLS_LANG=american export NLS_DATE_FORMAT='Mon DD YYYY HH24:MI:SS'
#
*
# * EXIT ON DETECTION OF OTHER RUNNING COPIES OF
CURRENT SCRIPT FOR SAME SID *
# *
*
#ps -ef | grep exec_restore.ksh | grep $RMAN_TARGSID |
grep -v grep | grep -v "sh -c" | grep -v $$ >
$WORKFILE_MULTI_CALLS 2>&1
ps -ef | grep $0 | grep $RMAN_TARGSID | grep -v grep |
grep -v "sh -c" | grep -v $$ > $WORKFILE_MULTI_CALLS
2>&1
if [ $? = 0 ]; then # Found Another Instance Running
echo >> $WORKFILE_MULTI_CALLS
echo "Restore Currently Going on $HOSTID for
$ORACLE_SID. Aborting ..." >> $WORKFILE_MULTI_CALLS
RMAN_SUBJECT="$HOSTID RMAN Aborted - Restore in Progress FOR $ORACLE_SID"
cat $WORKFILE_MULTI_CALLS | $SENDALERT -s "$RMAN_SUBJECT" -n $RMAN_NOTIFY
exit -1
fi
rm $WORKFILE_MULTI_CALLS > /dev/null 2>&1
#
*
# * SEND OUTPUT HEADER / START TIME / RESTORE CMDFILE
TO MAIN WRAPPER LOG *
# *
*
START_DATE=$(date)
echo
"**********************************************************" >> $EXECRMAN_LOG echo "$0 Run on $(date)" >> $EXECRMAN_LOG echo "attempting to restore on $HOSTID for $ORACLE_SID" >> $EXECRMAN_LOG
"**********************************************************" >> $EXECRMAN_LOG echo >> $EXECRMAN_LOG echo >> $EXECRMAN_LOG echo "Contents of CMDFILE: $RMAN_CMDFILE" >> $EXECRMAN_LOG echo >> $EXECRMAN_LOG cat $RMAN_CMDFILE >> $EXECRMAN_LOG
#
*
# * Launch RMAN Restore COMMANDS
*
# *
*
echo >> $EXECRMAN_LOG echo "LAUNCHING RMAN RESTORE JOB .." >> $EXECRMAN_LOG echo >> $EXECRMAN_LOG
$ORACLE_HOME/bin/rman cmdfile $RMAN_CMDFILE log
$WORKFILE_LOGFILE
STATUS=$?
#
*
# * SEND RMAN LOG and RESTORE COMPLETION TIME TO MAIN
WRAPPER LOG *
# *
*
echo >> $EXECRMAN_LOG
cat $WORKFILE_LOGFILE >> $EXECRMAN_LOG
echo >> $EXECRMAN_LOG
echo "RMAN STATUS: $STATUS" >> $EXECRMAN_LOG
echo >> $EXECRMAN_LOG
echo >> $EXECRMAN_LOG
echo "RMAN Restore Start Time:$START_DATE" >>
$EXECRMAN_LOG
echo >> $EXECRMAN_LOG
echo "RMAN Restore End Time:\t`date`" >>
$EXECRMAN_LOG
echo >> $EXECRMAN_LOG
#
*
# * IF ORACLE ERRORS (ORA-XXXXX) OR CRITICAL RMAN
ERRORS WERE ENCOUNTERED *
# * DURING THE EXECUTION OF THE RESTORE. IN EITHER
CASE, THE OUTPUT SHOULD *
# * BE SENT TO THE RMAN LOG AND SENT TO THE
NOTIFICATION GROUP. *
# *
*
sync;sync;sync;
egrep -i "ORA-|error message stack|RMAN-00569|error
occurred" $EXECRMAN_LOG > /dev/null 2>&1
if [ $? = 0 ]; then
RMAN_SUBJECT="Error occurred on $HOSTID for $ORACLE_SID!! (see $EXECRMAN_LOG)"
cat $EXECRMAN_LOG | $SENDALERT -s "$RMAN_SUBJECT" -n "$RMAN_NOTIFY"
exit -1
else
RMAN_SUBJECT="$HOSTID RMAN RESTORE Summary FOR
$ORACLE_SID"
cat $EXECRMAN_LOG | $SENDALERT -s
"$RMAN_SUBJECT" -n "$RMAN_NOTIFY"
exit 0
fi
#
*
*
# * EXECRMAN_LOG : Main Log File for Wrapper
{Not Deleted} *
# * WORKFILE_LOGFILE : RMAN Batch Mode Log File
{Not Deleted} *
# * WORKFILE_MULTI_CALLS : Multiple Instance Detector
{Deleted if success} *
# *
*
-- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Deepak Thapliyal INET: deepakthapliyal_at_yahoo.com Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Tue Oct 23 2001 - 16:18:55 CDT
![]() |
![]() |