Skip to content

Support BORG_HOSTNAME and BORG_USERNAME env vars, fixes #9651#9810

Open
ThomasWaldmann wants to merge 1 commit into
borgbackup:1.4-maintfrom
ThomasWaldmann:env-hostname-username-1.4
Open

Support BORG_HOSTNAME and BORG_USERNAME env vars, fixes #9651#9810
ThomasWaldmann wants to merge 1 commit into
borgbackup:1.4-maintfrom
ThomasWaldmann:env-hostname-username-1.4

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

Adds two environment variables to override the hostname/username borg uses:

  • BORG_HOSTNAME — overrides the hostname
  • BORG_USERNAME — overrides the username

When set, the override is used both for the value stored in newly created
archives
and for the {hostname} / {user} placeholders (so it also
applies 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() in src/borg/archive.py (stored archive metadata)
  • replace_placeholders() in src/borg/helpers/parseformat.py ({hostname}/{user})

fqdn, hostid (lock stale-removal, see BORG_HOST_ID) and the normal
auto-detection are intentionally left untouched.

Scope note

Per maintainer decision, this is env-vars only — no borg create --hostname/--username
CLI options (unlike the borg2/master change #9402).

Docs / tests

  • Documented both vars in the environment variables reference.
  • Changelog entry under 1.4.5.
  • New test test_create_hostname_username_override verifies both the stored
    metadata and {hostname}-{user} placeholder substitution in the archive name.

🤖 Generated with Claude Code

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>
@ThomasWaldmann ThomasWaldmann force-pushed the env-hostname-username-1.4 branch from e16dbc5 to 62e3013 Compare June 25, 2026 18:51
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.06%. Comparing base (b09bbed) to head (62e3013).
⚠️ Report is 4 commits behind head on 1.4-maint.

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.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant