borg check --repair return code
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+
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)
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.
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).
Guess we just keep it as is:
- for detecting problems use
borg checkwithout--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).