]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
fix restore with localhost
authorBastian Dehn <hhaalo@arcor.de>
Sat, 27 Jun 2026 18:26:12 +0000 (20:26 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 27 Jun 2026 18:26:43 +0000 (20:26 +0200)
src/restore

index 69877048c341cd68c27b4bce603bd2237799dbda..d2e46f838a5e95996e463041941682c700926a12 100755 (executable)
@@ -40,6 +40,12 @@ restore()
        local remote_user=
        local remote_machine=
        local remote_port=
+       local rsyncargs=("--archive" \
+               "--verbose" \
+               "--sparse" \
+               "--acls" \
+               "--hard-links" \
+               "--human-readable")
 
        backup_path=$(yq --raw-output ".backup_path" config.yaml)
        backup_name=$(yq --raw-output ".backup_name" config.yaml)
@@ -69,6 +75,7 @@ restore()
        [ "$remote_port" != "null" ] \
                || errlog "config.yaml missing port" \
                || return $?
+       rsyncargs+=("--rsh=\"ssh -p $remote_port\"")
 
        local backup_dir="$date"_"$number"_"$backup_name"
 
@@ -82,7 +89,9 @@ restore()
                || return $?
 
        local restore_path="$restore_prefix_path$path"
-       local remote_path="$remote_user@$remote_machine:$path"
+
+       local hostpath="$remote_user@$remote_machine:$path"
+       [ "$remote_machine" == "localhost" ] && local hostpath="$path"
 
        local mode="directory"
        [[ "$path" =~ /$ ]] || mode="file"
@@ -90,16 +99,18 @@ restore()
        [ -f "$restore_path" ] || [ -d "$restore_path" ] \
                || errlog "could not find $restore_path" \
                || return $?
+       rsyncargs+=("$restore_path")
+       rsyncargs+=("$hostpath")
 
        echo "ℹ️  INFO: restore mode $mode"
        echo
 
        echo "ℹ️  INFO: restore path $restore_path"
-       echo "ℹ️  INFO: remote path $remote_path"
+       echo "ℹ️  INFO: remote path $hostpath"
        echo
 
        [ "$origin" == "deletemode-on" ] \
-               && local deletemode="--delete" \
+               && rsyncargs+=("--delete") \
                && echo "⚠️  WARN: delete mode on" && echo
 
        local ask_restore="N"
@@ -114,16 +125,7 @@ restore()
 
        echo "ℹ️  INFO: restoring..."
 
-       rsync --archive \
-               --verbose \
-               --sparse \
-               --acls \
-               --hard-links \
-               --human-readable \
-               "$deletemode" \
-               --rsh "ssh -p $remote_port" \
-               "$restore_path" \
-               "$remote_path" \
+       rsync "${rsyncargs[@]}" \
                || errlog "could not restore" \
                || return $?