Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- HOST=`hostname -s`
- CONFIG=`dirname ${0}`"/submit.cf"
- BCC=""
- SUBJECT="Daily Backup on ${HOST}"
- NAME="server "`uname -n`
- M_BODY=""
- D_NOW=`/bin/date +%c`
- W_DAY=`/bin/date +%A`
- if [[ "$W_DAY" = "Monday" ]]
- then
- Y_DAY=`date +%Y-%b-%d -d "Today - 2 days"`
- else
- Y_DAY=`date +%A -d "Today - 1 day"`
- fi
- err_msg ()
- {
- EMSG=" ERROR Detected while running backup for ${D_SET}"
- M_BODY="${M_BODY}"$'\n'$'\n'" -- "$'\n'$'\n'"${EMSG}"$'\n'$'\n'" ${1} --"
- SUBJECT="ERROR: Daily Backup on ${HOST}"
- }
- snd_email ()
- {
- BODY=$1
- echo -e "To: ${TO}
- Cc: ${CC}
- Bcc: ${BCC}
- Subject: ${SUBJECT}
- User-Agent: Heirloom mailx 12.4 7/29/08
- MIME-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- Daily Backup on ${HOST} completed with the following messages
- ${BODY}
- -- Linux automated notification script
- "|/usr/sbin/sendmail -vt -f${FROM} -C${CONFIG}
- }
- EMSG=""
- M_BODY=""
- for D_SET in $*
- do
- if [[ -z "${D_SET}" ]]
- then
- err_msg "Filesystem argument is NULL"
- continue
- fi
- ZFS_1=`/sbin/zfs get -H type ${D_SET}|cut -d $'\t' -f 1`
- if [[ ${ZFS_1} != ${D_SET} ]]
- then
- err_msg "Argument is NOT a ZFS filesystem name"
- continue
- fi
- if [[ -n `/sbin/zfs list -H -t snapshot ${D_SET}@${W_DAY}` ]]
- then
- /sbin/zfs destroy -r ${D_SET}@${W_DAY}
- if [[ "${?}" -ne "0" ]]
- then
- err_msg "Failure destroying existing snapshots for ${D_SET}@${W_DAY}"
- continue
- fi
- fi
- /sbin/zfs snapshot -r ${D_SET}@${W_DAY}
- if [[ "${?}" -ne "0" ]]
- then
- err_msg "Failure creating zfs snapshots for ${D_SET}@${W_DAY}"
- continue
- fi
- ssh gemini "/sbin/zfs destroy -r ${D_SET}@${W_DAY}"
- if [[ "${?}" -ne "0" ]]
- then
- err_msg "Failure Destroying snapshots on gemini for ${D_SET}@${W_DAY}"
- fi
- /sbin/zfs send -R -i ${D_SET}@${Y_DAY} ${D_SET}@${W_DAY}| nc -w 200 gemini 8023
- if [[ "${?}" -ne "0" ]]
- then
- err_msg "Failure sending zfs incremental snapshots to gemini for ${D_SET}@${W_DAY}"
- continue
- fi
- LOC_N=`/sbin/zfs list -r -t snapshot ${D_SET}| grep @${W_DAY}|wc -l`
- LOC_R=`ssh gemini "/sbin/zfs list -r -t snapshot ${D_SET}| grep @${W_DAY}|wc -l"`
- if [[ "${LOC_N}" -ne "${LOC_R}" ]]
- then
- err_msg "Error, snapshot count inconsistency between atlas & gemini for ${D_SET}@${W_DAY}; atlas=${LOC_N} , gemini=${LOC_R}"
- continue
- fi
- if [[ "${EMSG}K" = "K" ]]
- then
- M_BODY="${M_BODY}"$'\n'$'\n'" No problems were detected for backup of ${D_SET}.(atlas=${LOC_N} , gemini=${LOC_R}) "$'\n'" The backed up data as of ${D_NOW} is found in"$'\n'" .zfs/snapshot/${W_DAY}"
- ssh gemini 'echo "pass" > /var/lib/zfs-scripts/daily.status'
- else
- M_BODY="${M_BODY}"$'\n'$'\n'" ATTENTION: Errors were detected for backup of ${D_SET}.(atlas=${LOC_N} , gemini=${LOC_R}) "$'\n'" The backed up data as of ${D_NOW} is found in"$'\n'" .zfs/snapshot/${W_DAY}"
- ssh gemini 'echo "fail" > /var/lib/zfs-scripts/daily.status'
- fi
- done
- snd_email "$M_BODY"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement