Continue transfers after partial archive failures

This commit is contained in:
root committed 2026-11-01 11:47:13 +13:00
1 parent 2351cb6384
commit 657ac97ee7
2 files changed
+47 -5

No files matched your search

+7
View File
@@ -14,6 +14,13 @@ logic remains common and can be updated through Git.
4. `stages/90-prune.sh` — retain the newest configured number of `.zst` 4. `stages/90-prune.sh` — retain the newest configured number of `.zst`
archives locally, including legacy `.zst` and current `.tar.zst` names. archives locally, including legacy `.zst` and current `.tar.zst` names.
The archive stage continues through all configured projects after a project
fails. The pipeline then attempts each enabled transfer using archives that
are available locally, records archive and transfer results separately, skips
pruning on any failure, and exits non-zero so schedulers still detect the
problem. A partial archive run with successful transfers is reported as
`partial`, not as full success.
Every stage can also be run directly. The old `docker-backup.sh` name invokes Every stage can also be run directly. The old `docker-backup.sh` name invokes
the container archive stage, while `dockerbackup_prune.sh` invokes the local the container archive stage, while `dockerbackup_prune.sh` invokes the local
prune stage. Use the new `backup.sh` for the complete pipeline. prune stage. Use the new `backup.sh` for the complete pipeline.
+40 -5
View File
@@ -102,7 +102,13 @@ finish_run() {
if (( exit_code == 0 )); then if (( exit_code == 0 )); then
if (( DRY_RUN )); then status="dry_run_success"; else status="success"; fi if (( DRY_RUN )); then status="dry_run_success"; else status="success"; fi
else else
if (( DRY_RUN )); then status="dry_run_failed"; else status="failed"; fi if (( DRY_RUN )); then
status="dry_run_failed"
elif [[ "$BACKUP_LOCAL_ARCHIVE_STATUS" == "partial" && "$BACKUP_REMOTE_COPY_STATUS" == "success" ]]; then
status="partial"
else
status="failed"
fi
fi fi
# Persist history even when MQTT reporting is disabled. The stage handles # Persist history even when MQTT reporting is disabled. The stage handles
# MQTT publication conditionally and keeps its own failures non-fatal here. # MQTT publication conditionally and keeps its own failures non-fatal here.
@@ -123,6 +129,7 @@ flock -n 9 || die "Another backup run holds lock: $LOCK_FILE"
stage_args=() stage_args=()
(( DRY_RUN )) && stage_args+=(--dry-run) (( DRY_RUN )) && stage_args+=(--dry-run)
[[ -n "$CONTAINERS_OVERRIDE" ]] && stage_args+=(--containers "$CONTAINERS_OVERRIDE") [[ -n "$CONTAINERS_OVERRIDE" ]] && stage_args+=(--containers "$CONTAINERS_OVERRIDE")
pipeline_failed=0
log START "Backup pipeline for $BACKUP_HOSTNAME" log START "Backup pipeline for $BACKUP_HOSTNAME"
if is_true "$MQTT_REPORT_ENABLED"; then if is_true "$MQTT_REPORT_ENABLED"; then
# The retained running state lets Home Assistant show that work is active. # The retained running state lets Home Assistant show that work is active.
@@ -133,8 +140,14 @@ fi
if (( SKIP_CONTAINERS )); then if (( SKIP_CONTAINERS )); then
BACKUP_LOCAL_ARCHIVE_STATUS="skipped" BACKUP_LOCAL_ARCHIVE_STATUS="skipped"
else else
"$SCRIPT_DIR/stages/10-containers.sh" "${stage_args[@]}" if "$SCRIPT_DIR/stages/10-containers.sh" "${stage_args[@]}"; then
if (( DRY_RUN )); then BACKUP_LOCAL_ARCHIVE_STATUS="dry_run"; else BACKUP_LOCAL_ARCHIVE_STATUS="success"; fi if (( DRY_RUN )); then BACKUP_LOCAL_ARCHIVE_STATUS="dry_run"; else BACKUP_LOCAL_ARCHIVE_STATUS="success"; fi
else
pipeline_failed=1
archived_count="$(grep -c "\[ARCHIVE\] Created " "$BACKUP_RUN_LOG" || true)"
if (( archived_count > 0 )); then BACKUP_LOCAL_ARCHIVE_STATUS="partial"; else BACKUP_LOCAL_ARCHIVE_STATUS="failed"; fi
log WARN "Some archive work failed; continuing transfer stages for archives available locally"
fi
fi fi
method_args=(); (( DRY_RUN )) && method_args+=(--dry-run) method_args=(); (( DRY_RUN )) && method_args+=(--dry-run)
# BACKUP_METHODS contains short names (for example: "rclone smb"). Numeric # BACKUP_METHODS contains short names (for example: "rclone smb"). Numeric
@@ -147,8 +160,19 @@ for method in $BACKUP_METHODS; do
rclone) if is_true "$RCLONE_ENABLED"; then BACKUP_RCLONE_STATUS="running"; fi ;; rclone) if is_true "$RCLONE_ENABLED"; then BACKUP_RCLONE_STATUS="running"; fi ;;
smb) if is_true "$SMB_ENABLED"; then BACKUP_SMB_STATUS="running"; fi ;; smb) if is_true "$SMB_ENABLED"; then BACKUP_SMB_STATUS="running"; fi ;;
esac esac
"$method_script" "${method_args[@]}" if "$method_script" "${method_args[@]}"; then
if (( DRY_RUN )); then method_result=0
else
method_result=$?
pipeline_failed=1
log ERROR "$method transfer stage failed; continuing with remaining stages"
fi
if (( method_result != 0 )); then
case "$method" in
rclone) [[ "$BACKUP_RCLONE_STATUS" == "running" ]] && BACKUP_RCLONE_STATUS="failed" ;;
smb) [[ "$BACKUP_SMB_STATUS" == "running" ]] && BACKUP_SMB_STATUS="failed" ;;
esac
elif (( DRY_RUN )); then
case "$method" in case "$method" in
rclone) [[ "$BACKUP_RCLONE_STATUS" == "running" ]] && BACKUP_RCLONE_STATUS="dry_run" ;; rclone) [[ "$BACKUP_RCLONE_STATUS" == "running" ]] && BACKUP_RCLONE_STATUS="dry_run" ;;
smb) [[ "$BACKUP_SMB_STATUS" == "running" ]] && BACKUP_SMB_STATUS="dry_run" ;; smb) [[ "$BACKUP_SMB_STATUS" == "running" ]] && BACKUP_SMB_STATUS="dry_run" ;;
@@ -160,5 +184,16 @@ for method in $BACKUP_METHODS; do
esac esac
fi fi
done done
(( SKIP_PRUNE )) || "$SCRIPT_DIR/stages/90-prune.sh" "${method_args[@]}" if (( SKIP_PRUNE )); then
:
elif (( pipeline_failed )); then
log WARN "Skipping prune because one or more earlier stages failed"
elif ! "$SCRIPT_DIR/stages/90-prune.sh" "${method_args[@]}"; then
pipeline_failed=1
log ERROR "Prune stage failed"
fi
if (( pipeline_failed )); then
log ERROR "Backup pipeline completed with failures"
exit 1
fi
log DONE "Backup pipeline completed successfully" log DONE "Backup pipeline completed successfully"