Skip to content

[Backup] Return error when mariabackup or other backup steps fail#7159

Open
EzxD wants to merge 1 commit intomailcow:stagingfrom
EzxD:fix/backup-mariabackup-error-handling
Open

[Backup] Return error when mariabackup or other backup steps fail#7159
EzxD wants to merge 1 commit intomailcow:stagingfrom
EzxD:fix/backup-mariabackup-error-handling

Conversation

@EzxD
Copy link
Copy Markdown

@EzxD EzxD commented Mar 22, 2026

Contribution Guidelines

What does this PR include?

Short Description

Fixes #7144. backup_and_restore.sh exits with code 0 even when mariabackup fails, producing broken backups silently.

Two problems:

  1. The mariabackup commands inside docker run are chained with ; (semicolons), so --prepare, chown, and tar all run even after --backup fails — creating a broken archive that looks valid.
  2. None of the docker run backup commands have their exit codes checked.

This PR changes the mariabackup chain from ; to && and adds exit code checks for all backup steps. The script now exits with code 1 if any step failed.

Affected Containers

None — this only changes the host-side helper script helper-scripts/backup_and_restore.sh.

Did you run tests?

What did you tested?

Verified the shell logic that causes the bug:

# Old behavior (;) — all commands run, exit 0
/bin/sh -c "false ; echo 'prepare ran' ; echo 'tar ran'"
# Output: prepare ran / tar ran / exit code: 0

# New behavior (&&) — stops at failure, exit 1
/bin/sh -c "false && echo 'prepare ran' && echo 'tar ran'"
# Output: exit code: 1

Also ran bash -n syntax check on the modified script.

What were the final results? (Awaited, got)

With &&, the command chain stops at the first failure and propagates a non-zero exit code. The error tracking logic then catches it and exits the script with code 1. This matches the expected behavior described in #7144.

Fixes mailcow#7144: backup_and_restore.sh exited with code 0 even when
mariabackup failed, producing broken backups silently.

- Change mariabackup command chain from ; to && so failures stop
  the pipeline instead of continuing to tar a broken backup
- Track exit codes for all backup steps (vmail, crypt, redis,
  rspamd, postfix, mysql) and report failures
- Exit with code 1 if any backup step failed
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