I'm running a FreeBSD host with ZFS.

Let's pretend that I am storing a series of incremental ZFS snapshot images on a remote host using zfs send:

zfs send -i zpool/data/foo@04hoursago zpool/data/foo@10hoursago > /nfs/backups/foo.zfs

Or perhaps I want to send the stream through an FTP server:

% ftp backup
ftp> put "| zfs send -i zpool/data/foo@04hoursago zpool/data/foo@10hoursago" /backups/foo.zfs

I would like to validate this remote image. I'd like to print a list of snapshots that are in this image, or optionally extract a checksum or other metadata to help check that the image is valid and contains the snapshots like I expected.

How can I query the image file and see what is inside?

I have tried zfs receive with the -nv (no-op and verbose) flags to list the snapshots within the image, but this may not work on a live system:

# zfs receive -nv zpool < /nfs/backups/foo.zfs
cannot receive new filesystem stream: destination 'zpool' exists
must specify -F to overwrite it
# zfs receive -nv -F zpool < /nfs/backups/foo.zfs
cannot receive new filesystem stream: destination has snapshots (eg. zpool@09hoursago)
must destroy them to overwrite it
  • I don't think it works this way. – ewwhite Mar 13 '15 at 21:07

More modern versions of ZFS provide a command named zstreamdump which can provide human-readable information from a stream (or image) created using zfs send.

This is an example using the commandline:

host # zstreamdump < foo.zfs 
BEGIN record
    toname = zpool/data/foo@04hoursago
    END checksum = 123123123123123123/123123123123123123/asdasdasdasdasd/zxczxczxczxczxc
    Total write size = 54784 (0xd600)

And an example from FTP:

ftp> get /backups/foo.zfs "| zstreamdump"
BEGIN record
 hdrtype = 1
 toname = zpool/data/foo@04hoursago
 END checksum = 123123123123123123/123123123123123123/asdasdasdasdasd/zxczxczxczxczxc

This provides me with the name of the actual snapshot, and a checksum of that snapshot. It will not provide me with a list of files within the snapshot of course, because that information exists at a different layer.

I have not actually tried this on an incremental snapshot created using zfs send -i, but this may be what I want.

  • 1
    You taught me two things in one post. Validating a zfs dump and storing a ftp file into a pipe. I'll remember this day long after forgetting how to do either :) – Florian Heigl Mar 23 '15 at 1:51
  • Glad I could help. ZFS is a great filesystem, but finding good examples outside of the Solaris docs can be hard. – Stefan Lasiewski Mar 23 '15 at 17:57

I think the problem with your -nv approach was that intermediate filesystems are not created when receiving with -n, and therefore it will fail every time, while it works without the no-op flag (but expanding the complete filesystems may take a long time). Unfortunately, most documentation/blogs online do not use this flag, therefore they never experience this error like you (and I) did.

Also a word of warning from the Solaris Internals ZFS Best Practices Guide:

If you store ZFS send stream on a file or on tape, and that file becomes corrupted, then it will not be possible to receive it, and none of the data will be recoverable. However, Nevada, build 125 adds the zstreamdump(1m) command to verify a ZFS snapshot send stream. See also, RFE 6736794.

Especially with large datasets this means three things:

  • If your stream is on storage you don't trust regarding bit safety, you would need to check almost all the time and still live with the risk that a single bit error wipes your whole backup.
  • If your stream is on storage you trust (for example on a ZFS volume exported as NFS), you are relatively save, but you miss out on zfs list -r and zfs diff.
  • If you have access to native storage (for example, ZFS volume accessed over SSH), you can expand the received filesystems and use the mentioned tools. Also in this case the -v switch works as expected and can be parsed easily.

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.