14

I'm running an Oracle 11 box as a ZFS storage appliance, and I'm taking regular snapshots of the ZFS filesystems, via cron.

In the past, I know that if I wanted to grab a particular file from a snapshot, a read-only copy was kept in .zfs/snapshot/{name}/ and I could just navigate there and pull the file out. This is documented on Oracle's website.

However, I went to do this the other day, and noticed that the ZFS directories within the snapshot directories are all empty. zfs list -t snapshot correctly shows the list of snapshots that should be present, and .zfs/snapshots correctly contains a directory for each snapshot, and in each snapshot there is a directory present for each ZFS filesystem. However, these directories appear to be empty.

I just tested a restore by touching a file in a little-used share and rolling back to the latest hourly snapshot, and this appears to have worked fine. So the rollback functionality is there.

Did Oracle change how snapshots are done? Or is something seriously wrong here?

sxc731
  • 297
  • 2
  • 15
growse
  • 7,830
  • 11
  • 72
  • 114
  • Related: https://groups.google.com/a/zfsonlinux.org/forum/#!topic/zfs-discuss/aAJsQoSY3BQ , https://github.com/zfsonlinux/zfs/issues/1768#issuecomment-27266951 and https://github.com/zfsonlinux/zfs/issues/2841 – Perseids Jan 22 '15 at 17:33
  • And also https://github.com/zfsonlinux/zfs/issues/3030 . Although, you use the Oracle ZFS tree, and they probably have diverted enough to not be directly comparable anymore. – Perseids Jan 22 '15 at 18:29

3 Answers3

6

If you have a descendent ZFS filesystem, for example tank/newfs. Then you will not find files in tank/newfs in the /tank/.zfs/mysnapshot folder, only the mountpoint newfs will exist. If you want to access the files you need to look for your files in the /tank/newfs/.zfs/mysnapshot folder.

2

The snapshots listed in .zfs/snapshot/ are automatically mounted on demand, as they are being browsed, and are automatically unmounted when no longer in use.

Doing a simple ls in a directory is apparently not enough to be considered 'demand'. You will need to cd into the directory in question and THEN issue the ls command.

You may also need to set snapdir=visible for the filesystem.

mprill
  • 584
  • 3
  • 10
Daniel
  • 121
  • 2
1

On ZoL (although the original q refers to Solaris), a bug currently exists whereby the automount feature described by @Daniel fails to work, resulting in empty snapshot directories. This seems to happen specifically for a ZFS root filesystem (where snapshots would normally be accessed under /.zfs/snapshot).

A telltale sign are entries in /proc/spl/kstat/zfs/dbgmsg reading Unable to automount <snapdir_path> error=512

Both workarounds proposed here worked for me (I'm running ZoL 2.0.6 on Ubuntu 21.10 and booting through ZFS Boot Menu):

  1. Add your ZFS root filesystem mountpoint to /etc/fstab (eg: zpool/ROOT/rootfs / zfs defaults 0 0) and reboot
  2. mkdir /sysroot && mount -o bind / /sysroot; the snaps can then be accessed through /sysroot/.zfs/

Choose the workaround you prefer (you don't need both).

According to a comment on a related issue:

this error occurs on systems with initramfs which chroot(2)s to new root filesystem and starts init process by running switch_root(8).

sxc731
  • 297
  • 2
  • 15