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" ] \
[ -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"
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 $?
{
local backup_path="$1"
local last_backup_dir_path="$2"
- local hardlinkopt=
local machines=
machines=$(yq --raw-output '.machines | keys[]' config.yaml)
[ -n "$machines" ] \