ZFS Monitor ZFS snapshots

Do you guys have a good way to monitor ZFS snapshots? Sometimes they are not removed and use up precious space. I was looking into using sanoid for this though doesn't always work as expected.
Main goal: list snapshots, if they exists and they are older than a year send a notification, or if they are fresh but space is low send a notification.
If nothing else I can write a script for it just wanted to look around first.
 
Thank you!
Sometimes we create a manual snapshot before OS update, pkg update, etc. and never gets removed. I mostly want to monitor these. Not really looking for another management tool, unless, of course the tool does what I'm looking for.
 
Maybe my post wasn't clear, I'm ONLY looking for this: list snapshots, if they exists and they are older than a year send a notification, or if they are fresh but space is low send a notification.
 
To me that sounds like a use case simple enough that wouldn't justify evaluating 3rd-party tooling and all the necessary procedures to ensure what you put into production is "safe and sound".
For this simple case I´d just go with writing your own shell script using built-in tooling such as zfs list, awk and so on as SirDice mentioned.
 
Script something yourself? Just grab a list of snapshots, check the creation property and destroy it if it's too old? Shouldn't be more than a few lines of script.
 
Not extensively tested but should get you started:
Code:
#!/bin/sh

LASTWEEKEPOCH=$(date -v-1w "+%s")

zfs list -r -t snapshot -H -o name | while read snapshot; do
  SNAPDATE=$(zfs get -H -o value creation $snapshot)
  SNAPEPOCH=$(date -j -f "%a %b %d %R %Y" "${SNAPDATE}" "+%s")

  if [ "${SNAPEPOCH}" -lt "${LASTWEEKEPOCH}" ]; then
    echo "$snapshot is more than a week old"
  fi
done
 
Not extensively tested but should get you started:
Code:
#!/bin/sh

LASTWEEKEPOCH=$(date -v-1w "+%s")

zfs list -r -t snapshot -H -o name | while read snapshot; do
  SNAPDATE=$(zfs get -H -o value creation $snapshot)
  SNAPEPOCH=$(date -j -f "%a %b %d %R %Y" "${SNAPDATE}" "+%s")

  if [ "${SNAPEPOCH}" -lt "${LASTWEEKEPOCH}" ]; then
    echo "$snapshot is more than a week old"
  fi
done
I think this is looking pretty good, thank you!
 
Back
Top