Skip to content

create/import-tar --json: report the deduplicated size of the new archive, #10335 - #10336

Merged
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:create-json-dedup-size
Sep 7, 2026
Merged

create/import-tar --json: report the deduplicated size of the new archive, #10335#10336
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:create-json-dedup-size

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

Fixes #10335.

The claim in the issue is correct: Statistics.usize is accumulated while creating an archive and printed as Deduplicated size: in the text --stats block, but Statistics.as_dict() did not include it, and --json replaces the text block, so a JSON consumer could not get the deduplicated size at all. borg info can not recover it later (calc_stats() does not compute it, that is expensive).

Changes

  • Statistics.as_dict() reports deduplicated_size (the borg 1.x key; in borg 2 it is the deduplicated original size, see the 2.0.0a2 changelog). This covers borg create --json, borg import-tar --json and the archive_progress JSON lines (which already show the U size in text mode).
  • Archive.calc_stats() (used by borg info) marks usize as unknown (None) instead of 0, and as_dict() leaves the key out then. So info --json stays honest: absent means "not computed", not "zero" (option 2 from the issue).
  • Docs: docs/internals/frontends.rst (keys, examples, the borg info note), docs/changes.rst, and the create / info help texts (docs/usage/*.rst.inc regenerated, only these two files changed). The create help still described a borg 1.x "This Archive" / "All archives" table that borg 2 does not print; fixed while there.
  • Tests: Statistics.as_dict() unit test, create --json (fresh repo vs. repeated backup), import-tar --json, and info --json not having the key.

Sample output (borg from this branch)

$ borg create --json arch input          # fresh repository
"stats": {"deduplicated_size": 150504, "original_size": 150504, "nfiles": 2, ...}
$ borg create --json arch input          # unchanged input again
"stats": {"deduplicated_size": 469, "original_size": 150504, "nfiles": 2, ...}
$ borg create --stats arch input         # the text block agrees
Deduplicated size: 470 B
$ borg info --json --last 1              # no deduplicated_size key
"stats": {"chunking_time": 0.0, "files_stats": {}, "hashing_time": 0.0, "nfiles": 2, "original_size": 150035}
$ borg create --progress --log-json ...
{"original_size": 0, "deduplicated_size": 0, "nfiles": 0, ..., "type": "archive_progress", "finished": false}

The --dry-run --json output is unchanged (nfiles and original_size only, nothing is deduplicated there).

🤖 Generated with Claude Code

…hive, borgbackup#10335

Statistics.usize (the size of the chunks that were new to the repository) is
accumulated while an archive is created and printed as "Deduplicated size" in
the text --stats block, but Statistics.as_dict() did not include it, so the
--json output (which replaces the text block) had no way to get it.

as_dict() now reports it as "deduplicated_size", as borg 1.x did (there it was
the deduplicated compressed size, in borg 2 it is the deduplicated original
size, see the 2.0.0a2 changelog). This covers borg create --json, borg
import-tar --json and the archive_progress JSON lines.

Archive.calc_stats() (used by borg info) can not compute the deduplicated size
of an existing archive (that is expensive, see borg analyze), so it now marks
usize as unknown (None) and as_dict() leaves the key out there instead of
reporting a misleading 0.

Also fix the create help text: borg 2 prints a single stats block, there is no
"This Archive" / "All archives" table anymore.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.75%. Comparing base (95856d4) to head (607ab62).
⚠️ Report is 9 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10336      +/-   ##
==========================================
+ Coverage   87.74%   87.75%   +0.01%     
==========================================
  Files         103      103              
  Lines       18817    18821       +4     
  Branches     2905     2906       +1     
==========================================
+ Hits        16511    16517       +6     
+ Misses       1602     1600       -2     
  Partials      704      704              

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

@ThomasWaldmann
ThomasWaldmann merged commit 63dcf95 into borgbackup:master Sep 7, 2026
26 checks passed
@ThomasWaldmann
ThomasWaldmann deleted the create-json-dedup-size branch September 7, 2026 19:18
@ioanalytica

Copy link
Copy Markdown

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

create --json: report the deduplicated size of the new archive (usize is computed but only printed in the text --stats block)

2 participants