Bash scripting for RSync logging

The following bash script is used to email a snapshot of the rsync job status upon completion of the job:


#!/bin/sh

RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=/home/rsync/cron/key
RUSER=rsync
RHOST=portal.rhost.com
RPATH=/media/DOC_CONTROL/
LPATH=/rhost/DOC_CONTROL
LOGFILE=/home/rsync/rsync.log

$RSYNC -azhh --stats --log-file=$LOGFILE -e "$SSH -i $KEY" $RUSER@$RHOST:$RPATH $LPATH

EMAIL=user@rhost.com
BODY=/home/rsync/email-body.tmp

if [ $? -eq 0 ]
then
STATUS=SUCCESS
else
STATUS=FAILURE
fi

echo -e "Backup Job Summary:\n" > $BODY
/usr/bin/tail -14 /home/rsync/rsync.log >> $BODY
echo -e "\nFile System Usage\n" >> $BODY
/bin/df -h | head -1 >> $BODY
/bin/df -h | grep startllc >> $BODY
echo -e "\n----END LOG----" >> $BODY

/bin/mail -s "$STATUS : Document Control Backup" "$EMAIL" < $BODY

and the email notification looks like:


From: xxxxx
Sent: xxxxx
To: xxxxx
Subject: SUCCESS : Document Control Backup

Job Summary:

2015/02/26 14:13:28 [7170] Number of files: 3282
2015/02/26 14:13:28 [7170] Number of files transferred: 0
2015/02/26 14:13:28 [7170] Total file size: 5.91G bytes
2015/02/26 14:13:28 [7170] Total transferred file size: 0 bytes
2015/02/26 14:13:28 [7170] Literal data: 0 bytes
2015/02/26 14:13:28 [7170] Matched data: 0 bytes
2015/02/26 14:13:28 [7170] File list size: 98.46K
2015/02/26 14:13:28 [7170] File list generation time: 0.002 seconds
2015/02/26 14:13:28 [7170] File list transfer time: 0.000 seconds
2015/02/26 14:13:28 [7170] Total bytes sent: 352
2015/02/26 14:13:28 [7170] Total bytes received: 99.74K
2015/02/26 14:13:28 [7170] sent 352 bytes received 99.74K bytes 28.60K
bytes/sec
2015/02/26 14:13:28 [7170] total size is 5.91G speedup is 61895.84
2015/02/26 14:13:28 [7168] sent 353 bytes received 102155 bytes total size
6343704911

File System Usage

Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 2.7T 1.4T 1.2T 55% /rmount

----END LOG----

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>