Shell script to check most recent ZFS snapshot

894 views Asked by At

I am running regular snapshots (zfs snapshot tank/name@$date).

This is working great, however, I want to add in a little bit more intelligence. In particular, I would like to run a cron that checks the most recent snapshot and if the snapshot is OLDER than X days then send an email alert.

Any ideas?

1

There are 1 answers

0
Joshuah On
status=$( zfs list -t snapshot -o name,creation -s creation -r tank/vm | tail -1 | cut -d ' ' -f 4,5,6,7,8,9 )

datenow=$( date +"%b %d %H:%M %Y" )

first_date=$(date -d "$datenow" "+%s")
second_date=$(date -d "$status" "+%s")

datediff=$(( ($first_date - $second_date)/(period=$((60*60))) ))
if [ "$datediff" -ge "1" ]
then
command to mail
else
command for mail
fi

Enjoy :)