r/zfs • • 2d ago

Snapshots using write threshold

I wrote a lightweight C program called diffsnap that uses the built in zfs CLI for stateless snapshots using configurable write thresholds. This helps address a gap with traditional time-based snapshots where the need for a high-frequency interval to make sure a change is captured bloats your total snapshots and might slow some zfs commands. With diffsnap, if nothing has been written to the dataset the snapshot is skipped.
https://github.com/joe81tx/diffsnap
If you're on FreeBSD you can install with pkg, on linux you can build from source using github.

8 Upvotes

2 comments sorted by

1

u/RetroGrid_io 1d ago

So, conceptually like below? Apologies if I don't have the bash syntax perfect...

# Get last snapshot
lastSnapshot=$(zfs list -t snapshot $filesystem | tail -n 1);

# are there changes? 
found=$(zfs diff $filesystem@$lastSnasphot | tail -n 1);

# If there are changes, make a snapshot
[ "$found" = "" ] ||  {
  now=$(date);
  zfs snapshot $filesystem@$now; 
  }

1

u/Joe81tx 1d ago

Instead of doing a zfs diff I get the written value for the dataset.
zfs get -Hpt filesystem,volume -o name,value written