borg icon indicating copy to clipboard operation
borg copied to clipboard

borg check --repair return code

Open ThomasWaldmann opened this issue 8 years ago • 1 comments

just had a borg check --repair run and it fixed a ton of issues (replacing missing chunks with all-zero replacement chunks).

rc was 0.

I was wondering if that is the right rc for that case.

We have to distinguish here whether borg check itself had major issues or whether it found/fixed issues.

borg 1.1.3+

ThomasWaldmann avatar Dec 16 '17 17:12 ThomasWaldmann

Maybe the following semantics makes sense:

Differentiate between:

  • borg check ("is everything ok?")
  • borg check --repair ("i know something is broken and want it repaired")

borg check:

  • 0 = everything ok
  • 1 = warnings (minor troubles with checking or minor issues found in repo/archive)
  • 2 = error (major errors with checking or major issues found in repo/archive)

borg check --repair:

  • 0 = everything ok
  • 1 = warnings (minor troubles with repairing)
  • 2 = error (major errors with repairing)

ThomasWaldmann avatar Dec 18 '17 15:12 ThomasWaldmann

Repository check (status quo)

The Repository.check method (local or via RPC api) only returns a boolean:

        return not error_found or repair

So that means:

  • True if no error was found for borg check (without --repair).
  • Always True for borg check --repair.
  • Besides returning a boolean value, there could be also Python exceptions.

If the method returns False, borg will terminate with rc 1 (WARNING). Otherwise it will continue with archives check usually or return with rc 0 (OK) for --repository-only. Any abrupt termination due to an uncatched Python exception would terminate with rc 2 (ERROR).

Guess we should not change that API for borg 1.x, because the borg version on the server (repo) side might be different from the client version, so any change would complicate things.

ThomasWaldmann avatar Feb 08 '24 18:02 ThomasWaldmann

Archives check (status quo)

The ArchiveChecker.check method (always local) only returns a boolean:

        return self.repair or not self.error_found

So that means:

  • True if no error was found for borg check (without --repair).
  • Always True for borg check --repair.
  • Besides returning a boolean value, there could be also Python exceptions.

If the method returns False, borg will terminate with rc 1 (WARNING). Otherwise it will return with rc 0 (OK). Any abrupt termination due to an uncatched Python exception would terminate with rc 2 (ERROR).

ThomasWaldmann avatar Feb 08 '24 18:02 ThomasWaldmann

Guess we just keep it as is:

  • for detecting problems use borg check without --repair - rc will be 0 if all is ok, 1 if there were issues found and 2 if something crashed.
  • for repairing a repo, use borg check --repair. rc usually will be 0, except if something crashed (rc 2).

ThomasWaldmann avatar Feb 08 '24 19:02 ThomasWaldmann