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:
parent
8d48656d2f
commit
cb520c65ef
25
snapsend.sh
25
snapsend.sh
@ -13,11 +13,14 @@ DATASETS="datastore/vm"
|
|||||||
|
|
||||||
# Destination host for snapshot replication
|
# Destination host for snapshot replication
|
||||||
# The user must have enought rights to use `zfs command`
|
# The user must have enought rights to use `zfs command`
|
||||||
DHOST="root@192.168.42.52"
|
DHOST="root@192.168.0.100"
|
||||||
|
|
||||||
# Output logfile
|
# Output logfile
|
||||||
LOGFILE="/var/log/snapsend/snapsend.log"
|
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)
|
# Tools that help implement snapshot logic (and transfer soon according the pull-requests)
|
||||||
ZSNAP="/usr/local/bin/zfSnap.sh"
|
ZSNAP="/usr/local/bin/zfSnap.sh"
|
||||||
|
|
||||||
@ -79,6 +82,7 @@ usage()
|
|||||||
if [ ! -f "${LOGFILE}" ]; then
|
if [ ! -f "${LOGFILE}" ]; then
|
||||||
mkdir -p $(dirname ${LOGFILE})
|
mkdir -p $(dirname ${LOGFILE})
|
||||||
touch "${LOGFILE}"
|
touch "${LOGFILE}"
|
||||||
|
touch "${TEMP_MAIL}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "${interval}" in
|
case "${interval}" in
|
||||||
@ -105,10 +109,10 @@ case "${interval}" in
|
|||||||
# Send the snapshot the remote host
|
# 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 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}"
|
zfs send -I "${DHOSTSNAP}" "${dset}@${LOCALSNAP}" | ssh "${DHOST}" zfs recv "${dset}"
|
||||||
printf ' ... done\n' >> $LOGFILE
|
printf ' ... DONE\n' >> $LOGFILE
|
||||||
else
|
else
|
||||||
# Mail admin
|
# 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
|
printf 'ERROR snapshot %s for %s does not exist on the local system\n' ${DHOSTSNAP} ${dset} >> $LOGFILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -120,7 +124,7 @@ case "${interval}" in
|
|||||||
zfs rename ${dset}@${DHOSTSNAP} ${dset}@${PREFIXSNAP}${DHOSTSNAP}
|
zfs rename ${dset}@${DHOSTSNAP} ${dset}@${PREFIXSNAP}${DHOSTSNAP}
|
||||||
else
|
else
|
||||||
# Mail admin
|
# 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
|
printf 'ERROR snapshot %s for %s does not exist on the remote host (%s)\n' ${LOCALSNAP} ${dset} ${DHOST} >> $LOGFILE
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -141,12 +145,19 @@ case "${interval}" in
|
|||||||
# take snapshots, keep for one week
|
# take snapshots, keep for one week
|
||||||
for dset in $DATASETS
|
for dset in $DATASETS
|
||||||
do
|
do
|
||||||
$ZSNAP -v -s -S -a 1w $dset >> $LOGFILE
|
$ZSNAP -v -s -S -a 1w $dset >> $TEMP_MAIL
|
||||||
done
|
done
|
||||||
|
|
||||||
# Purge snapshots according to TTL
|
# Purge snapshots according to TTL
|
||||||
$ZSNAP -v -s -S -d -p ${PREFIXSNAP} >> $LOGFILE
|
$ZSNAP -v -s -S -d -p ${PREFIXSNAP} >> $TEMP_MAIL
|
||||||
printf '\n' >> $LOGFILE
|
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' )
|
'weekly' )
|
||||||
|
Loading…
Reference in New Issue
Block a user