16

I have a ZFS dataset which gets hourly snapshots taken. Yesterday, a change was made to some of the files which needs to be reverted; however, the dataset has ongoing changes which shouldn't be reverted.

What are my options to access the snapshot without disturbing the current copy of its data? Can I mount a snapshot in read-only mode to a new mount point?

ChrisInEdmonton
  • 8,656
  • 7
  • 42
  • 49
STW
  • 1,836
  • 4
  • 17
  • 33

1 Answers1

20

It's been a while since I played with zfs, but you should be able to use zfs list -t snapshot to find your available snapshots and access the files under a special .zfs directory under your zfs mountpoint.

[~]# zfs list -t snapshot
NAME                       USED  AVAIL  REFER  MOUNTPOINT
mypool                    1.49G   527M   528M  /mnt/zfspool
mypool@snap1                28K      -   993M  -
mypool@snap2                28K      -   993M  -
mypool@snap3                28K      -   993M  -

[~]# cd /mnt/zfspool/.zfs/snapshot/snap1
[snap1]# ls

IIRC, snapshots are already read-only, so attempts to change data in the snapshot directory should fail. If the data changes in the real fs, the snapshot should grow, as it copies the pre-changed data to keep the snapshot consistent.

You would need to zfs clone the snapshot to a new location, in order for you to make edits to the snapshot (at which point, it wouldn't be the snapshot any more).

As I said, though, it's been a while, so test first...

ref: http://www.googlux.com/zfs-snapshot.html

jimbobmcgee
  • 692
  • 1
  • 5
  • 15
  • 3
    Yes, a ZFS snapshot is definitively read-only. – jlliagre Apr 23 '14 at 20:10
  • Perhaps it's because I'm using ZFS on Linux, but I don't see the .zfs folder under my pool's mount point – STW Apr 24 '14 at 15:11
  • 10
    @STW - according to https://groups.google.com/a/zfsonlinux.org/forum/#!topic/zfs-discuss/Ktbndmd3rNo, you need ZoL 0.6.0rc8, on kernel > 2.6.37. According to http://lists.freebsd.org/pipermail/freebsd-fs/2008-November/005345.html, you need `zfs set snapdir=visible /mnt/zfspool` to make it visible, but you shouldn't need it to access your snapshot (i.e. you should be able to do `cd /mnt/zfspool/.zfs/snapsot/snap1` anyway)... – jimbobmcgee Apr 24 '14 at 20:54
  • 10
    @STV you won't see .zfs but you can still cd into it. snapshots are stored in it's parent dataset so the parent dataset must be mounted in order to be able to access the .zfs – jficz Oct 03 '17 at 12:50
  • @mikky you make my day – Alessio Jul 05 '19 at 10:30
  • i unhid `.zfs`, per above, thanks, however `.zfs/snapshot` is empty. so i still cant find my snapshots. – Brian Thomas Mar 09 '20 at 18:25
  • 1
    @BrianThomas - did you actually *take* a snapshot, and was it of a mounted filesystem (not a volume)? If `zfs list -o name,mountpoint` shows *tank/yourfs* mounted at `/mnt/yourfs` and lists `yourfs@yoursnap`, then `ls /mnt/yourfs/.zfs/snapshot/yoursnap` should show the contents of */mnt/yourfs* as it was at the point of taking *yoursnap*. I know that ZoL didn't implement the `.zfs` directory for a while, but has since 2012 (https://github.com/openzfs/zfs/commit/ebe7e575eae1e03b1faa545a424f008faeac589d). – jimbobmcgee Mar 09 '20 at 18:54