0

I have a small server that I use as a NAS, it has a few services running on it and a number of files that it stores.

It is configured as RAID1 with two SSDs, formatted with btrfs.

I use apt-btrfs-snapshot, which creates snapshots each time an apt operation is performed. This all works fine for recovering from bad configuration changes - but I'd also like to copy those snapshots to some external backup target to use them for recovery if the server completely dies.

My question: suppose I have a recent btrfs snapshot of the root directory of this machine. To recover it, can I do a fresh install of Ubuntu (with the same hardware), copy across the snapshot, and then tell apt-btrfs-snapshot to "rollback" to that snapshot? Effectively I'm copying verbatim the entire root filesystem from a different but similar system. I would have thought this should be OK, as long as I keep the permissions the same then all the installed applications and configuration files should bring back the backed-up system exactly as it was at the time of the snapshot. I'm thinking I might try this out in a VM just to check, but are there any issues with copying a root filesystem to restore a whole machine?

0

OK, I tried it out in a VM. Here's the general gist of what I did:

  1. Create an Ubuntu 18.04 VM in VirtualBox, with a 20 GB disk. Install using the desktop ISO image, and (of course) configure using btrfs instead of accepting the defaults.

  2. Boot into the new system, install apt-btrfs-snapshot. Install some other things too, I did Docker because that's one of the things I wanted to make sure is backed-up. The idea is the backed-up system needs to be obviously different from a fresh install so that we can tell if this actually works.

  3. Make a reference snapshot with sudo apt-btrfs-snapshot snapshot.

  4. Remove the disk from the VM, and create a new disk and install Ubuntu 18.04 on it following the same process as before.

  5. In the new VM, also install apt-btrfs-snapshot, but nothing else (because we're going to restore our backup anyway).

  6. Shutdown the VM, then attach in SATA slot 1 the disk from the first VM. Boot back into the VM and make sure the new instance has booted and not the backup disk (you can check if the things you installed are there or not - they should not be there in the new instance).

  7. Manually mount the root of both the new and backup btrfs disks - I did this through entries in /etc/fstab but it can just be done with mount commands.

  8. Find the name of the snapshot in the backup that you want to restore, something like @apt-snapshot-2018-08-01_08:48:31 - there will be a number of these in the root of the btrfs filesystem.

  9. Make a btrfs subvolume of the same name in the new disk, with a command like sudo btrfs subvolume create /path/to/new/btrfs/@apt-snapshot-2018-08-01_08:48:31

  10. Copy everything across from the backup to the new empty subvolume, something like sudo cp -ar /path/to/old/@apt-snapshot-2018-08-01_08:48:31 /path/to/new/btrfs/

  11. Finally, check the new subvolume is seen with sudo apt-btrfs-snapshot list and then, assuming it is listed, set the restored image to be used on boot, with: sudo apt-btrfs-snapshot set-default @apt-snapshot-2018-08-01_08:48:31

  12. Power off the VM and remove the backup disk. Reboot, and then check the restore has worked. In my case, it did - in particular the Docker images I had tested before the backup worked on the restored machine.


So it seems like it does work to restore to a fresh install from a root subvolume snapshot, as long as the hardware is similar.

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.