Skip to content

new BORG_UNITS env var: si / iec / raw size formatting, #5513 - #9977

Merged
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:units-5513
Jul 30, 2026
Merged

new BORG_UNITS env var: si / iec / raw size formatting, #5513#9977
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:units-5513

Conversation

@ThomasWaldmann

@ThomasWaldmann ThomasWaldmann commented Jul 30, 2026

Copy link
Copy Markdown
Member

Fixes #5513.

BORG_UNITS determines how borg formats sizes in human-readable output:

  • si (default): decimal units, e.g. 1.23 MB (1kB = 1000B)
  • iec: binary units, e.g. 1.18 MiB (1KiB = 1024B)
  • raw: exact byte counts, e.g. 1234567 B

raw is what #5513 asked for: sizes that a script (e.g. for monitoring) can parse without
having to deal with scaled values and different units. It applies to all human-readable size
output, e.g.:

$ BORG_UNITS=raw borg info arch1 | tail -1
Original size: 993726 B

$ BORG_UNITS=raw borg -v compact --stats
Source data size was 993691 B in 68 files.
Deduplicated size is 993691 B.
Repository size is 524037 B in 69 objects.

Note that borg compact --stats uses precision=0, so it printed e.g. Repository size is 2 MB before - with BORG_UNITS=raw the exact value is not lost.

BORG_IEC was removed, use BORG_UNITS=iec instead. An invalid BORG_UNITS value is
warned about (once) and ignored.

Implementation notes:

  • get_size_units() resolves the units and format_file_size() uses them, so the whole iec
    argument plumbing through Archive / Statistics / ArchiveFormatter / Cache /
    ArchiveChecker / ArchiveGarbageCollector and use_iec_units() could be removed. Beside
    being less code, this also makes the setting effective at the call sites that never passed
    iec=use_iec_units(), e.g. borg repo-space.
  • raw rounds floats (some callers format throughput values).
  • The man pages are not updated here: scripts/make.py build_man currently regenerates all 48
    of them (they are stale for unrelated reasons, e.g. the return codes section and
    borg-webdav), which would just add noise to this PR.

Not part of this PR, but noticed while looking at the issue: for the repository size, which is
what the issue author actually wanted to monitor, there is still no machine-readable output at
all - borg compact --stats and borg analyze only log human-readable text (no --json), and
borg repo-info does not report sizes. Archive sizes are fine (borg info --json,
borg list/repo-list --format "{size}" give byte counts).

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.14815% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.84%. Comparing base (28de45c) to head (3a864cd).
⚠️ Report is 7 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/borg/archive.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9977      +/-   ##
==========================================
+ Coverage   85.83%   85.84%   +0.01%     
==========================================
  Files          95       95              
  Lines       17034    17056      +22     
  Branches     2607     2614       +7     
==========================================
+ Hits        14621    14642      +21     
- Misses       1673     1674       +1     
  Partials      740      740              

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

BORG_UNITS determines how borg formats sizes in human-readable output:

- si (default): decimal units, e.g. 1.23 MB (1kB = 1000B)
- iec: binary units, e.g. 1.18 MiB (1KiB = 1024B)
- raw: exact byte counts, e.g. 1234567 B

raw is meant for scripts (e.g. monitoring) that want to parse sizes without
having to deal with scaled values and units. An invalid BORG_UNITS value is
warned about (once) and ignored.

BORG_IEC was removed, use BORG_UNITS=iec.

format_file_size now determines the units itself (via BORG_UNITS), so the iec
argument plumbing through Archive / Statistics / ArchiveFormatter / Cache /
ArchiveChecker / ArchiveGarbageCollector and use_iec_units() are all gone.
Beside being less code, this also makes the setting effective at the call
sites that never passed iec=use_iec_units(), e.g. borg repo-space.
@ThomasWaldmann
ThomasWaldmann merged commit ce4972c into borgbackup:master Jul 30, 2026
19 checks passed
@ThomasWaldmann
ThomasWaldmann deleted the units-5513 branch July 31, 2026 06:33
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.

Show repository size in bytes or fixed unit

1 participant