Skip to content

Commit

Permalink
Change rsync shell command
Browse files Browse the repository at this point in the history
The shell would ignore the quotes when parsing the rsync_port variable
this results in rsync not receiving he full rsh parameter like
--rsh="ssh -p port" instead it gets --rsh="ssh, -p and port", that is
three parameters and when rsync reads the parameter --rsh="ssh it
complains when there is no closing quote. In order to try to be posix
compliant we skip the variable in the script and uses an if branch
instead.
  • Loading branch information
christian-eriksson committed Jun 3, 2021
1 parent 5c08a58 commit 45d5b00
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
17 changes: 11 additions & 6 deletions backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ test_nonexistent_link "$latest_link" "$message" "$host" "$user" "$port"
[ ! -z $user ] && remote_prefix="$user@"
[ ! -z $host ] && remote_prefix="$remote_prefix$host:"

[ ! -z $port ] && rsync_port="--rsh='ssh -p$port'"

index=0
source_path="$(dequote_string "$(get_list_item "$source_paths" "$index")")"
while [ "$source_path" != "null" ]; do
Expand All @@ -77,10 +75,17 @@ while [ "$source_path" != "null" ]; do
[ -z "$dry_run" ] && create_directory "$destination" "$host" "$user" "$port"
source="$source_root/$source_suffix"

rsync -aE --progress --delete $dry_run $rsync_port \
--link-dest "$latest_link/$backup_path_suffix" \
"$source" \
"$remote_prefix$destination"
if [ -z "$port" ]; then
rsync -aE --progress --delete $dry_run \
--link-dest "$latest_link/$backup_path_suffix" \
"$source" \
"$remote_prefix$destination"
else
rsync -aE --progress --delete $dry_run --rsh="ssh -p $port" \
--link-dest "$latest_link/$backup_path_suffix" \
"$source" \
"$remote_prefix$destination"
fi

index=$((index + 1))
source_path="$(dequote_string "$(get_list_item "$source_paths" "$index")")"
Expand Down
14 changes: 10 additions & 4 deletions restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ restore_root=$(trim_right_slash "$restore_root")
[ ! -z $user ] && remote_prefix="$user@"
[ ! -z $host ] && remote_prefix="$remote_prefix$host:"

[ ! -z $port ] && rsync_port="--rsh='ssh -p$port'"

index=0
restore_path="$(dequote_string "$(get_list_item "$restore_paths" "$index")")"
while [ "$restore_path" != "null" ]; do
Expand All @@ -81,9 +79,17 @@ while [ "$restore_path" != "null" ]; do

if [ ! -z "$backup_copy_path" ]; then
restore_backup_dir="$backup_copy_path/$datetime_of_snapshot/$restore_path_suffix"
rsync -aE --progress $rsync_port --delete $dry_run --backup --backup-dir "$restore_backup_dir" "$source_path" "$target_dir"
if [ -z "$port" ]; then
rsync -aE --progress --delete $dry_run --backup --backup-dir "$restore_backup_dir" "$source_path" "$target_dir"
else
rsync -aE --progress --rsh="ssh -p $port" --delete $dry_run --backup --backup-dir "$restore_backup_dir" "$source_path" "$target_dir"
fi
else
rsync -aE --progress $rsync_port --delete $dry_run "$source_path" "$target_dir"
if [ -z "$port" ]; then
rsync -aE --progress --delete $dry_run "$source_path" "$target_dir"
else
rsync -aE --progress --rsh="ssh -p $port" --delete $dry_run "$source_path" "$target_dir"
fi
fi

index=$((index + 1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ exit_code="$?"
test_results="$exit_code"

# AND blubee prepends the remote user and host to the backup destination
remote_calls=$(echo "$output" | grep -e "rsync.*--rsh='ssh -p$port'.*$host:$backup_dir/$name/[0-9]\{8\}_[0-9]\{6\}" | wc -l)
remote_calls=$(echo "$output" | grep -e "rsync.*--rsh=ssh -p $port.*$host:$backup_dir/$name/[0-9]\{8\}_[0-9]\{6\}" | wc -l)
test_results="$test_results $(assert_equal_numbers $remote_calls 4)"

# AND blubee has created the expected folders for backup on the remote
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ exit_code="$?"
test_results="$exit_code"

# AND blubee prepends the remote user and host to the backup destination
remote_calls=$(echo "$output" | grep -e "rsync.*--rsh='ssh -p$port'.*$user@$host:$backup_dir/$name/[0-9]\{8\}_[0-9]\{6\}" | wc -l)
remote_calls=$(echo "$output" | grep -e "rsync.*--rsh=ssh -p $port.*$user@$host:$backup_dir/$name/[0-9]\{8\}_[0-9]\{6\}" | wc -l)
test_results="$test_results $(assert_equal_numbers $remote_calls 4)"

# AND blubee has created the expected folders for backup on the remote
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ remote_calls=$(echo "$output" | grep -e "ssh.*-p$port.*$user@$host.*mkdir " | wc
test_results="$test_results $(assert_greater_than $remote_calls 0)"

# THEN blubee sets custom port to the rsync command
remote_calls=$(echo "$output" | grep -e "--rsh='ssh -p$port'" | wc -l)
remote_calls=$(echo "$output" | grep -e "--rsh=ssh -p $port" | wc -l)
test_results="$test_results $(assert_equal_numbers $remote_calls 4)"

echo "remote_destination_restore.test.sh\nRESULTS:"
Expand Down

0 comments on commit 45d5b00

Please sign in to comment.