33 lines
1.4 KiB
Bash
Executable File
33 lines
1.4 KiB
Bash
Executable File
#!/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"
|