Skip to content

fix(copy): exit with an error when copying to a target failed - #1950

Open
AlphaJack wants to merge 1 commit into
rustic-rs:mainfrom
AlphaJack:fix/copy-exit-code
Open

AlphaJack wants to merge 1 commit into
rustic-rs:mainfrom
AlphaJack:fix/copy-exit-code

Conversation

@AlphaJack

Copy link
Copy Markdown
Contributor

Fixes #1940

Problem

copy logs each target's error ([ERROR] error copying to target: …), goes on with the next target, and then exits 0. Scripts and schedulers can't tell that nothing was copied: an offline target, a target with another chunker, a target that doesn't exist, or rustic-rs/rustic_core#601 (copy --init between plain and hot/cold repositories).

Fix

Like backup with several snapshots ("Not all snapshots were generated successfully!"), copy still tries every target, then returns an error if any of them failed:

[ERROR] error copying to target: …
error: Copying failed for at least one target!

The exit code is then non-zero. When all targets succeed, nothing changes.

Tests

test_copy_to_failing_target_fails (in tests/backup_restore.rs) backs up, then copies to a target profile whose repository doesn't exist. On main the copy exits 0 and the test fails ("Unexpected success", code=0). With this change it fails as expected and the test passes. The other tests in backup_restore.rs still pass.

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.

rustic copy returns sucessful status code even though it failed

1 participant