Skip to content

Instantly share code, notes, and snippets.

@drscream
Last active August 29, 2015 14:23
Show Gist options
  • Save drscream/4524462bfaee370b390e to your computer and use it in GitHub Desktop.
Save drscream/4524462bfaee370b390e to your computer and use it in GitHub Desktop.
#!/usr/bin/bash
# Thomas Merkel <[email protected]>
# Script created in 5 minutes to check if a snapshot exists on
# the machine that is created with the timestamp from yesterday.
# Which datasets would we check
ADMIN_MAIL="[email protected]"
CHECK_DATASETS="
zones/2510db0b-81ef-46bc-b38e-c5ffcbe48403/data/mbox-01
"
# Function
pipe_if_not_empty () {
input=$(cat);
if [ "x$input" != x"" ]; then
{ printf '%s\n' "${input}"; } | "$@"
fi
}
# Main
yesterday=$(date -d yesterday +%Y-%m-%d)
snapshots=$(zfs list -t snapshot -o name)
for dataset in ${CHECK_DATASETS}; do
if [[ $(echo ${snapshots} | grep -c "${dataset}@${yesterday}") -eq 0 ]]; then
echo "Not found: ${dataset}@${yesterday}"
fi
done | pipe_if_not_empty mailx -s "zbackup missing on $(hostname)" ${ADMIN_MAIL}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment