diff --git a/scripts/backup.sh b/scripts/backup.sh index 5ef85df..17197cb 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -25,7 +25,7 @@ get_flag() { VALID_FLAGS=( "source" "target" "dry-run" "verbose" "compress" "system" "ssh-send" "ssh-receive" "link" "ntfs" "name" "exclude" - "progress" + "progress" "sudo" ) # ---------------------------------------------------------------------------- @@ -81,6 +81,7 @@ COMPRESS=false SYSTEM=false NTFS=false PROGRESS=false +SUDO_PRIV=flase get_flag "dry-run" && DRY_RUN=true get_flag "verbose" && VERBOSE=true @@ -88,6 +89,7 @@ get_flag "compress" && COMPRESS=true get_flag "system" && SYSTEM=true get_flag "ntfs" && NTFS=true get_flag "progress" && PROGRESS=true +get_flag "sudo" && SUDO_PRIV=true # ---------------------------------------------------------------------------- # Required argument checks @@ -109,17 +111,6 @@ else TARGET_PATH="${TARGET[0]}" fi -# ----------------------------------------------------------------------------- -# Prevent recursive backup of target inside source (Ask me how I Know) -# ----------------------------------------------------------------------------- -if [[ "${SOURCE[0]}" == "/" || "${SOURCE[0]}" == /* ]]; then - # Resolve absolute target path - TARGET_REAL=$(realpath "$TARGET_PATH") - - if [[ "$TARGET_REAL" == "${SOURCE[0]}"* ]]; then - EXCLUDES+=("$TARGET_REAL") - fi -fi # ---------------------------------------------------------------------------- # SSH configuration (push or pull) @@ -167,6 +158,23 @@ if [[ "$SYSTEM" == true ]]; then EXCLUDES+=("${SYSTEM_EXCLUDES[@]}") fi +# ----------------------------------------------------------------------------- +# Prevent recursive backup of target inside source and Link (Ask me how I Know) +# ----------------------------------------------------------------------------- +if [[ "${SOURCE[0]}" == "/" || "${SOURCE[0]}" == /* ]]; then + # Resolve absolute target path + TARGET_REAL=$(realpath "$TARGET_PATH") + + if [[ "$TARGET_REAL" == "${SOURCE[0]}"* ]]; then + EXCLUDES+=("$TARGET_REAL") + fi +fi + +if [[ -n "$LINK_DIR" ]]; then + # Automatically exclude the link destination itself + EXCLUDES+=("$LINK_DIR") +fi + # ---------------------------------------------------------------------------- # Build rsync command # ---------------------------------------------------------------------------- @@ -180,6 +188,7 @@ fi [[ "$PROGRESS" == true ]] && CMD+=("-P") [[ "$PROGRESS" == false ]] && CMD+=("--partial") +[[ "$SUDO_PRIV" == true ]] && CMD+=("--rsync-path=\"sudo rsync\"") CMD+=("--delete-excluded")