Skip to content

Fixes #9495 preserve cwd archive metadata#9501

Merged
ThomasWaldmann merged 3 commits intoborgbackup:masterfrom
ebuzerdrmz44:fix/transfer-cwd-metadata
Mar 19, 2026
Merged

Fixes #9495 preserve cwd archive metadata#9501
ThomasWaldmann merged 3 commits intoborgbackup:masterfrom
ebuzerdrmz44:fix/transfer-cwd-metadata

Conversation

@ebuzerdrmz44
Copy link
Contributor

Description

borg transfer was not preserving the cwdarchive metadata from the source archive. Instead, the transferred archive would end up with the cwd of the machine running the transfer command.

This adds cwd to the kept attributes in both UpgraderNoOp and UpgraderFrom12To20, so the original value is carried over. Also added a check for it test_transfer_archive_metadata.

Fixes #9495

Checklist

  • PR is against master (or maintenance branch if only applicable there)
  • New code has tests and docs where appropriate
  • Tests pass (run tox or the relevant test subset)
  • Commit messages are clean and reference related issues

@ThomasWaldmann ThomasWaldmann changed the title Fixes #9495 preserve cwd archieve metadata Fixes #9495 preserve cwd archive metadata Mar 17, 2026
for attr in ("hostname", "username", "comment", "chunker_params"):
for attr in ("hostname", "username", "comment", "chunker_params", "cwd"):
if hasattr(metadata, attr):
new_metadata[attr] = getattr(metadata, attr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, guess that solves it for borg 1.4 archives that do have the cwd metadata (borg 1.4.4+).

but what happens if an older archive gets transferred that does not have the cwd metadata, what will be and what should be in the resulting archive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review. I guess we shouldn't check cwd inside the for loop. After the loop, could we check it specifically, like getattr(metadata, "cwd", "")?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I'm not sure if "" is the best choice here . would you prefer leaving cwd unset or is that fine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can't know, having it unset might be the best choice. check if the code can cope with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out omitting cwd from additional_metadata wasn't enough . save() always falls back to self.cwd. Used None as a sentinel instead: upgraders pass cwd=None for archives without it, and save() drops the key when it sees None.

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.37%. Comparing base (1356aeb) to head (6b51f36).
⚠️ Report is 11 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9501      +/-   ##
==========================================
+ Coverage   83.36%   83.37%   +0.01%     
==========================================
  Files          87       87              
  Lines       15439    15448       +9     
  Branches     2309     2311       +2     
==========================================
+ Hits        12870    12880      +10     
  Misses       1818     1818              
+ Partials      751      750       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ThomasWaldmann ThomasWaldmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ThomasWaldmann ThomasWaldmann merged commit 7429789 into borgbackup:master Mar 19, 2026
20 checks passed
@ThomasWaldmann
Copy link
Member

Thanks!

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.

borg2: transfer "cwd" archive metadata

2 participants