]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
change rsync args to array
authorBastian Dehn <hhaalo@arcor.de>
Sat, 27 Jun 2026 17:42:32 +0000 (19:42 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 27 Jun 2026 17:42:32 +0000 (19:42 +0200)
src/backup

index cc998947264fd10dba43a6963c357d681b619a17..a7900aa219db963bab05badb86c3d78f7a13f3c9 100755 (executable)
@@ -103,36 +103,24 @@ print_line()
        printf "\n"
 }
 
-get_machine_excludes()
-{
-       local machine="$1"
-       local excludes=
-       excludes=$(yq --raw-output ".machines.\"$machine\".excludes[]" \
-               config.yaml \
-               2> /dev/null)
-
-       [ "$excludes" == "null" ] && return
-       [ -z "$excludes" ] && return
-
-       local options=()
-       for exclude in $excludes; do
-               options+=("--exclude=$exclude")
-       done
-
-       echo "${options[@]}"
-}
-
 backup_remote_pathes()
 {
        local backup_path="$1"
        local machine="$2"
        local last_backup_dir_path="$3"
-       local hardlinkopt=
        local remote_user=
        local host=
        local port=
        local pathes=
        local excludes=
+       local rsyncargs=("--archive" \
+               "--verbose" \
+               "--sparse"
+               "--acls" \
+               "--hard-links" \
+               "--relative" \
+               "--human-readable")
+
        remote_user=$(yq \
                --raw-output ".machines.\"$machine\".remote_user" config.yaml)
        [ -n "$remote_user" ] && [ "$remote_user" != "null" ] \
@@ -150,7 +138,19 @@ backup_remote_pathes()
        [ -n "$pathes" ] \
                || errlog "config.yaml missing pathes for $machine" \
                || return $?
-       excludes=$(get_machine_excludes "$machine")
+       excludes=$(yq --raw-output ".machines.\"$machine\".excludes[]" \
+               config.yaml \
+               2> /dev/null)
+
+       if [ "$excludes" != "null" ]; then
+               local exclude=
+               for exclude in $excludes; do
+                       rsyncargs+=("--exclude=$exclude")
+               done
+       fi
+
+       rsyncargs+=("--rsh=\"ssh -p $port\"")
+       [ "${#excludes[@]}" -ne 0 ] && rsyncargs+=("${excludes[@]}")
 
        local YELLOW="\e[0;33m"
        local LIGHTPURPLE="\e[1;35m"
@@ -163,23 +163,14 @@ backup_remote_pathes()
                printf "path ${YELLOW}%s${RESET}\n\n" "$path"
 
                [ -n "$last_backup_dir_path" ] \
-                       && local hardlinkopt="--link-dest=$last_backup_dir_path/$machine"
+                       && rsyncargs+=("--link-dest=$last_backup_dir_path/$machine")
 
                local hostpath="$remote_user@$host:$path"
                [ "$host" == "localhost" ] && local hostpath="$path"
+               rsyncargs+=("$hostpath")
+               rsyncargs+=("$backup_path/$machine")
 
-               rsync --archive \
-                       --verbose \
-                       --sparse \
-                       --acls \
-                       --hard-links \
-                       --relative \
-                       --human-readable \
-                       "$excludes" \
-                       "$hardlinkopt" \
-                       --rsh "ssh -p $port" \
-                       "$hostpath" \
-                       "$backup_path/$machine" \
+               rsync "${rsyncargs[@]}" \
                        || errlog "could not backup $machine with path $path" \
                        || return $?
 
@@ -191,7 +182,6 @@ backup_remotes()
 {
        local backup_path="$1"
        local last_backup_dir_path="$2"
-       local hardlinkopt=
        local machines=
        machines=$(yq --raw-output '.machines | keys[]' config.yaml)
        [ -n "$machines" ] \