Restore root from Sanoid snapshots

Ubuntu 22.04 LTS, KVM host on bare metal. Root install is on a drive in several pools:

bpool
rpool
hpool
kvmpool

These pools live on a drive as part of a two disc mirror vdev.

The snapshots are taken daily, and also replicated to another drive on a different host using cron.

I have everything backed up just fine, in multiple places.

I know I am about to upgrade to a more recent release and kernel. This next time I think I am going to put root on EXT4, and perhaps a software raid mirror for root. I will definitely leave my VMs on ZFS pools, with each VM in its own dataset.

However, I have the itch to break this ZFS root & see if I am able to successfully restore root from past snapshots. Perhaps roll it back a month and see if it works. Perhaps, this is the best way to break it in the first place, :slight_smile:

I would think the datasets could all be replicated back from an older snapshot without any trouble. My guess is that boot will probably not work out of the box.

Has anyone tried to restore a root install; or have any suggestions?

It can certainly be done, but getting the boot environment to work can be a hitch in your giddyup.

Apart from that, the important thing is to realize that you need a bootable OS that can import your boot pool, list its snapshots, roll it back to the one you want, and then exit. You can’t use the OS you want to roll back to roll itself back–certainly not without causing massive issues that would require an immediate reboot, at absolute best (and in practice, I think you’ll typically simply find it impossible because you can’t unmount the root filesystem, and Busybox et al don’t generally have their own ZFS functionality either).

Does Ubuntu provide a good way to put your VM configs on a dataset? Then the root shouldn’t even matter - just install the newer LTS, import your/mount your datasets including the one with your configs, and you’re good to go!

I personally treat all my rootfs as ephemeral throwaway things. My datasets are pets, rootfs are cattle.

root@box:~# zfs create data/images/qemu
root@box:~# rsync -ha /etc/libvirt/qemu/ /data/images/qemu/
root@box:~# rename /etc/libvirt/qemu /etc/libvirt/qemu-dist
root@box:~# zfs set mountpoint=/etc/libvirt/qemu data/images/qemu

This is what I do. The XML files that live in /etc/libvirt/qemu are what define your VMs. Each of my VMs has its own dataset beneath data/images; by putting the dataset mounted at /etc/libvirt/qemu beneath data/images, I ensure that any backup (eg syncoid -r data/images root@target:data/images) will pick up the VM definitions also.