9

Is there a canonical way of rolling back to a subvolume snapshot that has child subvolumes. So for example, this is my btrfs volume layout:

ID 257 gen 59802 top level 5 path __active
ID 258 gen 59784 top level 5 path __snapshot
ID 259 gen 59802 top level 257 path home
ID 260 gen 36538 top level 257 path opt
ID 261 gen 59802 top level 257 path var

So you can see that home, opt, and var are child subvolumes of __active. If I snapshot __active such that this is my new layout:

ID 257 gen 59802 top level 5 path __active
ID 258 gen 59784 top level 5 path __snapshot
ID 259 gen 59802 top level 257 path home
ID 260 gen 36538 top level 257 path opt
ID 261 gen 59802 top level 257 path var
ID 416 gen 59784 top level 258 path __snapshot/__active

If I want to roll back to the snapshot of __active, is there a way to reattach home, opt, and var to the new __active?

2 Answers 2

3
+100

If you mean with reattaching that your btrfs subvolume list would show:

ID 257 gen 59802 top level 5 path __active
ID 258 gen 59784 top level 5 path __snapshot
ID 259 gen 59802 top level 416 path home
ID 260 gen 36538 top level 416 path opt
ID 261 gen 59802 top level 416 path var
ID 416 gen 59784 top level 258 path __snapshot/__active

then no there is now way to do that with the btrfs-progs.

Sub-volumes can only be deleted if all the child-subvolumes (created with btrfs subvolume create ...) are empty, however this is not true for snapshots (which are created with btrfs subvolume snapshot .... Snapshots can always be deleted and so if you could move them, there would be a problem with removing the snapshot.

Although both child subvolumes and snapshots appear in the same tree structure, and even share the btrfs subvolume delete .. command, they don't act the same.

2

First of all, when making __snapshot/__active, the subvolumes (home, opt, var) are not snaped. Instead empty directories are created. Thus __snapshot/__active can easily be removed, whereas __active can not.

But the main point was restoring __active with __snapshot/__active. As far as I know, this can't be done atomically. But you can happily mv snapshots and other subvolumes around (as long as they are writable). So doing e.g.

mv __active __snapshot/__active.old
mv __snapshot/__active __active

restores __active from the snapshot, but moving the subvolumes to __snapshot/__active.old/{home,opt,var}. To reattach them you can now use

mv __snapshot/__active.old/{home,opt,var} __active/

and you will get

ID 257 gen 59804 top level 258 path __snapshot/__active.old
ID 258 gen 59786 top level 5 path __snapshot
ID 259 gen 59802 top level 416 path home
ID 260 gen 36538 top level 416 path opt
ID 261 gen 59802 top level 416 path var
ID 416 gen 59784 top level 5 path __active

In case your snapshot is made read-only you can do for example

mv __active __snapshot/__active.old
btrfs subvolume snapshot __snapshot/__active __active
rmdir __active/{home,opt,var}
mv __snapshot/__active.old/{home,opt,var} __active/

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.