0

In order to restore a BTRFS snapshot of /home, on NixOS, the Wiki says to first unmount /home.

"home must be unmounted for this operation" https://nixos.wiki/wiki/Btrfs

So my question is how to do this? Must I boot into a different system?

Maybe there is an easier way to restore a snapshot of home?

1 Answer 1

1

So my question is how to do this? Must I boot into a different system?

Log out from your regular account, then log in as root. Root's home directory is traditionally /root, which is outside of /home.

Then make sure all your user processes have stopped – e.g. there might be a 'systemd --user' process lingering around; stop it using systemctl stop user@YourUID. (Kill any other leftovers using systemctl stop user-YourUID.slice or just pkill -u YourName.)

Maybe there is an easier way to restore a snapshot of home?

You don't necessarily have to restore the whole snapshot in the first place if you can just cp -a the specific files or directories that you need out of the snapshot.

$ sudo cp -av /snapshots/home_snap_1234/Projects ~/Projects.restored

(Depending on how /snapshots has been set up, you might not even need 'sudo'.)

With modern GNU coreutils 'cp', this will make reflinks instead of full copies and will occupy no extra space (although if your coreutils is older than 9.1 then you'll need to add --reflink to ensure that).

4
  • If I do "cp -a" on files or folders, thus manually restoring them to /home, do I then need to do "chown", or to remove "read-only" status?
    – shmu
    Commented Mar 13 at 6:27
  • No, the individual files in your snapshots have exactly the same metadata in snapshots as they did in the original. The only "read-only" status is at whole-snapshot level, and cp won't copy that. (It's practically like copying out of a read-only filesystem.) Commented Mar 13 at 6:32
  • So then I could copy back the entire folder of a specific user, using "cp -a"? That sounds pretty painless. What would be the downside to that method?
    – shmu
    Commented Mar 13 at 6:36
  • I don't think there is any downside, really – cp --reflink is a standard operation in Btrfs, even across snapshots assuming you're running a 6.x kernel (and not ≤5.17). Though if you plan on copying things like ~/.config then you still should make sure that user's processes have been stopped. Commented Mar 13 at 6:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .