# Shadow Copies



## newton (Aug 18, 2012)

It seems so simple to setup shadow copies with zfs and samba, but it's not working for me.  Here's what i've got:


```
# uname -a
FreeBSD NAS2 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:30 UTC 2012     root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
# smbd -V
Version 3.4.14
```
/usr/local/etc/smb.conf : 

```
[global]
   #server info
   interfaces = re0 lo
   workgroup = HOME
   server string = NAS2
 
   #debugging
   log file = /var/log/samba34/samba.log
   log level = 2
   max log size = 50
 
   #security
   preferred master = no
   security = user
   local master = no
   dns proxy = no
 
   #compatibility
   encrypt passwords = true
 
   #printing
   printcap name = /etc/printcap
   load printers = no
 
   #share defaults
   guest ok = no
   invalid users = root
   writable = no
 
   #shadow copies
   unix extensions=no
 
[jnewt]
        comment=my Files
        path=/zfile/jnewt
        writable=yes
        valid users=jnewt
 
        #shadow copies
        follow symlinks = yes
        wide links = yes
        vfs objects = shadow_copy2
        shadow: snapdir = .zfs/snapshot
        shadow: sort = desc
        shadow: format= %Y_%m_%d
```
My snapshots:

```
# zfs list -t snapshot
NAME                        USED  AVAIL  REFER  MOUNTPOINT
```
...

```
zfile/jnewt@2012_01_01       256K      -  13.2G  -
zfile/jnewt@2012_01_08      38.9K      -  13.2G  -
zfile/jnewt@2012_01_09      50.9K      -  13.2G  -
zfile/jnewt@2012_01_15      43.4K      -  15.5G  -
```
...

```
zfile/jnewt@2012_08_15      3.16M      -  24.3G  -
zfile/jnewt@2012_08_16      3.13M      -  24.3G  -
zfile/jnewt@2012_08_17      3.13M      -  24.3G  -
zfile/jnewt@2012_08_18      3.12M      -  24.3G  -
```

And the Log (only reference to shadow)

```
[2012/08/18 07:39:06,  2] lib/module.c:64(do_smb_load_module)
  Module '/usr/local/lib/samba34/vfs/shadow_copy2.so' loaded
```

I right click on any file and get no previous versions.  that's it, no errors, even with log level 3 (that i can see, it gets pretty serious at level 3)


----------



## newton (Oct 17, 2012)

It's been a couple of months, i figure it's acceptable at this point to bump this thread, as I never found an answer or a reason why this doesn't work or how to fix it.


----------



## usdmatt (Oct 17, 2012)

I'm no samba expert but I managed to get it working quite easily so I'll post my settings. (I wasn't actually looking to do it, I just found a post somewhere and thought I'd give it a try).

I have a newer version of samba than you though on the same release. I would always recommend updating the ports tree with portsnap after installing os to get the latest ports:


```
# portsnap fetch extract
```


```
# smbd -V
Version 3.6.1
# uname -a
FreeBSD backup 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:30 UTC 2012     root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
```

I have shadow copies enabled on the home directories. Obviously it relies on the .zfs/snapshot directory
being there so the root of your samba share should be the root of a ZFS filesystem.

Edit: also you'll probably want %Y_%m_%d for the format. I had to play about with this a bit as I didn't like the way the date showed up when viewing versions of the share root. Had to put up with it in the end. There's a few things about it I'd like to change if I could but it works at least.


```
[global]
   workgroup = BACKUP
   security = user
   unix extensions = no
#============================ Share Definitions ==============================
[homes]
   comment = Home Directories
   browseable = no
   writable = yes
   follow symlinks = yes
   wide links = yes
   vfs objects = shadow_copy2
   shadow: snapdir = .zfs/snapshot
   shadow: sort = desc
   shadow: format = %d-%m-%Y
```


----------



## tanked (Oct 17, 2012)

I don't use Samba but does the following thread help? - 

http://forums.freebsd.org/showthread.php?t=34812&highlight=samba+shadow


----------



## Sebulon (Oct 17, 2012)

newton said:
			
		

> I right click on any *file* and get no previous versions.  that's it, no errors, even with log level 3 (that i can see, it gets pretty serious at level 3)



Have you ever tried right-clicking on a *folder* instead? Because that's how it works in our setups, you can only view previous versions on folders. I really hope it's that easy solving it for you. Getting this feature going is invaluable, hope it helps!

/Sebulon


----------



## usdmatt (Oct 18, 2012)

Using my config above it works as follows for me:

Right clicking on a file -> Properties -> Previous versions gives a list of actual different versions. I.e., I may have 50 snapshots but if a file hasn't changed at all I get nothing listed. If it's only changed twice, I'll see the two previous versions with their modified date. Works great.

Previous versions on a directory gives a list containing as many copies as I have snapshots. This makes sense as even though the directory itself may not have changed, the contents might have, so it gives a full list. The only annoying thing about this is that the date modified works the same way as for files, so it shows the date modified of the folder. This generally means I see a list containing 20 entries (if I have 20 snapshots), all with the same date. It would be nice if there was a modified "zfs edition" shadow copies samba module that showed the snapshot date here instead. I know I have a snapshot for the 1st June for instance, but there's no way of choosing to go into that version from Windows, I have to just pick an entry at random and look at the files.

I've "fixed" this on the root by touching the directory before taking a snapshot. So if I go into My Computer and view previous versions of the share itself, I see all the snapshot dates and can choose to browse the share as it was on any date (which is quite awesome). I can't touch every folder though... (well could script it but wouldn't want to)


----------



## Xenomorph (Oct 29, 2012)

@usdmatt:

Thank you for explaining that. My "Previous Versions" tab had listed all the folders (from each snapshot), but was listing nothing for files. As soon as I modified a file, the previous versions showed up.


----------

