Windows previous versions for ZFS backed Samba shares

If you want ZFS’s snapshots to show up as previous versions in Windows File Shares you need to have ZFS backed, samba data set with 1 or more snapshots. My zfs data set is tank in my examples. A snapshot can be made manually or automatically. The easy way to manage automatic snapshots is to use ‘zfs-auto-snapshot’ that is bundled with zfsonlinux. Example for hourly snapshots of the tank.
zfs-auto-snapshot -l hourly tank
Or you can use cron to do hourly snapshots for you.
5 */1 * * * zfs snapshot tank@`date +%F-%H%M`
Also cron can clean up old snapshots. (Careful with this one. Verify zfs list -H -o name -t snapshot -r tank | head -n 24 output first)
30 0 * * * zfs list -H -o name -t snapshot -r tank | head -n 24 | xargs -n1 sudo zfs destroy

Lastly to have samba to use ZFS snapshots you’ll need shadow: format, vfs objects, shadow: sort, and shadow: snapdir added to your samba share. Here is example config with if using zfs-auto-snapshot hourly.

shadow: format = zfs-auto-snap_hourly-%F-%H%M
vfs objects = shadow_copy2
shadow: sort = desc
path = /tank
comment = ZFS dataset with Previous Versions enabled
writeable = yes
public = yes
shadow: snapdir = .zfs/snapshot

Leave a Reply