diff --git a/backup.sh b/backup.sh index 7f6de6c..3863fa8 100755 --- a/backup.sh +++ b/backup.sh @@ -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 @@ -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")")" diff --git a/restore.sh b/restore.sh index 4f3a28a..d51b528 100755 --- a/restore.sh +++ b/restore.sh @@ -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 @@ -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)) diff --git a/tests/create_backups.tests/remote_destination_host_only_single_backup_w_custom_port.test.sh b/tests/create_backups.tests/remote_destination_host_only_single_backup_w_custom_port.test.sh index 9b6f046..6f743e3 100755 --- a/tests/create_backups.tests/remote_destination_host_only_single_backup_w_custom_port.test.sh +++ b/tests/create_backups.tests/remote_destination_host_only_single_backup_w_custom_port.test.sh @@ -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 diff --git a/tests/create_backups.tests/remote_destination_single_backup_w_custom_port.test.sh b/tests/create_backups.tests/remote_destination_single_backup_w_custom_port.test.sh index 8bef04c..c81c2de 100755 --- a/tests/create_backups.tests/remote_destination_single_backup_w_custom_port.test.sh +++ b/tests/create_backups.tests/remote_destination_single_backup_w_custom_port.test.sh @@ -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 diff --git a/tests/restore_backups.tests/remote_destination_restore_w_custom_port.test.sh b/tests/restore_backups.tests/remote_destination_restore_w_custom_port.test.sh index f09d9c4..4c0b148 100755 --- a/tests/restore_backups.tests/remote_destination_restore_w_custom_port.test.sh +++ b/tests/restore_backups.tests/remote_destination_restore_w_custom_port.test.sh @@ -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:"