diff --git a/scripts/backup.sh b/scripts/backup.sh index 0b57813..5ef85df 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -25,14 +25,25 @@ get_flag() { VALID_FLAGS=( "source" "target" "dry-run" "verbose" "compress" "system" "ssh-send" "ssh-receive" "link" "ntfs" "name" "exclude" + "progress" ) # ---------------------------------------------------------------------------- # Default values and constants # ---------------------------------------------------------------------------- SYSTEM_EXCLUDES=( - "/dev/*" "/proc/*" "/sys/*" "/tmp/*" "/run/*" "/mnt/*" "/media/*" - "swapfile" "lost+found" ".cache" "Downloads" ".ecryptfs" + "/dev" + "/proc" + "/sys" + "/tmp" + "/run" + "/mnt" + "/media" + "/swapfile" + "/lost+found" + "/home/*/.cache" + "/home/*/Downloads" + "/home/*/.ecryptfs" ) # ---------------------------------------------------------------------------- @@ -69,12 +80,14 @@ VERBOSE=false COMPRESS=false SYSTEM=false NTFS=false +PROGRESS=false get_flag "dry-run" && DRY_RUN=true get_flag "verbose" && VERBOSE=true get_flag "compress" && COMPRESS=true get_flag "system" && SYSTEM=true get_flag "ntfs" && NTFS=true +get_flag "progress" && PROGRESS=true # ---------------------------------------------------------------------------- # Required argument checks @@ -96,6 +109,18 @@ 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) # ---------------------------------------------------------------------------- @@ -152,8 +177,12 @@ if [[ "$NTFS" == false ]]; then fi [[ "$SYSTEM" == true ]] && CMD+=("-H") -CMD+=("-P") + +[[ "$PROGRESS" == true ]] && CMD+=("-P") +[[ "$PROGRESS" == false ]] && CMD+=("--partial") + CMD+=("--delete-excluded") + $VERBOSE && CMD+=("-v") $DRY_RUN && CMD+=("--dry-run") $COMPRESS && CMD+=("-z") @@ -213,13 +242,14 @@ else echo " └─ No Excludes Set" fi +echo +echo "Command : ${CMD[*]}" +read -rp "If correct press neter to continue..." echo echo "┌──────────────────────────────────────────┐" echo "│ Executing Rsync Process │" echo "└──────────────────────────────────────────┘" -echo "Command : ${CMD[*]}" echo - # Uncomment to execute "${CMD[@]}" echo