From 6c90d319cfc16ba514c7181fb9c9e0a8a104966c Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 27 Jun 2026 19:42:32 +0200 Subject: [PATCH] change rsync args to array --- src/backup | 60 +++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/src/backup b/src/backup index cc99894..a7900aa 100755 --- a/src/backup +++ b/src/backup @@ -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" ] \ -- 2.47.3