Published: Jan 23, 2023 by luxagen
BTRam automates a simple solution to the problem of mirroring filesystem trees or subvolumes across multiple machines.
Traditionally, one would make all the copies writeable and rely on either conventions of use or tree-diffing to periodically reintegrate the changes. Good tools for comparing filesystem trees are hard to come by, though, especially when your definition of “good” includes both readability and content analysis; identifying moves and copies would be nice too.
An improvement on this is to use a BTRFS snapshot as a common starting point, and then instantiate the two sides from there. Via the excellent
btrbk, one can then keep reciprocal incremental snapshots of the two instances that both share the initial data and independently record changes on both sides. This workflow doesn’t remove the reintegration problem though.
Instead, I’ve recently simplified by having a writeable subvolume on machine A (the master copy) and subvolume-mounting a snapshot thereof on machine B (the read-only copy). This reduces complexity by giving me only one snapshot lineage to manage, but it does mean periodically remounting to switch machine B to use a more up-to-date snapshot.
This is where
btram comes in: when run, it will spot subvolume mounts of outdated snapshots (i.e. where later-dated snapshots of the same set are available) and remount automatically. You can also dry-run to see what would happen without doing any actual remounting.