Skip to content

repo-create: store default compression and chunker params in the repository, fixes #346 - #10438

Merged
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:repo-default-compression
Sep 27, 2026
Merged

ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:repo-default-compression

Conversation

@ThomasWaldmann

@ThomasWaldmann ThomasWaldmann commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Adds per-repository defaults for compression and chunker params, fixes #346 (set at repository creation time).

What it does

  • borg repo-create --compression SPEC / --chunker-params PARAMS store repository defaults.
  • Compression: the commands that compress data (create, recreate, import-tar, transfer, repo-compress, debug put-obj) use the repository default if no compression was given. borg repo-compress without --compression recompresses to the repository default.
  • Chunker params: create and import-tar use the repository default if no chunker params were given. recreate and transfer still only rechunk if --chunker-params is given; --chunker-params default now means the repository default (else the built-in default) instead of always the built-in default.
  • Precedence, for both:
    1. the command line, the environment (e.g. BORG_CREATE__COMPRESSION, BORG_CREATE__CHUNKER_PARAMS) or default.yaml
    2. the repository default
    3. the built-in default (lz4, fastcdc,19,23,21,2), as before
  • borg repo-info shows Default compression: … and Default chunker params: … (with (built-in) if the repository has no default); --json has a new defaults key.

Storage

The defaults are stored in a new config/defaults store object (msgpacked dict of strings, e.g. {"compression": "zstd,3", "chunker_params": "fastcdc,19,23,21,2"}) in the key's store object envelope, like the index/ and cache/ objects. So they are authenticated: nobody without the key can change them (e.g. remove an obfuscate compression, or turn compression on where none was chosen) without being noticed. config/config can not hold them: it is read before the key is known and is not authenticated.

  • missing object / missing entry: no repository default
  • failed authentication: IntegrityError
  • malformed content or an invalid value: InvalidRepositoryConfig (rc 16), the message names the problem

The resolution happens in one place, the with_repository decorator (default_compression() / default_chunker_params() in archiver/_common.py). --compression options default to None; ChunkerParams("default") returns a DEFAULT_CHUNKER_PARAMS marker, which is also the parser default of create and import-tar. config/defaults is read at most once per Repository object.

Not in this PR

  • Changing the defaults of an existing repository (only repo-create sets them).
  • borg check does not verify config/defaults; every command using it (incl. repo-info) authenticates it.

Docs / tests

Docs: repo-create epilog ("Repository defaults"), -C / --chunker-params help texts, borg help compression, data-structures.rst (new "Repository defaults" section), frontends.rst, quickstart. Usage docs are not regenerated.

New tests in repo_create_cmd_test.py: defaults used by create/repo-compress/recreate, precedence (command line, env), built-in fallbacks, --chunker-params default, invalid values at creation, tampered and invalid stored defaults. Full test suite passes locally (macOS, Python 3.15).

🤖 Generated with Claude Code

@ThomasWaldmann ThomasWaldmann changed the title repo-create --compression: store a default compression in the repository, refs #346 repo-create: store default compression and chunker params in the repository, refs #346 Sep 27, 2026
@ThomasWaldmann ThomasWaldmann changed the title repo-create: store default compression and chunker params in the repository, refs #346 repo-create: store default compression and chunker params in the repository, fixes #346 Sep 27, 2026
@codecov

codecov Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.70%. Comparing base (9b3b7eb) to head (f694ba3).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/borg/repository.py 86.36% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10438      +/-   ##
==========================================
+ Coverage   88.62%   88.70%   +0.07%     
==========================================
  Files         103      103              
  Lines       19229    19284      +55     
  Branches     2994     3004      +10     
==========================================
+ Hits        17041    17105      +64     
+ Misses       1522     1507      -15     
- Partials      666      672       +6     

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

…sitory, fixes borgbackup#346

"borg repo-create --compression SPEC --chunker-params PARAMS" stores repository
defaults in the new config/defaults store object.

Compression: the commands that compress data (create, recreate, import-tar,
transfer, repo-compress, debug put-obj) use the repository default if no
compression was given via the command line, the environment or default.yaml;
without a repository default, they use lz4 as before.

Chunker params: "--chunker-params default" now means the repository default,
else the built-in CHUNKER_PARAMS: ChunkerParams("default") returns the
DEFAULT_CHUNKER_PARAMS marker and with_repository replaces it by the real
chunker params. borg create and borg import-tar use the marker as their parser
default, so they use the repository default if no chunker params were given.
borg recreate and borg transfer still only rechunk if --chunker-params is
given; with "default", they rechunk to the repository default.

config/defaults is stored in the key's store object envelope, so it is
authenticated: nobody without the key can change the defaults (e.g. remove an
"obfuscate" compression) without being noticed. config/config can not hold
them, as it is read before the key is known and is not authenticated.
config/defaults is read at most once per Repository object.

borg repo-info shows the defaults (also in --json).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ThomasWaldmann
ThomasWaldmann force-pushed the repo-default-compression branch from 46853df to f694ba3 Compare September 27, 2026 01:41
@ThomasWaldmann
ThomasWaldmann merged commit 88d0c42 into borgbackup:master Sep 27, 2026
27 of 28 checks passed
@ThomasWaldmann
ThomasWaldmann deleted the repo-default-compression branch September 27, 2026 10:27
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.

Per-repo default parameters (chunker, compression)

1 participant