30 lines
1.2 KiB
Bash
Executable File
30 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Copy the local backup tree to an already-mounted SMB share.
|
|
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 "$SMB_ENABLED" && (( FORCE == 0 )); then log SKIP "SMB method is disabled"; exit 0; fi
|
|
[[ -n "$SMB_MOUNT" ]] || die "SMB_MOUNT is not configured"
|
|
require_command rsync
|
|
require_command mountpoint
|
|
[[ -d "$BACKUP_ROOT" ]] || die "Backup root not found: $BACKUP_ROOT"
|
|
[[ -d "$SMB_MOUNT" ]] || die "SMB mount does not exist: $SMB_MOUNT"
|
|
mountpoint -q "$SMB_MOUNT" || die "SMB path is not a mounted filesystem: $SMB_MOUNT"
|
|
destination="${SMB_MOUNT%/}"
|
|
is_true "$SMB_HOST_SUBDIR" && destination="$destination/$BACKUP_HOSTNAME"
|
|
(( DRY_RUN )) || mkdir -p "$destination"
|
|
read -r -a rsync_args <<<"$SMB_RSYNC_ARGS"
|
|
(( DRY_RUN )) && rsync_args+=(--dry-run)
|
|
log INFO "Copying backups to $destination"
|
|
rsync "${rsync_args[@]}" "$BACKUP_ROOT/" "$destination/"
|
|
log DONE "SMB backup method completed"
|