Snapshotting of read-only /etc directory with systemd service and btrfs #1023
Labels
No labels
blocked
breaking
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No milestone
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
borgmatic-collective/borgmatic#1023
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
I am trying to set up Borgmatic with btrfs and schedule the running of borgmatic using a systemd timer since I want it to run also when the timer ticks when the PC is off. However, I have had problems doing so because of how the systemd template service is set up and how Borgmatic checks the snapshottable subvolumes.
When I run
findmnt -t btrfs --listnormally, this is what I get:I have a root subvolume mounted and a /home subvolume mounted as well. I have other subvolumes but they're not mounted so Borgmatic ignores them. These two are the only ones that need to be snapshotted by Borgmatic in order to back up my system.
However, when
borgmaticis run inside the systemd service, it detects many other mounted filesystems. This is the output offindmnt -t btrfs --listinside of the systemd service:As you can see, it detects many more subvolumes and tries to snapshot them all. So, my Borgmatic systemd service fails with this error:
Steps to reproduce
Use btrfs, download the Borgmatic systemd service from the link above and run borgmatic using the systemd service.
Actual behavior
Borgmatic fails because it tries to snapshot read only filesystems.
Expected behavior
Not sure what is to be expected. I think Borgmatic should just snapshot
/and since/etcis inside of the/subvolume, it should just read the contents of/etcfrom/.borgmatic-snapshot-12345/etc/.Other notes / implementation ideas
No response
borgmatic version
1.9.13
borgmatic installation method
Archlinux package
Borg version
1.4.0
Python version
3.13.2
Database version (if applicable)
No response
Operating system and version
NAME="Arch Linux" PRETTY_NAME="Arch Linux" ID=arch BUILD_ID=rolling ANSI_COLOR="38;2;23;147;209" HOME_URL="https://archlinux.org/" DOCUMENTATION_URL="https://wiki.archlinux.org/" SUPPORT_URL="https://bbs.archlinux.org/" BUG_REPORT_URL="https://gitlab.archlinux.org/groups/archlinux/-/issues" PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
Snapshotting of read-onlyto Snapshotting of read-only/etcdirectory with systemd service/etcdirectory with systemd service and btrfsThanks for taking the time to file this. (I'm glad you found your way here from Reddit!) I'll look into this when I get a chance and: 1. See if I can repro the extra read-only subvolumes with systemd, and 2. Hopefully figure out a solution to them causing read-only filesystem errors. My guess is that snapshotting read-only subvolumes should actually be possible and that the Btrfs hook is doing something to break that. E.g., I see there's a
makedirs()call that may actually be the cause of that error you're seeing.Side note: Are you by chance using Snapper or anything that might be impacting the subvolumes?
Turns out that this wasn't just a problem with making the snapshot directory; Btrfs really can't snapshot a read-only subvolume. So what I did was make borgmatic ignore any such read-only subvolumes when figuring out which subvolumes to snapshot. Now only read-write subvolumes will be considered. I didn't have a repro of your systemd setup, but I did test with both read-only and read-write subvolumes, and this fix should hopefully fix your use case.
This is implemented in main and will be part of the next release. Thanks again!
Released in borgmatic 1.9.14!