LVM snapshots feature fails to update patterns paths without a leading slash #1226
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#1226
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
extracted from #962
When the pattern is specified according to Borg docs as an absolute path but without a leading
/, then appending the snapshot path fails.Example, if I have specified a pattern
pf:home/myuser/.local/share/baloo, then I see in borgmatic verbose log that it ends up! pf:home/myuser/.local/share/baloo.Here a valid workaround is to specify the pattern as
pf:/home/myuser/.local/share/baloo. According toman borgthe patterns should not start with a leading/but that leading slash is removed automatically so the workaround is viable. Still it will be correct for borgmatic to handle patterns without a leading slash because they seem to be the canonical format.So with
pf:/home/myuser/.local/share/baloo, that is properly later translated to! pf:/run/user/0/borgmatic/lvm_snapshots/f667480a34df1550a601/./home/myuser/.local/share/baloo.Actually current approach may fail with some regular expressions, because for the
re:pattern I don't see Borg removing leading slashes. I didn't test that though.Discussion:
As far as I read and my testing goes, there are no relative paths in Borg. All paths are absolute and inmost pattern types, a leading
/is removed. So what would a "relative" path mean in this context and do relative paths have a special borgmatic meaning?Steps to reproduce
man borgthis is what I see as the canonical approach).Actual behavior
Expected behavior
Other notes / implementation ideas
Perhaps compare pattern prefixes with and without a leading slash (i.e. do not consider the leading slash as significant)
borgmatic version
2.0.13
borgmatic installation method
RPM
Borg version
borg 1.4.2
Python version
Python 3.13.9
Database version (if applicable)
No response
Operating system and version
Fedora Linux 42
That's mostly correct. There are no relative paths within Borg archives, but there are in borgmatic. borgmatic has a
working_directoryoption that allows you to use relative paths in yoursource_directoriesorpatterns, which then get adjusted based on theworking_directoryvalue before getting passed to Borg.Additionally, even if
working_directoryisn't set, you can still feed relative paths to Borg (relative to the current working directory where Borg was run), which get stored without any absolute path prefix. And then the archive itself doesn't distinguish between absolute and relative paths once stored. For example:The file isn't stored in the archive as
/home/witten/Downloads/tmp/test.yaml; it's stored only astest.yaml.So, getting to the problem you've identified, the challenge is that any particular pattern given to borgmatic might be a relative or absolute path.
The edge case I can think of is a relative path pattern that's not referring to the same path as the snapshot. For instance, if you cd to
/some/pathand run borgmatic with and a relative pattern ofhome/myuser/.local/share/baloo, that would mean that the actual absolute path is/some/path/home/myuser/.local/share/baloo, which shouldn't necessarily match the snapshot path.In fact, thinking about this a little more, I'm not sure how a path like
pf:home/myuser/.local/share/balooeven works for you (putting aside snapshots altogether) unless you run borgmatic from/. Same thing with plain Borg—I'm not sure how a path like that would work unless you run Borg from the/directory. Example:So what directory are you in when you're running borgmatic?
from
man borgPlease notice the last sentences - "A leading path separator is always removed.`
So while one can apparently (and surprising to me) specify relative paths, the exclude/include patterns should never start with a slash in pure borg.
It is confusing that borg accepts relative paths in places and not in other places. And it is even more complicated when borgmatic has its own logic. Maybe at least this deserves some more clarification in docs.
I believe the exclude patterns match absolute paths, not the path within the archive. Because to work, my patterns need the full absolute path, not only the path after
/./element.One option is to make borgmatic match borg behavior where it accepts relative paths or not.
Another option would be to handle relative paths everywhere but make sure that these are adjusted to correct absolute paths when passed down to borg.
In both cases a little more documentation would be an improvement.
I hope this makes sense, as it is quiet late here and not sure my brain works.
Sorry for the spam. But even if we agree that borgmatic wants to support relative paths in exludes and patterns, then it should append the workdir before passing to borg. Otherwise patterns will not be recognized.
So there are IMHO two valid options:
Just passing unprocessed relative paths to borg does no good as that has no chance of working as far as I can tell. Or did I miss your point?
I don't think the second statement follows from the first. Even though Borg always removes a leading path separator upon storage in an archive, you still need to supply a leading path separator if you want to specify and resolve an absolute path instead of a relative one. And that's even when using Borg by itself without borgmatic.
Yeah, clarification in the docs makes sense to me.
The part after the
/./is the only part of the path stored in the archive. That's just how Borg (1.4+) works. But if that's not the case on your system, can you give more details (logs, etc.) about this happening?Could you say more about what that might look like?
The difficulty is that some users actually want relative paths stored. For instance, many users who are using the
working_directoryoption are using it because they want relative paths stored, not absolute.See the example from above:
In this example, Borg is being given a path without an initial path separator—and is not considering it an absolute path. But maybe what you're saying though is that once stored within a Borg archive, Borg doesn't distinguish between relative and absolute paths? If so, I totally agree.
I think it works for many users, but their use cases are very likely different from yours.
So getting back to your initial problem, I see a couple of possible solutions:
source_directoriesorexclude_patterns), then use leading path separators. In both Borg and borgmatic, paths without leading path separators are relatives paths (just for purposes of resolving files, before their paths are stored in an archive).working_directoryoption (or alternatively acdbefore running borgmatic, which is basically the same thing just less convenient). Note however to your point, these will be stored as relative paths in Borg as well, not absolute ones.But if I'm missing something and there's really a use case for specifying relative paths but storing absolute ones, please let me know!