Hello! If anyone like me likes to verify what files have changed between zfs snapshots, I have a simple post-hook success zfs diff script I use with Sanoid. You are free to use it, I kept it simple. Take it as is or give suggestions if you think you can make it better. Take care!
Example of conf file:
sh:
#!/bin/sh
# Sanoid post-hook to log ZFS snapshot diffs via syslog (FreeBSD style)
CONFIG_FILE="/usr/local/etc/zfs-diff.conf"
: "${SYSLOG_TAG:=zfs-diff}"
: "${SYSLOG_FACILITY:=local0}"
: "${SNAPSHOT_TYPE:=hourly}"
[ $# -eq 1 ] && CONFIG_FILE="$1"
[ -f "$CONFIG_FILE" ] && . "$CONFIG_FILE"
log() {
logger -p "${SYSLOG_FACILITY}.$1" -t "$SYSLOG_TAG" -- "$2"
}
[ -z "$TARGET_DATASETS" ] && log warn "No TARGET_DATASETS set" && exit 0
for ds in $TARGET_DATASETS; do
zfs list "$ds" >/dev/null 2>&1 || {
log warn "Dataset '$ds' not found"
continue
}
snaps=$(zfs list -t snapshot -o name -s creation -r "$ds" 2>/dev/null |
grep "^$ds@autosnap_.*_${SNAPSHOT_TYPE}$" | tail -n 2)
set -- $snaps
[ $# -lt 2 ] && log warn "$ds: fewer than 2 '${SNAPSHOT_TYPE}' snapshots" && continue
log info "zfs diff '$1' '$2'"
zfs diff -FHh "$1" "$2" 2>&1 | while IFS= read -r line; do
[ -n "$line" ] && log info "$line"
done
Example of conf file:
Code:
TARGET_DATASETS="tank/dataset1"
SYSLOG_TAG="zfs-diff"
SYSLOG_FACILITY="local0"
SNAPSHOT_TYPE="hourly"