digint / btrbk

Tool for creating snapshots and remote backups of btrfs subvolumes
https://digint.ch/btrbk/
GNU General Public License v3.0
1.64k stars 120 forks source link

[SOLVED] How to reorganize ro snapshots (from single snapshot dir to multiple snapshot dirs)? #448

Closed ghost closed 2 years ago

ghost commented 2 years ago

In the past, I had used and configured a single snapshot directory for all snapshots. Browsing it has become tedious, since it receives a lot of snapshots from various subvolumes. I'd like to reorganize that, and introduce multiple subdirs in the snapshot directory, without losing the existing UUIDs.

Is there any way to change to a per-subvolume snapshot subdirectory setup, and move existing snapshots? Adapting all btrbk conf files that I use does look easy, but haven't found a viable solution for the "move" problem.

digint commented 2 years ago

[...] but haven't found a viable solution for the "move" problem.

You can use mv on subvolumes. This preserves all uuids.,e.g.

cd /path/to/snapshots
# list uuids
lsbtr -u ./

mv home.20220101 ../new_snapshot_dir/home.20220101

or, you can as well create snapshots (read-only). this sets parent uuid, which implies that you need to keep the parent in order to preserve the relationships required for send/receive (check with lsbtr -u)!

cd /path/to/snapshots
btrfs subvolume snap -r home.20220101 ../new_snapshot_dir/home.20220101
lsbtr -u ../
ghost commented 2 years ago

You can use mv on subvolumes.

Only if they're not read-only. Is it ok to remove the flag, move the subvolumes, and set it again?

digint commented 2 years ago

Oh, this is strange, I'm pretty sure this used to work (this restriction makes absolutely no sense: I can rename it using mv, but not move it into a folder? Looks like a bug to me...)

Is it ok to remove the flag, move the subvolumes, and set it again?

Should be fine.

ghost commented 2 years ago

Seems to be a known restriction, see here mv for renaming a ro snapshot is ok, but not for moving it e.g. into a subdir.

Anyway, I'll try rw > mv > ro.

[EDIT] Can confirm that this works:

  1. set read-only property of existing snapshots to false
  2. mv snapshots to subdir
  3. set read-only property of moved snapshots to true again
  4. adapt btrbk conf files to use subdir

e.g.:

cd btrbk_snapshots
mkdir data
find . -maxdepth 1 -iname "data.202*" -exec btrfs property set -ts "{}" ro false \;
find . -maxdepth 1 -iname "data.202*" -exec mv "{}" ./data/ \;
cd ./data
find . -maxdepth 1 -iname "data.202*" -exec btrfs property set -ts "{}" ro true \;