Support BORG_HOSTNAME and BORG_USERNAME env vars, fixes #9651#9810
Open
ThomasWaldmann wants to merge 1 commit into
Open
Support BORG_HOSTNAME and BORG_USERNAME env vars, fixes #9651#9810ThomasWaldmann wants to merge 1 commit into
ThomasWaldmann wants to merge 1 commit into
Conversation
When set, these override the hostname/username that is stored in newly
created archives and that is used for the {hostname}/{user} placeholders
(e.g. in archive names, prune --glob-archives, check). Useful to run borg
on host A but impersonate host B.
fqdn/hostid and the auto-detection are intentionally left untouched.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
e16dbc5 to
62e3013
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 1.4-maint #9810 +/- ##
=============================================
+ Coverage 82.04% 82.06% +0.01%
=============================================
Files 38 38
Lines 11384 11384
Branches 1794 1794
=============================================
+ Hits 9340 9342 +2
+ Misses 1460 1459 -1
+ Partials 584 583 -1 ☔ View full report in Codecov by Harness. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two environment variables to override the hostname/username borg uses:
BORG_HOSTNAME— overrides the hostnameBORG_USERNAME— overrides the usernameWhen set, the override is used both for the value stored in newly created
archives and for the
{hostname}/{user}placeholders (so it alsoapplies to archive names,
prune --glob-archives '{hostname}-*',check, etc.).Use case (from #9651): run borg on host A but impersonate host B — e.g. a
reliably-online desktop performs prune/compact/check on behalf of an
opportunistically-online laptop against a shared, deduplicated repository, and
wants consistent per-hostname archive naming / prune configs.
Fixes #9651.
Implementation
The env vars are read at the point of use (
os.environ.get('BORG_HOSTNAME') or hostname),in the two places that consume these values:
Archive.save()insrc/borg/archive.py(stored archive metadata)replace_placeholders()insrc/borg/helpers/parseformat.py({hostname}/{user})fqdn,hostid(lock stale-removal, seeBORG_HOST_ID) and the normalauto-detection are intentionally left untouched.
Scope note
Per maintainer decision, this is env-vars only — no
borg create --hostname/--usernameCLI options (unlike the borg2/master change #9402).
Docs / tests
test_create_hostname_username_overrideverifies both the storedmetadata and
{hostname}-{user}placeholder substitution in the archive name.🤖 Generated with Claude Code