Support Overriding System Hostname #1317
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#1317
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
Just wanted to add an upstream borgbackup request that I have open:
https://github.com/borgbackup/borg/issues/9651
(borg2 already supports this).
This simplifies some use cases with borg (as documented in the above issue).
I think it is equally useful for borgmatic to support custom hostnames when one "controller" impersonates othe machines.
May also help with some other edge cases depending on how borgmatic is used. See #1310
Other notes / implementation ideas
Borgmatic should respect an environment variable (e.g.
BORGMATIC_HOSTNAMEor something like this depending on what gets finalized with borg as well) and use this instead ofhostnamewherever relevant.Additionally if the
BORG_HOSTNAME(or equivalent env var) is NOT set, then prior to invoking borg, borgmatic should duplicate theBORGMATIC_HOSTNAMEvariable intoBORG_HOSTNAME(or equivalent) OR explicitly invoke borg via the--hostname(or whatever final option is implemented).It will also be useful if this field/value can be used by hooks/scripts etc. when called via borgmatic.
NOTE: This requires
borgsupport which as of creating this issue is still open (for 1.4.x but completed for 2.x).Seems handy. This is implemented now in main via
--archive-hostnameand anarchive_hostnameoption as well. I didn't go with--hostname/hostnamebecause that would collide with the database flags/options. Tested with Borg 2.x, but let me know if the 1.4.5 feature ends up not using a Borg flag named--hostname(which is what borgmatic passes in).If any environment variable is used, borgmatic doesn't touch it, and it'll get passed through to Borg directly.
bootstraphard-codes--glob-archives#1310This is also particularly useful for prune but it looks like this is currently only implemented for create.
I think in general, this option could be useful in some other scenarios as well - essentially when borgmatic is being run on a host as "proxy" for another host to perform some operations (like prune, delete, archive checks, maybe even for a spot check in some cases).
This option should replace
{hostname}everywhere - not just for create.Could you also support an environment variable override for this? This will allow config file and script reuse with simple environment overrides (and may be specially useful for container setups).
Oh, good catch. I'll have a look at the other actions.
And I think I'd prefer not to add a one-off environment variable for this one option, but (at the risk of vast overengineering) I'd be happy to look at making all borgmatic options available as environment variables in the same way that all options are now available as command-line flags. Maybe as a separate ticket?
I will say that if Borg exposes this as an environment variable, then borgmatic shouldn't have to do anything to support that.
@witten wrote in #1317 (comment):
(IMHO) definitely overkill and I don't think it is needed for now.
Agreed - that will allow borgmatic to be pretty much a full "pass through" wrapper for borg (probably eliminating the need to use the
--archive-hostnamevia borgmatic for most scenarios if one goes with the environment variable option).Done! (Again.)
@witten - just a heads up that https://github.com/borgbackup/borg/issues/9651 is still work in progress but with an ongoing debate on whether to make the hostname override purely ENV VAR based or also support cmd line flags (for which you've added support).
I will update this issue once the final decision has been taken. Depending on the outcome there maybe changes and/or a rollback on the options required.
Sorry for the extra work in case that happens.
Thanks for the heads up. I'll reopen this ticket for now!
@witten - for now there is no plan to implement command line args/options for the hostname and username overrides in borg. As a result, the only way to override hostname/username is via environment variables.
I assume that for borgmatic most of these place holders are pass through to borg and so borgmatic shouldn't care. In case there are scenarios where borgmatic needs to use a custom hostname (maybe for a spotcheck?), it would be best if borgmatic also uses the the BORG_HOSTNAME (and BORG_USERNAME) override environment variables (rather than using/expecting a separate borgmatic specific variable).
@witten - Borg 1.4.5 has been released. Only environment variable support to override hostname and username (via BORG_HOSTNAME and BORG_USERNAME).
Could you please make appropriate changes in borgmatic for this (if required)?
Thanks for the update. This feature now passes the
archive_hostnameoption (or--archive-hostnameflag) to Borg via environment variable. It also passesBORG_HOSTNAMEthrough to Borg ifarchive_hostnameis not set and the environment variable is. It does not however readBORG_HOSTNAMEas input to borgmatic's own config. I'd be happy to implement a general mechanism for making all borgmatic config settable via environment variable (in a separate ticket), but I'd rather not implement a one-off for that.I also added a corresponding
archive_usernameoption /--archive-usernameflag for the{user}placeholder.All of this will be part of the next release.
Couple of points:
borgmatic/config/schema.yamlit would be more appropriate to haveexample: borgmatic_userorexample: backup_userinstead ofexample: example.orgfor thearchive_usernamesection.{username}or{hostname}internally - both are place holders purely for borg and as long as theBORG_HOSTNAMEandBORG_USERNAMEenvironment variables are set, borg should behave correctly in case of overrides?@quietquark wrote in #1317 (comment):
Thanks, fixed!
Yes—unless you create constants with those names.
Released in borgmatic 2.1.7!