Script to Email the Database Backup Status

Database backup is very important for its recovery from a crash. The administrator has to ensure that a backup is taken regularly. Here is a shell script to check and report the status of the backup via an email.

#!/bin/sh


. ~/.profile

# -------- Set variables per your requirement ---------

MAILSEND=/tmp/.mail.send
SID=REPLACE_THIS_WITH_YOUR_SID
mail_recipient=REPLACE_THIS_WITH_YOUR_EMAIL_ID
# -----------------------------------------------------

# Check for backup log file

if [ -f /oracle/${SID}/sapbackup/back${SID}.log ]
then

# extract date information

print The previous backup was attempted on `tail -1 /oracle/${SID}/sapbackup/back${SID}.log | awk '{print $3}'` > $MAILSEND

# extract return code information

rc=`tail -1 /oracle/${SID}/sapbackup/back${SID}.log | awk '{print $7}'`

# check if backup is currently active

if [ ` ps -eaf | grep ${SID} | grep brbackup |wc -l` -gt 0 ]
then
rc=7
fi

# decode return codes

case $rc in
0) print The backup was successful >> $MAILSEND ;;
1) print The backup ended with warnings. All files were backed up. >> $MAILSEND ;;
2) print The backup was terminated in the initialization phase by a user or other signal. >> $MAILSEND ;;
3) print Errors occurred in the initialization phase. The backup was not started. >> $MAILSEND ;;
4) print The backup was terminated during processing by a user or other signal. >> $MAILSEND ;;
5) print The backup was started but not finished, because of errors during processing. >> $MAILSEND ;;
6) print The backup ended due to an internal termination. >> $MAILSEND ;;
7) print The backup is active. >> $MAILSEND ;;
*) print The return code of the backup could not be understood. >> $MAILSEND ;;
esac

else


# if the backup log is not available

print Details of backup are not available >> $MAILSEND
fi

# send email

mail -s "Backup status of ${SID}" ${mail_recipient} < $MAILSEND
exit 0



Recommended Reading
SAP Administration - Practical Guide

A practical guide to commonly performed system administrator tasks, this book provides you with concrete and detailed instructions on how to perform both routine and special activities, using step-by-step instructions and hundreds of screenshots. In addition, the appendices provide you with lists of transaction codes, help topics, and SAP Notes. This book serves as an up-to-date resource based on release 7.0/7.1 of NetWeaver AS ABAP.

Comments

Popular posts from this blog

OS/DB Migration - CMD. STR, TOC, EXT, R3load, DDLDBS.TPL and more

Fixing Inconsistent Table - Table activation fails due to inconsistency between DD and DB

301 Redirect Using SAP Web Dispatcher