18

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?

1 Answer 1

21

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

7
  • 3
    Yes, a ZFS snapshot is definitively read-only.
    – jlliagre
    Apr 23, 2014 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, 2014 at 15:11
  • 10
    @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)... Apr 24, 2014 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 3, 2017 at 12:50
  • 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 (github.com/openzfs/zfs/commit/…). Mar 9, 2020 at 18:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .