Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZFS-auto-Snapshot and Samba shadow: snapprefix interaction #84

Open
Terry-Bennett opened this issue Apr 5, 2018 · 17 comments
Open

ZFS-auto-Snapshot and Samba shadow: snapprefix interaction #84

Terry-Bennett opened this issue Apr 5, 2018 · 17 comments

Comments

@Terry-Bennett
Copy link

Terry-Bennett commented Apr 5, 2018

First off. My appologizes if this is not the right place to post this. I have tried the Samba forums.

Looking for a little assistance on this as I have been unsuccessful is
getting the shadow: snapprefix, shadow:delimiter and shadow:format to work
as I expect.

I have no issue with getting previous versions in Windows to show me either
hourly, daily or weekly, etc snapshots as previous versions. But I would
like to be able to expose all.

The shadow:snapprefix, etc seems to be the way to do it, but I am unable to
get it to work.
When I setup the prefix, etc, I get no previous versions at all.

My setup in Smb.conf is below, and my directories are named as follows:

shadow:snapprefix =
^(zfs-auto-snap_dai){0,1}(zfs-auto-snap_hour){0,1}$
shadow:delimiter = ly-
shadow:format = ly-%Y-%m-%d-%H%M

Directories :

zfs-auto-snap_daily-2018-01-01-1235
zfs-auto-snap_daily-2018-03-15-1135
zfs-auto-snap_daily-2018-03-29-1135
zfs-auto-snap_hourly-2018-04-03-1817
zfs-auto-snap_hourly-2018-04-04-0817
zfs-auto-snap_weekly-2018-01-17-1240

and a lot more then that
Etc, etc, etc

When I do something like : shadow: format =
zfs-auto-snap_hourly-%Y-%m-%d-%H%M

in the smb.conf, without the prefix, etc, there are no issues. I see the
hourlys appear in my previous versions.
I do understand that this might be outside the scope of this forum, but I thought maybe there is something in the zfs-auto-snapshot script that I could do to make it work, or other of you here have experience using the Samba shadow:snapprefix.

I am using the latest version of Samba, and Ubuntu 16.04, and your ZFS-auto-Snapshot.

Great script.

Any help would be appreciated.
Regards

@machthree
Copy link

I am by far an expert on this and my memory on how I set up my server is hazy but I have some notes which may help. As suggested by: #10 I edited the cron files to change the naming system (i.e. the label argument) for the snapshots following the scheme below:

* frequent -> 00  [/etc/cron.d/zfs-auto-snapshot]
* hourly -> 01  [/etc/cron.hourly/zfs-auto-snapshot]
* daily -> 02  [/etc/cron.daily/zfs-auto-snapshot]
* weekly -> 03   [/etc/cron.weekly/zfs-auto-snapshot]
* monthly -> 04 [/etc/cron.monthyl/zfs-auto-snapshot]

As a result of this the snapshots have the name format:
pool1/media@zfs-auto-snap_nn-YYYY-MM-DD-hhmm where nn matches one of the two digit numbers above.

I then made the following settings in my smb.conf file:

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

Note that the last argument is probably the most critical - it matches the format of the snapshots. In effects it uses %S (seconds I think) as a variable character that has no impact.

The snapshot directory can be made visible by issuing the following command (but you have probably done this already).

sudo set snapdir=visible pool1/media

I hope this helps.

@machthree
Copy link

Agreed - localtime is not a good idea.

However, the difficulty of setting up snapshots in a format that are suitable for visibility in a samba context might be worthy as considering as a bug/product deficiency. Perhaps the scripts and install could allow for that in some way?

Arguably samba could be modified to help setup ZFS appropriately. However, I think it would be reasonable to argue that samba shouldn't have to be aware of every file system but ZFS could be aware of this common use case for ZFS.

@Terry-Bennett
Copy link
Author

So, are you both talking about this localtime :
shadow: localtime = yes
Why is that a problem?

Thank you both for the insight on this. Yes, I do realize this is a bug tracker, but sometime when you exhaust other resources..... You go to the experts of the script.

@beren12
Copy link

beren12 commented Apr 5, 2018

There is a howto to make z-a-s work easily with samba shadow shares. it works great if you follow it. you can adjust your current snapshots to that style, add the properties it needs then rename.
https://github.com/zfsonlinux/zfs-auto-snapshot/wiki/Samba

@Terry-Bennett
Copy link
Author

Terry-Bennett commented Apr 5, 2018

