Default you can only use a single snapshot schema for your "Restore previous version". The problem lays in the sambas shadow:format setting.
Lets examine one of my shares with testparm.
Pay attention for the shadow:format and shadow:snapdir. From shadow:format we see that samba will only dive into and search snapshot who start with auto- and have YYYYMMDD.HHMM and ends with -100d.
For example ...
auto-20170203.0930-100d
auto-20170204.0930-100d
auto-20170205.0930-100d
auto-20170205.0600-1w <-- this will be skipped.
So why don't we generate a script that takes all the snapshots and normalize them into a single format? As .zfs is write protected we have to make our list else where. It's should be no problem because we can specify the shadow:snapdir.
A tip here when you are writing a script is that call it from another script in a loop. Then you just have to save and bang your changes will be shown in the terminal.
It can be a bit tedious switching terminal window back and forth just to execute it.
Here is my loop script when I was testing and writing my main script
So after long weekend I end up with this ...
First we have the conf.
dryrun=true means that it will only output to terminal what it want to do.
uncomment the dryrun=false to make it run.
snapshot_dir and link_dir should be self explained.
The link_dir you must make your self. Set write permission to what user this script should be run under.
Verify that your snapshot schema is added to the normilize function.
From our testparm we copy the important pieces and paste into the Auxiliary Parameters.
Remeber also to include the VFS Object. For 9.3 it's shadow_copy2.
Remember to edit the shadow:format and shadow:snapdir and also unselect the Periodic Snapshot Task:
Bellow you have an easy copy and paste
.....
shadow:snapdirseverywhere = yes
shadow:format = %Y%m%d.%H%M
shadow:localtime = yes
shadow:sort = desc
shadow:snapdir = .zfs_links
.....
Now you set up a cron job ..
Don't be so foolish as I'am by using the user root.
When all this done you can peek into symlink_directory (the example above is .zfs_link) to see when list is starting populate.
Be a bit patient, for me I have to disconnect the mapped letter (or I was patient ... it finally started show something).
And voila ..
As you can see the last snapshot or Restore previous version slot is way off the other ones (2017-03-05 09:57).
I find this interesting, do you ?.
**** NOTE I take no responsibility for your data while you are using this script. ****
Hmm I think it works ... still testing
... after some testing .. bah it seems to default to first snapshot schema. What you get from testparm is not necessary the conf. for samba it seems.
... back to ground zero again ...
Lets examine one of my shares with testparm.
Code:
... [data] path = /mnt/Vol_1/data read only = No guest ok = Yes ea support = No case sensitive = Yes preserve case = No short preserve case = No hide dot files = No veto files = /.snapshot/.windows/.mac/.zfs/ map archive = No map readonly = no store dos attributes = No vfs objects = shadow_copy2 zfs_space zfsacl aio_pthread streams_xattr recycle recycle zfsacl:acesort = dontcare nfs4:chown = true nfs4:acedup = merge nfs4:mode = special shadow:snapdirseverywhere = yes shadow:format = auto-%Y%m%d.%H%M-100d shadow:localtime = yes shadow:sort = desc shadow:snapdir = .zfs/snapshot recycle:subdir_mode = 0700 recycle:directory_mode = 0777 recycle:touch = yes recycle:versions = yes recycle:keeptree = yes recycle:repository = .recycle/%U ...
Pay attention for the shadow:format and shadow:snapdir. From shadow:format we see that samba will only dive into and search snapshot who start with auto- and have YYYYMMDD.HHMM and ends with -100d.
For example ...
auto-20170203.0930-100d
auto-20170204.0930-100d
auto-20170205.0930-100d
auto-20170205.0600-1w <-- this will be skipped.
So why don't we generate a script that takes all the snapshots and normalize them into a single format? As .zfs is write protected we have to make our list else where. It's should be no problem because we can specify the shadow:snapdir.
A tip here when you are writing a script is that call it from another script in a loop. Then you just have to save and bang your changes will be shown in the terminal.
It can be a bit tedious switching terminal window back and forth just to execute it.
Here is my loop script when I was testing and writing my main script
Code:
while true; do clear # clear screen dir='/home/pernils/d/links' touch $dir/tmp rm $dir/tmp_ln1 rm $dir/tmp_ln2 ln -s $dir/tmp $dir/tmp_ln1 ln -s $dir/tmp $dir/tmp_ln2 rm $dir/tmp # the above is for generate broken symlink ./make_symlink.sh # my main script done
So after long weekend I end up with this ...
Code:
#!/bin/bash dryrun="true" # Dryryn simulate mode. For live system set it to false #dryrun="false" # snapshot_dir='/mnt/Vol_1/data/.zfs/snapshot' # snapshot_dir is the directory where your snapshot is located. # # tex /mnt/Vol_1/dataset/.zfs/snapshot # link_dir='/mnt/Vol_1/data/.zfs_links' # link_dir is where your symlinks to your snapshot will be saved. # # tex /mnt/Vol_1/dataset/.zfs_links # # ************************************************** # # Normilize the snapshot name # # ************************************************** # Add your snapshot schema suffix to be include # function normilize { # strip out prefix "auto-" and suffix like "-1d, -1w" etc # add your own suffix if needed item=$1 # first argument item=$(echo $item | sed -e 's/auto-//') # remove prefix auto- item=$(echo $item | sed -e 's/-1d//') # remove trailing -1d item=$(echo $item | sed -e 's/-100d//') # remove trailing -100d item=$(echo $item | sed -e 's/-1w//') # remove trailing -1w item=$(echo $item | sed -e 's/-2w//') # remove trailing -2w # your edit goes in above ..... item=$(echo $item | sed -e 's/\///') # remove trailing / echo $item # form return value } if $dryrun; then echo " **** Deletes broken snapshots ****" fi # ****************** Main start ********************* # # Clenup of broken symlinks # # *************************************************** # # Broken symlink means snapshot that have been deleted /rotated # for item in $(find -L $link_dir -maxdepth 1 -type l ) do if $dryrun; then echo "<broken symlink>... rm $item" else rm $item # deletes broken sym link fi done if $dryrun; then echo echo " **** Collectings snapshots ****" fi # ************************************************** # # Collect the snapshot list # # ************************************************** # Collecting all snapshots that start with prefix auto- # This list is store into $snap_array i=0 #counter for snap_array snap_array=() #initilize the array for item in $(find $snapshot_dir -mindepth 1 -maxdepth 1 -type d ); do item=$(echo $item | sed -e "s|$snapshot_dir/||") # strip off prefix $snapshot_dir if grep -q '^auto-' <<< $item; then #grep -q quit no output snap_array[$i]=$(echo $item | sed -e 's/\///') # removes trailing / if $dryrun; then echo "<found snapshot>.." ${snap_array[$i]} fi i=$((i+1)) # inc counter fi done if $dryrun; then echo echo " **** Writing new symlinks ****" fi # ************************************************** # # Writing new symlinks # # ************************************************** # Loops throw $snap_array and wrtite symlink that don't exists # for item in ${snap_array[@]} do normitem=$(normilize $item) # check if normilized $item -> $normitem can't be found aka ! if ! test -n "$(find $link_dir/ -name $normitem -type l)"; then if $dryrun; then echo "... ln -s $snapshot_dir/$item $link_dir/$normitem" else ln -s $snapshot_dir/$item $link_dir/$normitem # generate symlink fi fi done if $dryrun; then echo echo .... waiting 1 sec .... sleep 1 fi
First we have the conf.
dryrun=true means that it will only output to terminal what it want to do.
uncomment the dryrun=false to make it run.
snapshot_dir and link_dir should be self explained.
The link_dir you must make your self. Set write permission to what user this script should be run under.
Verify that your snapshot schema is added to the normilize function.
From our testparm we copy the important pieces and paste into the Auxiliary Parameters.
Remeber also to include the VFS Object. For 9.3 it's shadow_copy2.
Remember to edit the shadow:format and shadow:snapdir and also unselect the Periodic Snapshot Task:
Bellow you have an easy copy and paste
.....
shadow:snapdirseverywhere = yes
shadow:format = %Y%m%d.%H%M
shadow:localtime = yes
shadow:sort = desc
shadow:snapdir = .zfs_links
.....
Now you set up a cron job ..
Don't be so foolish as I'am by using the user root.
When all this done you can peek into symlink_directory (the example above is .zfs_link) to see when list is starting populate.
Be a bit patient, for me I have to disconnect the mapped letter (or I was patient ... it finally started show something).
And voila ..
As you can see the last snapshot or Restore previous version slot is way off the other ones (2017-03-05 09:57).
I find this interesting, do you ?.
**** NOTE I take no responsibility for your data while you are using this script. ****
Hmm I think it works ... still testing
... after some testing .. bah it seems to default to first snapshot schema. What you get from testparm is not necessary the conf. for samba it seems.
... back to ground zero again ...
Last edited: