Thursday 6 September 2018

BackupPC success mail triggering

Step 1

Go to Edit Config->Backup Setting and add the following lines into the DumpPostUserCmd

/opt/BackupPC/email_sample.sh $xferOK $host $type $client $hostIP $share $XferMethod $sshPath $cmdType

Before that we have to create email_sample.sh in that particular locations.

step 2

add the following scipt in email_sample.sh file and create  a txt file in /tmpas emailmessage.txt

#!/bin/bash
# script to send simple email
# Email To ?
EMAIL="your mail address"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"

# Grab the status variables
xferOK=$1
host=$2
type=$3
client=$4
#hostIP=$5
share=$6
XferMethod=$7
#TopDir=$8
#cmdType=$9

#Extract the info file
#LOG_FILE="/u01/BackupPC/pc/$host//backupInfo"
 

LOG_FILE=`ls -t /u01/BackupPC/pc/$host/*/backupInfo | /usr/bin/head -1`
 

# Check if backup succeeded or not.
if [[ $xferOK == 1 ]]; then
        STATUS="SUCCESS"
else
        STATUS="FAILED"
fi

# email subject
SUBJECT="[BackupPC] $STATUS for host: $client"

# Email text/message
echo "Filesystem backup for $host $STATUS" > $EMAILMESSAGE
echo "" >>$EMAILMESSAGE
echo "Type: $type" >>$EMAILMESSAGE
#echo "Client: $client" >>$EMAILMESSAGE
echo "Host: $host" >>$EMAILMESSAGE
#echo "Host IP: $hostIP" >>$EMAILMESSAGE
echo "Share: $share" >>$EMAILMESSAGE
echo "XferMethod: $XferMethod" >>$EMAILMESSAGE
#echo "BackupPath: $TopDir" >>$EMAILMESSAGE
#echo "cmdType: $cmdType" >>$EMAILMESSAGE
echo "BackupDetails: $LOG_FILE" >>$EMAILMESSAGE
cat $LOG_FILE >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE

 

I have # some details if you required that you can enable it. 

Then change the owner to backuppcuser and provide execute permission

chown backuppc:backuppc email_sample.sh

chmod +x email_sample.sh

Now you will receive success and failure message whenever the backup start. 

No comments:

Post a Comment

Permanent hostname setup for RHEL7

Step 1 Set the host name on NMTUI tool like following nmtui set host name   then save and exit Step 2 add the following l...