Skip to content

Replace create --hostname/--username with BORG_HOSTNAME/BORG_USERNAME env vars, fixes #9651#9811

Open
ThomasWaldmann wants to merge 1 commit into
borgbackup:masterfrom
ThomasWaldmann:env-hostname-username-master
Open

Replace create --hostname/--username with BORG_HOSTNAME/BORG_USERNAME env vars, fixes #9651#9811
ThomasWaldmann wants to merge 1 commit into
borgbackup:masterfrom
ThomasWaldmann:env-hostname-username-master

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

Forward-port of the 1.4-maint env-var approach (#9810) to master, and removal of the borg create --hostname/--username CLI options (added in 2.0.0b21, #9402).

Per maintainer decision, hostname/username overriding is now env-vars only:

  • 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 (#9651): run borg on host A but impersonate host B — e.g. a reliably
online machine performs prune/compact/check on behalf of an opportunistically
online laptop against a shared, deduplicated repository, with consistent
per-hostname archive naming.

Fixes #9651.

Changes

  • Removed the --hostname/--username options and the corresponding
    Archive.__init__ parameters.
  • Archive.save() now stores os.environ.get("BORG_HOSTNAME") or platform.hostname
    and os.environ.get("BORG_USERNAME") or getuser().
  • _replace_placeholders() honors the same overrides for {hostname} / {user}.
  • fqdn, hostid (lock stale-removal, see BORG_HOST_ID) and the normal
    auto-detection are intentionally left untouched.
  • Docs: documented both env vars; regenerated create usage; changelog entry
    under 2.0.0b22.
  • Test renamed to test_hostname_and_username_override, now driving the feature
    via env vars and also asserting {hostname}-{user} placeholder substitution in
    the archive name.

Note

This is a breaking change relative to the 2.0.0b21 beta for anyone who used
--hostname/--username, but beta releases are explicitly test-only, so this is
acceptable.

🤖 Generated with Claude Code

… env vars, fixes borgbackup#9651

The --hostname/--username options on borg create (added in 2.0.0b21, borgbackup#9402)
are removed in favor of the BORG_HOSTNAME / BORG_USERNAME environment variables.

When set, these override the hostname/username stored in newly created archives
and used by the {hostname}/{user} placeholders (so they also apply to archive
names, prune --glob-archives, check, etc.). Useful to run borg on host A but
impersonate host B.

The env vars are read at the point of use; fqdn/hostid (see BORG_HOST_ID) 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-master branch from 35f6080 to 5e27122 Compare June 25, 2026 19:07
@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 84.77%. Comparing base (4a28995) to head (5e27122).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9811   +/-   ##
=======================================
  Coverage   84.77%   84.77%           
=======================================
  Files          92       92           
  Lines       15289    15285    -4     
  Branches     2297     2297           
=======================================
- Hits        12961    12958    -3     
+ Misses       1630     1629    -1     
  Partials      698      698           

☔ 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.

Support Custom Hostname Overrides in Borg 1.4.x

1 participant