27 lines
1.0 KiB
Bash
Executable File
27 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Copy the local backup tree to an rclone destination.
|
|
set -Eeuo pipefail
|
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
. "$SCRIPT_DIR/../lib/common.sh"
|
|
DRY_RUN=0; FORCE=0
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--dry-run) DRY_RUN=1 ;; --force) FORCE=1 ;;
|
|
-h|--help) echo "Usage: ${0##*/} [--dry-run] [--force]"; exit 0 ;;
|
|
*) die "Unknown option: $1" 2 ;;
|
|
esac
|
|
shift
|
|
done
|
|
if ! is_true "$RCLONE_ENABLED" && (( FORCE == 0 )); then log SKIP "rclone method is disabled"; exit 0; fi
|
|
[[ -n "$RCLONE_REMOTE" ]] || die "RCLONE_REMOTE is not configured"
|
|
require_command rclone
|
|
[[ -d "$BACKUP_ROOT" ]] || die "Backup root not found: $BACKUP_ROOT"
|
|
read -r -a extra_args <<<"$RCLONE_EXTRA_ARGS"
|
|
destination="${RCLONE_REMOTE%/}"
|
|
is_true "$RCLONE_HOST_SUBDIR" && destination="$destination/$BACKUP_HOSTNAME"
|
|
args=(copy "$BACKUP_ROOT" "$destination" "${extra_args[@]}")
|
|
(( DRY_RUN )) && args+=(--dry-run)
|
|
log INFO "Copying backups to $destination"
|
|
rclone "${args[@]}"
|
|
log DONE "rclone backup method completed"
|