# ZFS snapshots as softlink



## bsus (Sep 22, 2011)

Hi,
I am making daily snapshots which expire after 30 days.

Now I would like to access them easily read-only over a link in my home dir.

So I can go via samba/nfs in the folder and see all files listed in /usr/home/.zfs/snapshot and there I can go to the folder with the date of the snapshot so I can easily recover changed files.

My question is now how I can do this?
when I try
	
	



```
ln -s /usr/home/.zfs/snapshot /usr/home/<user>/snapshots
```
I am getting a sort of permission error.

This could be because the snapshots aren't "real" files also I am not sure if it works at all because maybe zfs would make snapshots of the snapshots ^^

Regards


----------



## bsus (Sep 22, 2011)

So the *ln -s* command works now can't really say why now but I still don't get access.
because root:wheel is owner of the snapshots and I don't have read permissions. Do I now have to add wheel to my user or is there a better solution?

I don't really want to mix up administration with normal users...


----------



## mbrumlow (Sep 22, 2011)

You would need to clone your snapshots.. 


```
zfs snapshot tank/home@snap01
zfs clone tank/home@snap01 tank/home_snap02
```

You can't read a snapshot directly as far as I know..


----------



## bsus (Sep 22, 2011)

You can!

```
freebsd ~ # cd /usr/home/.zfs/snapshot
freebsd snapshot # ls
2011-09-19_13.52.00--30d 2011-09-21_01.00.00--30d
2011-09-20_01.00.00--30d 2011-09-22_01.00.00--30d
```
Here the snapshots kept and when I ls them I have access to the home-dirs of alle users and the data which is saved in there.

They problem is just that the snaps belong to root:wheel and only root can read them. A normal user can't and I would like to change this somehow.
And here's the problem: chown and chmod won't work because it's read-only ^^
Regards


----------



## kpa (Sep 22, 2011)

Why not just add yourself to the wheel group? You are the admin after all...


----------



## Savagedlight (Sep 22, 2011)

My snapshot directories have 555 as permission sets. (r-xr-xr-x)
Permissions within the snapshots reflect that of the real filesystem, so users only have access to files in the snapshot which they have access to on the real system as well.

It would probably help to get more information on what the permissions look like on .zfs and .zfs/snapshot.


----------



## bsus (Sep 22, 2011)

> Why not just add yourself to the wheel group? You are the admin after all...


I tried this already - didn't changed anything at all over samba

I can access the snapshots over the terminal with my user account(So it should also work over nfs) but under samba I am getting some error although I am logged on with user and user passwort and user files work.

Does samba make problems because the files don't belong to me?


----------



## Savagedlight (Sep 23, 2011)

bsus said:
			
		

> I tried this already - didn't changed anything at all over samba
> 
> I can access the snapshots over the terminal with my user account(So it should also work over nfs) but under samba I am getting some error although I am logged on with user and user passwort and user files work.
> 
> Does samba make problems because the files don't belong to me?



Aha, some new information there.

