Exposing Sanoid ZFS snapshots as Windows Shadow Copies over Samba
By hernil
ZFS snapshots are super convenient for keeping dataset histories and fascilitating backups. Sanoid and Syncoid are commonly used abstractions on top of the ZFS native snapshot and send tools for managing taking and pruning snapshot with a policy based config.
In addition to being a nice security for a sysadmin we can actually expose some of these conveniences to the users of a Samba file share. Spesifically Windows users - by exposing the snapshot as “Windows Shadow Copies”.
Config
vfs objects = shadow_copy2, catia
catia:mappings = 0x22:0xa8,0x2a:0xa4,0x2f:0xf8,0x3a:0xf7,0x3c:0xab,0x3e:0xbb,0x3f:0xbf,0x5c:0xff,0x7c:0xa6
shadow: snapdir = .zfs/snapshot
shadow: sort = desc
shadow: format = _%Y-%m-%d_%H:%M:%S
shadow: snapprefix = ^autosnap
shadow: delimiter = _
shadow: localtime = no
Adding these settings to a standard smb.conf file (at least Samba 4) should do the trick.
shadow: snapdir = .zfs/snapshot
is where ZFS saves and exposes snapshots on the system. Note that .zfs
is hidden for commands like ls
, but you should be able to cd
to them manually if you want to browse these on the system.
shadow: format = _%Y-%m-%d_%H:%M:%S
together with snapprefix
and delimiter
tells Samba how to interpret the default Sanoid naming scheme of ZFS snapshots and translate those to something that Windows understands.
shadow: localtime = no
is needed because Sanoid timestamps snapshots in UTC rather than local time. This makes consolidating snapshots from various timezones less painfull.
catia:mappings
is basically a translating table for a bunch of characters that Windows does not understand as part of paths or file names. See separate post for these.
Sources
The main inspiration for these settings comes from this forum post.