Refactor Docker backups into modular pipeline
This commit is contained in:
1 parent
3ba4b7f738
commit
261e88f5dc
12 files changed
+480
-848
No files matched your search
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# Main pipeline: container archives, configured methods, then local prune.
|
||||
set -Eeuo pipefail
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||
. "$SCRIPT_DIR/lib/common.sh"
|
||||
DRY_RUN=0; SKIP_CONTAINERS=0; SKIP_PRUNE=0
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--dry-run|-t) DRY_RUN=1 ;; --skip-containers) SKIP_CONTAINERS=1 ;; --skip-prune) SKIP_PRUNE=1 ;;
|
||||
-h|--help)
|
||||
echo "Usage: ${0##*/} [--dry-run] [--skip-containers] [--skip-prune]"
|
||||
echo "Methods run in BACKUP_METHODS order. Add methods/NN-name.sh and list name in BACKUP_METHODS."
|
||||
exit 0 ;;
|
||||
*) die "Unknown option: $1" 2 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
require_command flock
|
||||
mkdir -p "$(dirname "$LOCK_FILE")"
|
||||
exec 9>"$LOCK_FILE"
|
||||
flock -n 9 || die "Another backup run holds lock: $LOCK_FILE"
|
||||
stage_args=(); (( DRY_RUN )) && stage_args+=(--dry-run)
|
||||
log START "Backup pipeline for $BACKUP_HOSTNAME"
|
||||
(( SKIP_CONTAINERS )) || "$SCRIPT_DIR/stages/10-containers.sh" "${stage_args[@]}"
|
||||
for method in $BACKUP_METHODS; do
|
||||
method_script=""
|
||||
while IFS= read -r candidate; do method_script="$candidate"; break; done < <(find "$SCRIPT_DIR/methods" -maxdepth 1 -type f -name "*-${method}.sh" -print | sort)
|
||||
[[ -n "$method_script" ]] || die "Configured backup method not found: $method"
|
||||
"$method_script" "${stage_args[@]}"
|
||||
done
|
||||
(( SKIP_PRUNE )) || "$SCRIPT_DIR/stages/90-prune.sh" "${stage_args[@]}"
|
||||
log DONE "Backup pipeline completed successfully"
|
||||
Reference in new issue
Block a user