8

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?

13

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

  • 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
  • 8
    @STW - according to groups.google.com/a/zfsonlinux.org/forum/#!topic/zfs-discuss/…, you need ZoL 0.6.0rc8, on kernel > 2.6.37. According to lists.freebsd.org/pipermail/freebsd-fs/2008-November/…, 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
  • 6
    @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 – mikky Oct 3 '17 at 12:50
  • @mikky you make my day – Alessio Jul 5 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.