bootstrap hard-codes --glob-archives #1310
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
borgmatic-collective/borgmatic#1310
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'd like to do and why
Off the back of recent
bootstrapwork, I've discovered that, I think, it hard-codes--glob-archives:When something different is used for
archive_name_format, this makes bootstrapping difficult.--archiveof course works, but it's a hard catch-22 guessing whatlatestmight be ;)Other notes / implementation ideas
No response
Yeah, the
--glob-archivesdefault value is{hostname}-*in borgmatic ifarchive_name_formatis not set. And so, because thebootstrapaction is starting from a place of zero configuration, there's noarchive_name_formatand it uses the default value.This is of course a problem when the user has been using a non-default
archive_name_formatto create their backups, as you've discovered. And there could even be multiple formats in a single repository.One idea here is to add an
--archive-name-formatflag to thebootstrapaction, which would require a user to reproduce the full format, sobootstrapcan go and grab the correspondinglatestarchive. That could work, but it's not great—in that it requires the user to remember a potentially complex string of characters (or get it from another source).Another idea is for bootstrap to try to detect the multiple different "latest" archives in the repository, one for each format used, and present them to the user to select from. Not with an interactive UI, but just erroring out with: "Which of these latest archives do you actually want? Add an --archive flag to select one." However detecting this seems potentially error-prone. Borg does store the archive name "format", but not directly. It stores the command-line used to create each archive. E.g.:
Command line: /usr/bin/borg create --patterns-from /run/user/1000/borgmatic/tmp8h6zlbt6 --log-json --debug --show-rc 'test.borg::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'But maybe that could be used to back-calculate thearchive_name_format, at least to a degree necessary to group archives and find all the latests.Let me know your thoughts. (I'm open to other ideas too!)
@witten wrote in #1310 (comment):
Indeed, and as I've discovered, that
{hostname}is resolved from the machine borg{matic} is being run from; see next comment.@witten wrote in #1310 (comment):
Or, in my case, attempting to restore/mount/etc a backup on a different machine, with a different
{hostname}! So even when using a default forarchive_name_format, it breaks.@witten wrote in #1310 (comment):
Yeah, not good.
@witten wrote in #1310 (comment):
Agree, this starts to sound complex/messy too.
My thoughts right now (and I'll mull over it more), is that it should simply resolve
--glob-archivesto'*'if inlatestmode, and be done with it. If a user has mixed naming or other complexities, they'll have to manage that themselves (to avoid over-reaching inborgmatic).They either get the freedom to specify a specific archive (in full), or they just get whatever
'*'and--last 1resolves to.@lingfish wrote in #1310 (comment):
So I tried this for fun. It actually wasn't too terrible given that I could make use of
borg info's JSON output. Proof of concept here: #1313Example actual output:
@lingfish wrote in #1310 (comment):
That could work. But it would hide the
archive_name_formatcomplexities in a way that means the user could select the wrong archive on accident.@witten wrote in #1310 (comment):
Ok, that's kinda cute, but I wonder if there are many different "latest"'s, how the output would look. For me personally, I wouldn't have thought that one repo would have many, as a typical user use-case... I tend to split mine out (finer-grain retention control etc)... but I guess
borgmaticshould cater for any and all.And what about the case (my case actually) of having one repo, one archive prefix, that merely doesn't resolve to the original hostname (as I'm restoring on another host)? Without staring at the code for a bit, would it still claim there's multiples, yet listing only one? Perhaps with the PoC, if it sees only one, that differs from currently-running
hostname, it could auto-select that at least?@witten wrote in #1310 (comment):
True, but couldn't that technically happen as the prod code is now? Say you have (as yours above):
flux-2026-05-22T14:33:56.698164flux-documents-2026-05-22T19:30:54(note this is technically "latest")... and you're restoring from a
hostnameofflux, well inlatestmode you're kinda technically getting the latest in thefluxtrain, but not the latest in the repo overall, and that'd be silent to the user too.@lingfish wrote in #1310 (comment):
Yeah, I know at least some users use a different
archive_name_formatfor each of several different application backups written to the same repository.Actually for that case, yeah, the PoC would see only one. And right now it would silently just try to use the same wrong default
archive_name_formatto fetch the latest archive. But it would be pretty easy to change the PoC it to ignore the defaultarchive_name_formatand always fetch the latest archive if there's only one. And I think that would solve your particular use case (while also erroring when there are multiple latests and it can't pick just one).Yeah, I think we both agree that the released code behavior is problematic in this regard. There's no guarantee that any archive starts with the hostname. That's just the default / a common
archive_name_formatprefix. I've seen users use formats likemyapp-{now...}.Just wanted to add an upstream borgbackup request that I have open as well:
https://github.com/borgbackup/borg/issues/9651
(borg2 already supports this).
This simplifies some use cases with borg (as documented in the issue).
I think it is equally useful for borgmatic to support custom hostnames when one "controller" impersonates othe machines.
[Please advise if this should be split out into a separate issue]
Seems reasonable. Maybe a
hostnameoption (and corresponding flag) that gets passed to Borg as--hostname. I think that would allow you to address your use case—but only if you're aware of the problem. I'm thinking that something like the PoC or the--glob-archives *during bootstrap would still be necessary to avoid some of the pitfalls in the general case discussed above. So I think the hostname thing should probably be a separate ticket.#1317 is implemented now as an
archive_hostnameoption (and corresponding CLI flag). It requires Borg 1.4.5+ though.Nice one Dan, thanks!
Reopening this, as I think I still have to do something about the incorrect "latest" archive. Maybe not for your use case, but in general.
Okay, I cleaned up the proof of concept, made
bootstrapnot use the default archive name format, and merged all that to main. It'll be part of the next release.Released in borgmatic 2.1.7!