Article proposal: restore backups from Btrfs snapshots

Thank you for publishing Article proposal: Incremental backups with Btrfs snapshots
As a follow up it could be interesting an article about restore/recovery.
I don’t know what a good title could be. “Backup recovery from Btrsf snapshots”? “Restoring backups using Btrfs snapshots?”

The article will be pretty simple.

  • How to copy single files or directories from snapshots back to the original location (or elsewhere)
  • How to rollback an entire snapshot (but I’m unable to cover /home and / subvolumes, I think it is not a trivial task, isn’t it?)
  • How to recover the subvolume from the snapshot previously sent to the USB disk in case of disaster recovery (i.e. system reinstalled on a new disk)

@cmurf I’ve a doubt. In the previous article I talked about the /home subvolume. Let’s say I deleted my entire home directory (/home/mysuer). In this case is it better to copy the directory from the last snapshot, right? In case of disaster recovery, where I lost my disk drive and I reinstalled the system on a new one, in order to send/receive the snapshot in the USB disk, is it better to do that using a Live, I mean, doing that while the user is logged in should be avoided, right?

+1 What good are backups if you can’t recover from them? :slight_smile:

+1 - I would just be echoing what @bcotton said.

I have restored complete systems from btrfs snapshots on at least two occasions. The first time, I used a naive method, and it was successful. The second time, I used the method documented on the btrfs Wiki. It was simpler, quicker, and also successful.

The first time, I simply copied all of the files from the snapshots back to my local drive, using “cp -ar”.

The second time, I sent a btrfs snapshot back to the local drive. Then I made a new read-write snapshot of it. Then I used the Linux “mv” command to rename the rw snapshot to the directory I wanted it to be on the recovered system. That’s all there is to it, and IMO, it is one of btrfs’s greatest advantages.

1 Like

You do quickly get into “it depends” sort of questions.

If it’s just some files or directories, you can copy them normally with cp directly from any snapshot on external drive; to your existing home. Or using the desktop file manager.

A full rollback is perhaps more of a system level thing. And full restore is a variation on that. Either way, the starting point is a read-only snapshot. It’s either already there in the rollback case, or you need to send+receive one from your backup of snapshots (which ever one you want, typically the most recent). All you need to do is snapshot the snapshot without -r to make it a read-write snapshot of the proper name.

In case of a rollback, you have a naming conflict. e.g.

root #mounted at /
home #mounted at /home
root.20200916
home.20200916

You can just do:

mv root rootold
mv home homeold
btrfs sub snap root.20200916 root
btrfs sub snap home.20200916 home
reboot

Btrfs immediately reflects the name changes, such that rootold is on / and homeold is on /home so nothing has been yanked out from under a running system. So now just reboot.

The tricky parts of course are, well what about my VM images? I don’t want those rolled back. Well what about logs, I don’t want those rolled back. What if the rollback is older than the oldest kernel in /boot? It definitely gets complicated to do these things manually, hence various tools that do that stuff on behalf of the user. But the imperfection of simplicity is the point of any learning experience. It’s legitimately do not even ask these questions, and let the reader realize these things on their own - hey! wait a minute!

1 Like

openSUSE uses snapper to restore an entire snapshot or file selectively from snasphots, showing the difference of the changes, but they are snasphots present on the partition and not on the external backup sent with send.

Obviously you can’t do that if a user is logged in, isn’t it?

Hello @alciregi,

I have created the card for your article on Taiga, #235. Currently I titled it “Restoring an incremental backup of a BTRFS snapshot”, but we can change that if necessary. I assigned the card to you and once you get started on it just move the card state to in progress. When you’re ready for review move it into the review category so the editors are aware.

1 Like