Beren12, thanks for your input. Yes indeed, I can get the shadow copies to work without issue. The problem is, is that I want multiple levels of shadow copies. I don't just the frequents (Which I don't use). I want the hourlys, dailys, monthlys at the very least to show up.

It does appear that the #10 issues is how I need to go it. The regular expression method provided by Samba doesn't appear to work. Which is unfortunate because I didn't want to lose the naming of daily, montly, etc. I plan to have this end-user facing.

@beren12
Copy link

beren12 commented Apr 5, 2018

You still didn't read that page. Every snapshot is available because they have a common name. They use a property to tell z-a-s the type, it's not encoded into the name at all. you can convert your current snapshots to that as well by adding the correct property, then renaming them. Easy to script.

@Terry-Bennett
Copy link
Author

hummm, are you talking about the addition of the leecallen modifications??? I did not do because I don't really know how to do that. Specifically "Fix manual conflict". what ever that means.
I don't know how to do any of this :
git checkout leecallen
$ git merge master
$ editor src/zfs-auto-snapshot.sh (manually fix a conflict)
$ git add .
$ git commit -a

All I know, is that that stock script will not show all the various snapshots. It only shows the level based on the shadow: format entry in smb.conf

@beren12
Copy link

beren12 commented Apr 5, 2018

you just look in the file it tells you for conflicts. basically remove the conflict text. if the tool doesn't work, try again :)

@Terry-Bennett
Copy link
Author

Terry-Bennett commented Apr 5, 2018

I appreciate the comments, but I don't think that is a good way to do it. Beside, I don't want to mess with code I know nothing about. There should be absolutely no reason why I should have to change the naming to get this to work since Samba is suppose to have this built in now. Just my thoughts

@kmccormick
Copy link

I'm running 16.04's Samba, which doesn't support the snapprefix and delimiter options yet, but I think your problem is just your regular expression. From the docs: "The option only supports Basic Regular Expression (BRE)." (), {}, etc. are matched literally in BRE, not treated as grouping characters.

Try this:
^zfs-auto-snap_(hour)?(dai)?

@benpye
Copy link

benpye commented Oct 6, 2018

I realise this is an old issue, but I hope this can be helpful to someone. It's a bit of a hack but it works with the default zfs-auto-snapshot names and will be fine until 2100.

   vfs objects = shadow_copy2
   shadow: snapdir = .zfs/snapshot
   shadow: sort = desc
   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

@recklessnl
Copy link

@benpye thanks for sharing that - does this still work well for you? Have you used it in production?

@benpye
Copy link

benpye commented Aug 11, 2019

@recklessnl This works fine for me. My "production" use is a home server but I have no reason to think it shouldn't work in a production environment.

@recklessnl
Copy link

@benpye Could you help with the syntax to get this to work? I have my snapshots being written like this:

autosnap_2018-03-17_11:30:00_frequently
autosnap_2018-03-17_12:00:00_daily

And I can't get the snapprefix and formatting to work in Samba. What values should I use in order make Samba work with snapshots that are being made in the above format?

@DeViLRuNNeR-dev
Copy link

I don't think windows plays niceley with ':' chars in snapshot names.
But you could try the RegEx below:

shadow:format = autosnap_%Y-%m-%d_%H:%M:%S_([^_]*)$

Please let me know if that worked for you.

@DeViLRuNNeR-dev
Copy link

DeViLRuNNeR-dev commented Sep 18, 2019

@recklessnl & @benpye
I have done some testing myself and it turns out we can't use Windows Shadow Copies on Samba due to the naming of these snapshots. There is not option in SAMBA to catch the snapshottype (hourly, frequent) at the end of the snapshot name.

autosnap_frequently_ 2018-03-17_11.30.00 = Should be fine
autosnap_2018-03-17_11:30:00_frequently = can never work

Does anybody know how we make things work with snapshot names appending characters on the end of the name?

@sporkus
Copy link

sporkus commented Nov 11, 2022

I know this is an old issue. But this is one of the top results when I looking for help, so hopefully this will be visible to the next poor soul trying to figure this out.

A general wildcard pattern that works:

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

Like DeViLRuNNeR-dev says, naming pattern with wildcard after the timestamp won't work. Also, shadow:format doesn't accept any regex pattern; it needs to be parsed by strptime. Somehow -20 as a NULL parameter is also necessary for shadow:delimiter.

More examples and explanations in my gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants