Snapsend:

* Send an email for the daily snapshot with the log in content
  * Add the hostname in the mail's subject (async and daily)
This commit is contained in:
Jeremy Gardais 2014-11-20 14:29:06 +01:00
parent 3df3bc5744
commit a98cb084ba
1 changed files with 17 additions and 6 deletions

View File

@ -18,6 +18,9 @@ DHOST="root@192.168.0.100"
# Output logfile
LOGFILE="/var/log/snapsend/snapsend.log"
# Temp file for mail content
TEMP_MAIL="/var/log/snapsend/temp.mail"
# Tools that help implement snapshot logic (and transfer soon according the pull-requests)
ZSNAP="/usr/local/bin/zfSnap.sh"
@ -79,6 +82,7 @@ usage()
if [ ! -f "${LOGFILE}" ]; then
mkdir -p $(dirname ${LOGFILE})
touch "${LOGFILE}"
touch "${TEMP_MAIL}"
fi
case "${interval}" in
@ -105,10 +109,10 @@ case "${interval}" in
# Send the snapshot the remote host
# zfs send -I datastore/vm@2014-11-17_11.26.22--1h datastore/vm@2014-11-18_14.19.10--1h | ssh nec02.ipr.univ-rennes1.fr zfs recv datastore/vm
zfs send -I "${DHOSTSNAP}" "${dset}@${LOCALSNAP}" | ssh "${DHOST}" zfs recv "${dset}"
printf ' ... done\n' >> $LOGFILE
printf ' ... DONE\n' >> $LOGFILE
else
# Mail admin
printf 'ERROR snapshot %s does not exist on the local system\n' ${DHOSTSNAP} | mail ${MAILADMIN} -s 'snapsend_error'
printf 'ERROR snapshot %s does not exist on the local system\n' ${DHOSTSNAP} | mail ${MAILADMIN} -s "snapsend_error $(hostname -f)"
printf 'ERROR snapshot %s for %s does not exist on the local system\n' ${DHOSTSNAP} ${dset} >> $LOGFILE
fi
@ -120,7 +124,7 @@ case "${interval}" in
zfs rename ${dset}@${DHOSTSNAP} ${dset}@${PREFIXSNAP}${DHOSTSNAP}
else
# Mail admin
printf 'ERROR snapshot %s for %s does not exist on the remote host (%s)\n' ${LOCALSNAP} ${dset} ${DHOST} | mail ${MAILADMIN} -s 'snapsend_error'
printf 'ERROR snapshot %s for %s does not exist on the remote host (%s)\n' ${LOCALSNAP} ${dset} ${DHOST} | mail ${MAILADMIN} -s "snapsend_error $(hostname -f)"
printf 'ERROR snapshot %s for %s does not exist on the remote host (%s)\n' ${LOCALSNAP} ${dset} ${DHOST} >> $LOGFILE
fi
done
@ -141,12 +145,19 @@ case "${interval}" in
# take snapshots, keep for one week
for dset in $DATASETS
do
$ZSNAP -v -s -S -a 1w $dset >> $LOGFILE
$ZSNAP -v -s -S -a 1w $dset >> $TEMP_MAIL
done
# Purge snapshots according to TTL
$ZSNAP -v -s -S -d -p ${PREFIXSNAP} >> $LOGFILE
printf '\n' >> $LOGFILE
$ZSNAP -v -s -S -d -p ${PREFIXSNAP} >> $TEMP_MAIL
printf '\n' >> $TEMP_MAIL
# Send email to admin
cat $TEMP_MAIL | mail ${MAILADMIN} -s "Daily snapshot $(hostname -f)"
# Send the previous log to the main logfile
cat ${TEMP_MAIL} >> ${LOGFILE}
rm -f ${TEMP_MAIL}
;;
'weekly' )