Samba might not like following symlinks (where owner doesn't match)?


----------



## bsus (Sep 23, 2011)

Yes,
snapshots are shared as softlink via samba.

So we have /usr/home/.zfs/snapshot with the ro snapshots of each day. Owned by root:wheel.

Samba shared the home-dirs. I am logged on with my smbpasswd informations and am getting an error by trying to access the softlink to the snapshots...

Regards


----------



## Sebulon (Sep 25, 2011)

Try getting SAMBA's vfs_shadow_copy or vfs_shadow_copy2 to work.
http://www.edplese.com/samba-with-zfs.html

Please let me know if you succeed. I've banged my head against it a couple of times but never got it working correctly, but it would definitely be worth it, since it gives ZFS/SAMBA the exact level of service and ease of use as Sun/Oracle, NetApp and Windows storage servers. I'll keep trying myself and we'll see who get's it first

/Sebulon


----------



## phoenix (Sep 26, 2011)

You also need to set the *snapdir* property of the ZFS filesystem to *visible*.  Otherwise, the .zfs/ "directory" is not visible to normal commands (like Samba, NFS, ls, etc).


----------



## Sebulon (Sep 27, 2011)

phoenix said:
			
		

> You also need to set the *snapdir* property of the ZFS filesystem to *visible*.  Otherwise, the .zfs/ "directory" is not visible to normal commands (like Samba, NFS, ls, etc).






```
# zfs get snapdir pool1/home
NAME                    PROPERTY  VALUE    SOURCE
pool1/home              snapdir   visible  local
```

Trying to browse is through SAMBA gives:

```
Z:\.zfs is not accessible.

The request is not supported.
                                 [  OK  ]
```

This might be a clue. Could be permissions? But the same user can do:

```
# ls -lah /export/home/
drwxr-x---+  9 root   domain users     8B Sep  5 13:57 .
drwxr-x---+  5 root   domain users     5B Jun 30 08:53 ..
ls: /export/home//.zfs: Operation not supported [B]<-(?)[/B]
dr-xr-xr-x   4 root   wheel            4B Jun 14 05:45 .zfs
drwx------+ 37 user   domain users    44B Sep 27 05:30 user
# ls -lah /export/home/.zfs/
total 3
dr-xr-xr-x   4 root  wheel            4B Jun 14 05:45 .
drwxr-x---   9 root  domain users     8B Sep  5 13:57 ..
dr-xr-xr-x   2 root  wheel            2B Jun 14 05:45 shares
dr-xr-xr-x  12 root  wheel           12B Sep 27 06:00 snapshot
# ls -lah /export/home/.zfs/snapshot/
total 17
dr-xr-xr-x  12 root  wheel           12B Sep 27 06:00 .
dr-xr-xr-x   4 root  wheel            4B Jun 14 05:45 ..
drwxr-x---+  8 root  domain users     8B Sep  5 13:57 20110923-173912
drwxr-x---+  8 root  domain users     8B Sep  5 13:57 20110923-184118
drwxr-x---+  8 root  domain users     8B Sep  5 13:57 GMT-2011.09.23-17.50.49
drwxr-x---+  8 root  domain users     8B Sep  5 13:57 GMT-2011.09.23-18.17.55
drwxr-x---+  8 root  domain users     8B Sep  5 13:57 GMT-2011.09.23-19.29.57
drwxr-x---+  8 root  domain users     8B Sep  5 13:57 GMT-20110923-182519
drwxr-x---+  8 root  domain users     8B Sep  5 13:57 auto-2011-09-27_02.00
drwxr-x---+  8 root  domain users     8B Sep  5 13:57 auto-2011-09-27_03.00
drwxr-x---+  8 root  domain users     8B Sep  5 13:57 auto-2011-09-27_04.00
drwxr-x---+  8 root  domain users     8B Sep  5 13:57 auto-2011-09-27_05.00
drwxr-x---+  8 root  domain users     8B Sep  5 13:57 auto-2011-09-27_06.00
# ls -lah /export/home/.zfs/snapshot/auto-2011-09-27_06.00/
drwxr-x---+  8 root   domain users     8B Sep  5 13:57 .
dr-xr-xr-x  13 root   wheel           13B Sep 27 06:00 ..
drwx------+ 37 user   domain users    44B Sep 27 05:30 users
```

And still no "Previous Versions". Ideas?

phoenix, if you got this working, I would be very glad to know your SAMBA version, how you compiled and installed it, eventual patches etc. Also smb.conf would be great, please? I need a success to compare my fail to

/Sebulon


----------



## bsus (Sep 27, 2011)

@sebulon

Yes I got similar settings/options

Would be really great if somebody could solve this.
Samba/NFS with snaps would be a great thing.

Maybe I will have some time coming week to discover the link you postet, but I think when you didn't succeed I will also fail.



Regards


EDIT:

```
freebsd admin # zfs get snapdir
NAME                                   PROPERTY  VALUE    SOURCE
storage                                snapdir   hidden   default
storage/home                           snapdir   visible  local
storage/home@2011-09-19_13.52.00--30d  snapdir   -        -
storage/home@2011-09-20_01.00.00--30d  snapdir   -        -
storage/home@2011-09-21_01.00.00--30d  snapdir   -        -
storage/home@2011-09-22_01.00.00--30d  snapdir   -        -
storage/home@2011-09-23_01.00.00--30d  snapdir   -        -
storage/home@2011-09-24_01.00.00--30d  snapdir   -        -
storage/home@2011-09-25_01.00.00--30d  snapdir   -        -
storage/home@2011-09-26_01.00.00--30d  snapdir   -        -
storage/home@2011-09-27_01.00.00--30d  snapdir   -        -
```

Ah here we see that the direct snaps aren't visible.
Is there an option to change this?

Regards


----------



## Sebulon (Sep 27, 2011)

The snapshots themselves havenÂ´t got that property, take me for example:

```
zfs get -r snapdir pool1/home
NAME                                PROPERTY  VALUE    SOURCE
pool1/home                          snapdir   visible  local
pool1/home@20110923-173912          snapdir   -        -
pool1/home@GMT-2011.09.23-17.50.49  snapdir   -        -
pool1/home@GMT-2011.09.23-18.17.55  snapdir   -        -
pool1/home@GMT-20110923-182519      snapdir   -        -
pool1/home@20110923-184118          snapdir   -        -
pool1/home@GMT-2011.09.23-19.29.57  snapdir   -        -
pool1/home@auto-2011-09-27_10.00    snapdir   -        -
pool1/home@auto-2011-09-27_11.00    snapdir   -        -
pool1/home@auto-2011-09-27_12.00    snapdir   -        -
pool1/home@auto-2011-09-27_13.00    snapdir   -        -
pool1/home@auto-2011-09-27_14.00    snapdir   -        -
```

/Sebulon


----------



## bsus (Oct 1, 2011)

Are there some new informations about the samba problem?

I am trying to contact the samba mailing list.

@Sebulon
I think there are some more issues which we didn't think about.
1.) The .zfs/snapshot dir doesn't work with normal unix-rights when I change to user 1 I can read the date of user 2 in the snapshots. This is suboptimal, the data should just be readable for the own user. Over the snapshots even a "guest" user could read everything.
2.) In which structural way did you think to make the snaps available? Over a softlink in the home dir or over an extra samba share?

Regards


----------



## da1 (Oct 1, 2011)

One thing to check is the samba user that you use to "see" the snapshots. If the snapshot itself is owned by root and no one except root and wheel have permissions for that dir, if you use for instance user "nobody" for samba ... your out of luck. Check that the smb user you use has enough privileges to brose the .zfs dir.


----------



## bsus (Oct 1, 2011)

I use Samba with user authentication. So I am logged on with the user of and "his" home-dir. When I now have a softlink to /home/.zfs/snapshot I am getting a permission error.

The strange thing is now that I can cd without problems to the .zfs dir and even read data of every user - with my normal user account - even the permissions say that I can't read the data.

I am unsure how I could explain it best. (Can I write you what I mean in german?)


----------



## Savagedlight (Oct 2, 2011)

As I said earlier, you should verify that Samba is set up to follow symlinks.
Try adding these to the shares config for experimenting:

```
follow symlinks = yes
  wide links = yes
```


----------



## bsus (Oct 2, 2011)

Samba follows symlinks... this works by default.

I think its better to change the question:
What to I have to do to access the .zfs/snapshot dir over samba?


----------

