Skip to content

Instantly share code, notes, and snippets.

@sporkus
Created November 11, 2022 04:44
Show Gist options
  • Save sporkus/2dfaafe582b9385b09a1ad7809189b43 to your computer and use it in GitHub Desktop.
Save sporkus/2dfaafe582b9385b09a1ad7809189b43 to your computer and use it in GitHub Desktop.
Exposing zfs snapshot to windows previous version using samba vfs_shadow_copy2

Exposing zfs snapshot to windows previous version using samba vfs_shadow_copy2

This was much trickier than I had originally anticipated and have spent a few hours testing.

The config from samba wiki absolutely works, but it wasn't ranked higher in search engine and it's not general enough. https://github.com/zfsonlinux/zfs-auto-snapshot/wiki/Samba

Tested on ubuntu 22.04LTS, samba 4.15.9 and windows 11.

TLDR

If you snapshot utility labels the snapshot in a format other than [wildcard][timestmap], it's unlikely that it will work. sanoid and zfsnap both have dynamic labels after the timestamp, so they won't work.

Wildcard prefix

The default names for zfs-auto-snapshot is zfs-auto-snap_[label]_%Y-%m-%d-%H%M. This is the minimal viable config.

vfs_objects = shadow_copy2
shadow:snapdir = .zfs/snapshot
shadow:snapprefix = .*
shadow:delimiter = -20
shadow:format = -%Y-%m-%d-%H%M

Optional:

shadow:snapdirseverywhere = yes

Things that don't

Don't try to get creative, shadow_copy2 is extremely particular.

  • -20 works as NULL for shadow:delimiter. I haven't found anything else that worked in its place. Dashes, hypens, regex patterns, alpha only strings, quoted, empty quotes, etc etc.
  • removing the leading - from shadow:format.
  • Using regex anywhere besides shadow:snapprefix
  • Quoting your parameter

Examples that don't work

shadow:snapprefix = zfs-auto-snap_hourly
shadow:delimiter = -
shadow:format = %Y-%m-%d-%H%M
shadow:snapprefix = zfs-auto-snap
shadow:delimiter = _hourly-
shadow:format = %Y-%m-%d-%H%M
shadow:snapprefix = zfs-auto-snap_
shadow:delimiter = hourly
shadow:format = -%Y-%m-%d-%H%M
shadow:format = .*-%Y-%m-%d-%H%M

Examples that do work

The original config from samba wiki, but won't generalize for other snapshot naming pattern.

vfs objects = shadow_copy2
shadow:snapdir = .zfs/snapshot
shadow:format = -%Y-%m-%d-%H%M
shadow:snapprefix = ^zfs-auto-snap_\(frequent\)\{0,1\}\(hourly\)\{0,1\}\(daily\)\{0,1\}\(monthly\)\{0,1\}
shadow:delimiter = -20

If you don't need regex/wildcards, then using just hard code everything in shadow:format.

vfs objects = shadow_copy2
shadow: snapdir = .zfs/snapshot
shadow: sort = desc
shadow: format = zfs-auto-snap_hourly-%Y-%m-%d-%H%M

Other notes

  • sanoid uses : in the snapshot names, vfs objects = catia and some extra catia config is needed for the folders under the hidden .zfs to display properly.
  • Using some of the shadow options will force you to specify another option. For example: snapprefix and snapdir. Read the manpage carefully.
  • The zfs-auto-snapshot package from ubuntu installs cron jobs in /etc/cron.d, /etc/cron.hourly, and etc.
@Starover27
Copy link

ничего не понятно, особенно $ git add .
$ git commit -a

@favtony
Copy link

favtony commented Jun 28, 2024

thanks electr1cBugaloo's investigation!

I have further info when using samba in docker:
TLDR: consider add :shared or :slave suffix when mounting dataset into container
check docker bind mount for more info.

I run samba in docker, and I found that although snapshots are shown, they are usually empty when opened.
then I found that zfs might need to mount snapshot to be able to view it, but docker's default mount propagation policy will not allow mount propagation after container started.

I used :shared and it works, and on on child datasets too, even though the doc said only r prefix support nested mounts' propagation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment