fix(deploy): propagate backup retention failures

This commit is contained in:
cesnimda
2026-11-11 14:59:12 +01:00
parent 3cca441874
commit e1c8e84502
9 changed files with 261 additions and 7 deletions
+19 -4
View File
@@ -559,14 +559,29 @@ apply_backup_retention() {
echo "Monthly recovery set retained: ${monthly_dir}"
fi
find "$BACKUP_DIR" -maxdepth 1 -type f -name 'jobtracker-*' -mtime "+$daily_days" -delete
if ! find "$BACKUP_DIR" -maxdepth 1 -type f -name 'jobtracker-*' -mtime "+$daily_days" -delete; then
echo "Daily backup retention failed. Aborting deploy."
return 1
fi
local monthly_dirs=()
mapfile -t monthly_dirs < <(find "$monthly_root" -mindepth 1 -maxdepth 1 -type d -name '20??-??' | sort)
local monthly_dirs=() monthly_listing
# Check the pipeline directly; mapfile cannot report process-substitution failures.
if ! monthly_listing="$(find "$monthly_root" -mindepth 1 -maxdepth 1 -type d -name '20??-??' | sort)"; then
echo "Could not enumerate monthly backups. Aborting deploy."
return 1
fi
if [ -n "$monthly_listing" ]; then
mapfile -t monthly_dirs <<< "$monthly_listing"
fi
while [ "${#monthly_dirs[@]}" -gt "$monthly_count" ]; do
local oldest="${monthly_dirs[0]}"
case "$oldest" in
"$monthly_root"/20??-??) rm -rf -- "$oldest" ;;
"$monthly_root"/20??-??)
if ! rm -rf -- "$oldest"; then
echo "Monthly backup retention failed. Aborting deploy."
return 1
fi
;;
*) echo "Refusing to prune unexpected monthly backup path: $oldest"; return 1 ;;
esac
monthly_dirs=("${monthly_dirs[@]:1}")