Skip to content

check --repair: rebuild a corrupt repository index from the packs, #10026 - #10048

Open
mr-raj12 wants to merge 1 commit into
borgbackup:masterfrom
mr-raj12:check-repair-index-rebuild-10026
Open

check --repair: rebuild a corrupt repository index from the packs, #10026#10048
mr-raj12 wants to merge 1 commit into
borgbackup:masterfrom
mr-raj12:check-repair-index-rebuild-10026

Conversation

@mr-raj12

@mr-raj12 mr-raj12 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

A corrupt chunks index currently leaves a borg2 repo stuck: Repository.check(repair=True) just logged "repository repair not implemented" and stopped. This implements the repository-level index repair from #10026.

When the index is corrupt and --repair is given, the index is now rebuilt from the packs and persisted:

  • Each pack's sha256 is verified, then the chunks index is rebuilt from the object headers of the intact packs. A pack whose sha256 no longer matches is skipped, so a corrupted header cannot put a wrong or absent chunk into the index and break dedup on the next create (borg2: avoid doing an unnecessary rebuild of the index #8476).
  • Chunks that live only in skipped packs are dropped from the index. Salvaging objects out of corrupt packs needs the key and is not implemented yet (to pack or not to pack ... #8572).
  • build_chunkindex_from_repo gets an only_packs filter and a progress indicator for the rebuild.

Left for follow-up work: pack salvage and reading the persisted corrupt-pack list (needs #9925), and keeping the rebuilt index across the archives check. ArchiveChecker.finish still deletes it, so a full borg check --repair rebuilds again in the archives phase, while --repository-only --repair keeps the persisted index.

Tests cover rebuilding a corrupt index (every chunk gets indexed and resolves) and excluding a corrupt pack from the rebuild (its chunk is dropped, the intact pack's chunk is recovered).

Refs #10026.

…rgbackup#10026

Verify each pack's sha256 and rebuild the chunks index from the intact
packs' object headers, then persist it. Chunks that exist only in corrupt
packs are dropped; salvaging them is not implemented yet.
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.64%. Comparing base (5e119f6) to head (750805b).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/borg/repository.py 95.83% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10048      +/-   ##
==========================================
+ Coverage   86.61%   86.64%   +0.02%     
==========================================
  Files          97       97              
  Lines       16912    16942      +30     
  Branches     2550     2557       +7     
==========================================
+ Hits        14649    14680      +31     
+ Misses       1571     1570       -1     
  Partials      692      692              

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

1 participant