4

I'm trying to make use of the ability of zfs snapshots. To explain a little how it's configured on my end:

zpool create vol0 mirror /dev/sda /dev/sdb
zfs create -o volblocksize=128K -V 15T vol0/pprovol

I got my ZFS volumes:

NAME           USED  AVAIL  REFER  MOUNTPOINT
vol0          15.0T  16.6T   100K  /vol0
vol0/pprovol  15.0T  31.6T  1.99G  -

And I have a block device on:

Disk /dev/zd0: 15 TiB, 16492674416640 bytes, 32212254720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 131072 bytes
I/O size (minimum/optimal): 131072 bytes / 131072 bytes

I formated it as xfs with: mkfs.xfs /dev/zd0 and mounted it on my mounted point

Now I would like to create snapshots for this zd0 device. So that I could rollback changes made on the xfs filesystem.

Is this possiable? And how can I do this?

It does work for my /vol0 but that isn't what I need. Hope to get some help around here! Thanks.

g00gle
  • 343
  • 1
  • 3
  • 5

2 Answers2

4

Here's how to manage snapshots on an XFS on top of ZFS setup.
(a disclaimer: there are safer and more intelligent ways to store (ppro) data on ZFS)

  • Take a snapshot.
  • Identify the snapshot.
  • Clone the snapshot.
  • Mount the cloned block device.

When you run the ZFS snapshot, the snapshot will appear in your snapshot lists:

enter image description here

From there, you have to clone the snapshot to make it visible as a block device.

zfs clone vol1/pprovol2@snap_daily-2016-12-23-2359 vol1/recovery

This creates a new zfs filesystem named vol1/recovery, and simultaneously creates a new /dev/zdX device. dmesg | tail will reveal the actual device name. It will likely be /dev/zd16.

This is your clone. If you want to mount it, you just run:

mount -t xfs -o nouuid /dev/zd16 /mountpoint

The nouuid is needed because the cloned device has the name UUID as the original XFS filesystem.

ewwhite
  • 197,159
  • 92
  • 443
  • 809
  • 2
    Excellent answer. However, I would *not* use `clone`, as the OP seems to talk about read-only, immutable snapshots. I would rather use a "regular" `zfs snapshot` command, mounting the XFS filesystem with `-o nouuid,ro,norecovery` mount options. – shodanshok Nov 29 '17 at 17:23
  • 1
    The OP didn’t clarify, and hasn’t seemed to return... – ewwhite Nov 29 '17 at 19:28
2

You can take snapshots of a ZFS volume in the same way you would any other dataset. You might want to freeze the file system first though to make sure you get it in a consistent state. Fortunately XFS is one of the few file systems that make this easy

# xfs_freeze -f /mount
# zfs snapshot vol0/pprovol@snap1
# xfs_freeze -u /mount

On most ZFS systems you then end up with a ...@snapshot device under /dev, although I've never tried it on Linux. You should be able to mount that device readonly to recover files.

If you just want to rollback entirely, you can unmount the live file system, run zfs rollback, then mount it again.

USD Matt
  • 5,381
  • 15
  • 23