Skip to content

Add gib repair command to detect corruption and recover using redundant copies #7

@Theryston

Description

@Theryston

Description:

Create a repair tool that can:

  1. detect corrupted files in the repository (especially indexes and backup manifests)
  2. automatically restore valid versions from redundant copies when available

This command is meant to be the practical “fix it” companion to gib check #6

Why:

Users need a straightforward way to recover from corruption without manually digging through objects. Since we plan to store redundant copies for critical files, we should use them automatically.

Proposed CLI:

gib repair --storage <name> --key <repo>

Proposed behavior:

  • Run the same validations as gib check

  • For each detected corrupted/missing file:

    • If it is a critical file with a copy:

      • Validate the copy (checksum/parse)
      • Replace the corrupted primary with the copy
    • If primary is valid but copy is corrupted:

      • Regenerate the copy from primary
    • If both are corrupted/missing:

      • Report as unrecoverable

What counts as “corrupted”:

  • Fails checksum (checksums are stored)
  • Fails parsing / schema validation
  • Truncated / malformed data
  • Unexpected version/magic bytes

Targets:

  • indexes/chunksindexes/chunks.bak
  • indexes/backupsindexes/backups.bak
  • backups/<hash>backups/<hash>.bak

Safety:

  • Default mode should create an “audit log” of all changes and print a summary
  • Always keep at least one known-good file (e.g., if replacing, move old to *.corrupt.<timestamp> when possible)

Acceptance Criteria:

  • gib repair can fix:
    • missing primary when copy exists
    • corrupted primary when copy is valid
    • missing/corrupted copy when primary is valid
  • Produces clear output and stable exit codes
  • Works on both local and S3 storage backends

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions