If you've never used
inotifywait, it's pretty handy for when you want to snapshot a directory after a file is accessed, or written to, or moved to a watched directory, etc., like so:
inotifywait -r -m --exclude "/srv/downloads/incomplete/" -e moved_to "/srv/downloads/" | while read -r line; do sudo /usr/sbin/zfs snapshot rpool/downloads@snap_"$( /bin/date +%F-%T )"_completionSnap done
However, imagine you're watching a large directory tree where there may be many ZFS datasets, how would you know which dataset to snapshot?
httm has your back!
httm -m <INPUT_FILE> will detect and report back the mount of the ZFS dataset upon which that watched file resides, so you can use that mount/dataset in your snapshot scripts:
inotifywait -r -m --format %w%f --exclude "/srv/downloads/incomplete/" -e moved_to "/srv/downloads/" | while read -r line; do filemount="$(httm -m $line)" filedataset="$(mount | grep $filemount | cut -f1 -d' ')" sudo /usr/sbin/zfs snapshot $filedataset@snap_"$( /bin/date +%F-%T )"_completionSnap done
If you're comfortable with
httm making a few choices for you,
httm can also take a snapshot from using just the filename as input:
% sudo httm --snap /var/log/syslog httm took a snapshot named: rpool/ROOT/ubuntu_wi01vc/var/log@snap_Jun-25-2022-23:11:50_httmSnapFileMount
This last feature is ZFS only for right now.
Available now for 0.12.6 and later editions.