Blame SOURCES/rsync-output.patch

ec6e77
commit e6a9c973dbb7be6e46ed9a7fe34df0635635fed6
ec6e77
Author: Johannes Meixner <jsmeix@suse.com>
ec6e77
Date:   Tue Jul 12 13:59:28 2022 +0200
ec6e77
ec6e77
    Merge pull request #2831 from pcahyna/rsync-url-fix-refactor
ec6e77
    
ec6e77
    Refactor rsync URL support, fixes rsync OUTPUT_URL:
ec6e77
    The code to parse rsync:// URLs was BACKUP_URL specific.
ec6e77
    If one specified BACKUP=RSYNC and an OUTPUT_URL different from BACKUP_URL,
ec6e77
    the OUTPUT_URL was ignored and the output files went to BACKUP_URL.
ec6e77
    Fix by introducing generic functions for rsync URL parsing and
ec6e77
    use them for both BACKUP_URL and OUTPUT_URL, as appropriate.
ec6e77
    Replace all uses of global RSYNC_* variables derived
ec6e77
    from BACKUP_URL by those functions.
ec6e77
    There also was inconsistent special handling for OUTPUT=PXE which is now removed:
ec6e77
    An rsync OUTPUT_URL with OUTPUT=PXE now creates the RSYNC_PREFIX directory
ec6e77
    at the destination and the URL is interpreted as in all other cases.
ec6e77
    See https://github.com/rear/rear/pull/2831
ec6e77
    and https://github.com/rear/rear/issues/2781
ec6e77
ec6e77
diff --git a/usr/share/rear/backup/NETFS/default/200_check_rsync_relative_option.sh b/usr/share/rear/backup/NETFS/default/200_check_rsync_relative_option.sh
ec6e77
deleted file mode 120000
ec6e77
index 336b83f5..00000000
ec6e77
--- a/usr/share/rear/backup/NETFS/default/200_check_rsync_relative_option.sh
ec6e77
+++ /dev/null
ec6e77
@@ -1 +0,0 @@
ec6e77
-../../RSYNC/default/200_check_rsync_relative_option.sh
ec6e77
\ No newline at end of file
ec6e77
diff --git a/usr/share/rear/backup/NETFS/default/210_check_rsync_relative_option.sh b/usr/share/rear/backup/NETFS/default/210_check_rsync_relative_option.sh
ec6e77
new file mode 120000
ec6e77
index 00000000..0570eb44
ec6e77
--- /dev/null
ec6e77
+++ b/usr/share/rear/backup/NETFS/default/210_check_rsync_relative_option.sh
ec6e77
@@ -0,0 +1 @@
ec6e77
+../../RSYNC/default/210_check_rsync_relative_option.sh
ec6e77
\ No newline at end of file
ec6e77
diff --git a/usr/share/rear/backup/RSYNC/GNU/Linux/610_start_selinux.sh b/usr/share/rear/backup/RSYNC/GNU/Linux/610_start_selinux.sh
ec6e77
index 1692ba4c..dd198ede 100644
ec6e77
--- a/usr/share/rear/backup/RSYNC/GNU/Linux/610_start_selinux.sh
ec6e77
+++ b/usr/share/rear/backup/RSYNC/GNU/Linux/610_start_selinux.sh
ec6e77
@@ -6,29 +6,29 @@ local backup_prog_rc
ec6e77
 	touch "${TMP_DIR}/selinux.autorelabel"
ec6e77
 	cat $TMP_DIR/selinux.mode > $SELINUX_ENFORCE
ec6e77
 	Log "Restored original SELinux mode"
ec6e77
-	case $RSYNC_PROTO in
ec6e77
+	case $(rsync_proto "$BACKUP_URL") in
ec6e77
 
ec6e77
 	(ssh)
ec6e77
 		# for some reason rsync changes the mode of backup after each run to 666
ec6e77
                 # FIXME: Add an explanatory comment why "2>/dev/null" is useful here
ec6e77
                 # or remove it according to https://github.com/rear/rear/issues/1395
ec6e77
-		ssh $RSYNC_USER@$RSYNC_HOST "chmod $v 755 ${RSYNC_PATH}/${RSYNC_PREFIX}/backup" 2>/dev/null
ec6e77
+		ssh $(rsync_remote_ssh "$BACKUP_URL") "chmod $v 755 $(rsync_path_full "$BACKUP_URL")/backup" 2>/dev/null
ec6e77
 		$BACKUP_PROG -a "${TMP_DIR}/selinux.autorelabel" \
ec6e77
-		 "$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}/backup/.autorelabel" 2>/dev/null
ec6e77
+		 "$(rsync_remote_full "$BACKUP_URL")/backup/.autorelabel" 2>/dev/null
ec6e77
 		backup_prog_rc=$?
ec6e77
 		if [ $backup_prog_rc -ne 0 ]; then
ec6e77
-			LogPrint "Failed to create .autorelabel on ${RSYNC_PATH}/${RSYNC_PREFIX}/backup [${rsync_err_msg[$backup_prog_rc]}]"
ec6e77
-			#StopIfError "Failed to create .autorelabel on ${RSYNC_PATH}/${RSYNC_PREFIX}/backup"
ec6e77
+			LogPrint "Failed to create .autorelabel on $(rsync_path_full "$BACKUP_URL")/backup [${rsync_err_msg[$backup_prog_rc]}]"
ec6e77
+			#StopIfError "Failed to create .autorelabel on $(rsync_path_full "$BACKUP_URL")/backup"
ec6e77
 		fi
ec6e77
 		;;
ec6e77
 
ec6e77
 	(rsync)
ec6e77
 		$BACKUP_PROG -a "${TMP_DIR}/selinux.autorelabel" "${BACKUP_RSYNC_OPTIONS[@]}" \
ec6e77
-		 "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/backup/.autorelabel"
ec6e77
+		 "$(rsync_remote_full "$BACKUP_URL")/backup/.autorelabel"
ec6e77
 		backup_prog_rc=$?
ec6e77
 		if [ $backup_prog_rc -ne 0 ]; then
ec6e77
-			LogPrint "Failed to create .autorelabel on ${RSYNC_PATH}/${RSYNC_PREFIX}/backup [${rsync_err_msg[$backup_prog_rc]}]"
ec6e77
-			#StopIfError "Failed to create .autorelabel on ${RSYNC_PATH}/${RSYNC_PREFIX}/backup"
ec6e77
+			LogPrint "Failed to create .autorelabel on $(rsync_path_full "$BACKUP_URL")/backup [${rsync_err_msg[$backup_prog_rc]}]"
ec6e77
+			#StopIfError "Failed to create .autorelabel on $(rsync_path_full "$BACKUP_URL")/backup"
ec6e77
 		fi
ec6e77
 		;;
ec6e77
 
ec6e77
diff --git a/usr/share/rear/backup/RSYNC/GNU/Linux/620_force_autorelabel.sh b/usr/share/rear/backup/RSYNC/GNU/Linux/620_force_autorelabel.sh
ec6e77
index 9a17d6bb..de57d571 100644
ec6e77
--- a/usr/share/rear/backup/RSYNC/GNU/Linux/620_force_autorelabel.sh
ec6e77
+++ b/usr/share/rear/backup/RSYNC/GNU/Linux/620_force_autorelabel.sh
ec6e77
@@ -4,29 +4,29 @@ local backup_prog_rc
ec6e77
 
ec6e77
 	> "${TMP_DIR}/selinux.autorelabel"
ec6e77
 
ec6e77
-	case $RSYNC_PROTO in
ec6e77
+	case $(rsync_proto "$BACKUP_URL") in
ec6e77
 
ec6e77
 	(ssh)
ec6e77
 		# for some reason rsync changes the mode of backup after each run to 666
ec6e77
                 # FIXME: Add an explanatory comment why "2>/dev/null" is useful here
ec6e77
                 # or remove it according to https://github.com/rear/rear/issues/1395
ec6e77
-		ssh $RSYNC_USER@$RSYNC_HOST "chmod $v 755 ${RSYNC_PATH}/${RSYNC_PREFIX}/backup" 2>/dev/null
ec6e77
+		ssh $(rsync_remote_ssh "$BACKUP_URL") "chmod $v 755 $(rsync_path_full "$BACKUP_URL")/backup" 2>/dev/null
ec6e77
 		$BACKUP_PROG -a "${TMP_DIR}/selinux.autorelabel" \
ec6e77
-		 "$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}/backup/.autorelabel" 2>/dev/null
ec6e77
+		 "$(rsync_remote_full "$BACKUP_URL")/backup/.autorelabel" 2>/dev/null
ec6e77
 		backup_prog_rc=$?
ec6e77
 		if [ $backup_prog_rc -ne 0 ]; then
ec6e77
-			LogPrint "Failed to create .autorelabel on ${RSYNC_PATH}/${RSYNC_PREFIX}/backup [${rsync_err_msg[$backup_prog_rc]}]"
ec6e77
-			#StopIfError "Failed to create .autorelabel on ${RSYNC_PATH}/${RSYNC_PREFIX}/backup"
ec6e77
+			LogPrint "Failed to create .autorelabel on $(rsync_path_full "$BACKUP_URL")/backup [${rsync_err_msg[$backup_prog_rc]}]"
ec6e77
+			#StopIfError "Failed to create .autorelabel on $(rsync_path_full "$BACKUP_URL")/backup"
ec6e77
 		fi
ec6e77
 		;;
ec6e77
 
ec6e77
 	(rsync)
ec6e77
 		$BACKUP_PROG -a "${TMP_DIR}/selinux.autorelabel" "${BACKUP_RSYNC_OPTIONS[@]}" \
ec6e77
-		 "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/backup/.autorelabel"
ec6e77
+		 "$(rsync_remote_full "$BACKUP_URL")/backup/.autorelabel"
ec6e77
 		backup_prog_rc=$?
ec6e77
 		if [ $backup_prog_rc -ne 0 ]; then
ec6e77
-			LogPrint "Failed to create .autorelabel on ${RSYNC_PATH}/${RSYNC_PREFIX}/backup [${rsync_err_msg[$backup_prog_rc]}]"
ec6e77
-			#StopIfError "Failed to create .autorelabel on ${RSYNC_PATH}/${RSYNC_PREFIX}/backup"
ec6e77
+			LogPrint "Failed to create .autorelabel on $(rsync_path_full "$BACKUP_URL")/backup [${rsync_err_msg[$backup_prog_rc]}]"
ec6e77
+			#StopIfError "Failed to create .autorelabel on $(rsync_path_full "$BACKUP_URL")/backup"
ec6e77
 		fi
ec6e77
 		;;
ec6e77
 
ec6e77
diff --git a/usr/share/rear/backup/RSYNC/default/200_make_prefix_dir.sh b/usr/share/rear/backup/RSYNC/default/200_make_prefix_dir.sh
ec6e77
new file mode 100644
ec6e77
index 00000000..81aa6879
ec6e77
--- /dev/null
ec6e77
+++ b/usr/share/rear/backup/RSYNC/default/200_make_prefix_dir.sh
ec6e77
@@ -0,0 +1,28 @@
ec6e77
+# Create RSYNC_PREFIX/backup on remote rsync server
ec6e77
+# RSYNC_PREFIX=$HOSTNAME as set in default.conf
ec6e77
+
ec6e77
+local proto host
ec6e77
+
ec6e77
+proto="$(rsync_proto "$BACKUP_URL")"
ec6e77
+host="$(rsync_host "$BACKUP_URL")"
ec6e77
+
ec6e77
+mkdir -p $v -m0750 "${TMP_DIR}/rsync/${RSYNC_PREFIX}" >&2 || Error "Could not mkdir '${TMP_DIR}/rsync/${RSYNC_PREFIX}'"
ec6e77
+mkdir -p $v -m0755 "${TMP_DIR}/rsync/${RSYNC_PREFIX}/backup" >&2 || Error "Could not mkdir '${TMP_DIR}/rsync/${RSYNC_PREFIX}/backup'"
ec6e77
+
ec6e77
+case $proto in
ec6e77
+
ec6e77
+	(ssh)
ec6e77
+		$BACKUP_PROG -a $v -r "${TMP_DIR}/rsync/${RSYNC_PREFIX}" "$(rsync_remote "$BACKUP_URL")" >/dev/null 2>&1 \
ec6e77
+                    || Error "Could not create '$(rsync_path_full "$BACKUP_URL")' on remote ${host}"
ec6e77
+		;;
ec6e77
+
ec6e77
+	(rsync)
ec6e77
+		$BACKUP_PROG -a $v -r "${TMP_DIR}/rsync/${RSYNC_PREFIX}" "${BACKUP_RSYNC_OPTIONS[@]}" "$(rsync_remote "$BACKUP_URL")/" >/dev/null \
ec6e77
+                    || Error "Could not create '$(rsync_path_full "$BACKUP_URL")' on remote ${host}"
ec6e77
+		;;
ec6e77
+
ec6e77
+esac
ec6e77
+
ec6e77
+# We don't need it anymore, from now we operate on the remote copy
ec6e77
+rmdir $v "${TMP_DIR}/rsync/${RSYNC_PREFIX}/backup"
ec6e77
+rmdir $v "${TMP_DIR}/rsync/${RSYNC_PREFIX}"
ec6e77
diff --git a/usr/share/rear/backup/RSYNC/default/200_check_rsync_relative_option.sh b/usr/share/rear/backup/RSYNC/default/210_check_rsync_relative_option.sh
ec6e77
similarity index 91%
ec6e77
rename from usr/share/rear/backup/RSYNC/default/200_check_rsync_relative_option.sh
ec6e77
rename to usr/share/rear/backup/RSYNC/default/210_check_rsync_relative_option.sh
ec6e77
index cedee9ce..692616b7 100644
ec6e77
--- a/usr/share/rear/backup/RSYNC/default/200_check_rsync_relative_option.sh
ec6e77
+++ b/usr/share/rear/backup/RSYNC/default/210_check_rsync_relative_option.sh
ec6e77
@@ -1,4 +1,4 @@
ec6e77
-# 200_check_rsync_relative_option.sh
ec6e77
+# 210_check_rsync_relative_option.sh
ec6e77
 # See issue #871 for details
ec6e77
 
ec6e77
 # check for the --relative option in BACKUP_RSYNC_OPTIONS array
ec6e77
diff --git a/usr/share/rear/backup/RSYNC/default/450_calculate_req_space.sh b/usr/share/rear/backup/RSYNC/default/450_calculate_req_space.sh
ec6e77
index eb99dbf6..037e49c0 100644
ec6e77
--- a/usr/share/rear/backup/RSYNC/default/450_calculate_req_space.sh
ec6e77
+++ b/usr/share/rear/backup/RSYNC/default/450_calculate_req_space.sh
ec6e77
@@ -1,6 +1,12 @@
ec6e77
 # here we will calculate the space required to hold the backup archive on the remote rsync system
ec6e77
 # This file is part of Relax-and-Recover, licensed under the GNU General
ec6e77
 # Public License. Refer to the included COPYING for full text of license.
ec6e77
+local proto host path
ec6e77
+
ec6e77
+proto="$(rsync_proto "$BACKUP_URL")"
ec6e77
+host="$(rsync_host "$BACKUP_URL")"
ec6e77
+path="$(rsync_path "$BACKUP_URL")"
ec6e77
+
ec6e77
 _local_size=0
ec6e77
 _remote_size=0
ec6e77
 while read -r ; do
ec6e77
@@ -13,17 +19,17 @@ while read -r ; do
ec6e77
 done < $TMP_DIR/backup-include.txt
ec6e77
 LogPrint "Estimated size of local file systems is $(( _local_size / 1024 )) MB"
ec6e77
 
ec6e77
-case $RSYNC_PROTO in
ec6e77
+case $proto in
ec6e77
     (ssh)
ec6e77
-        LogPrint "Calculating size of $RSYNC_HOST:$RSYNC_PATH"
ec6e77
-        ssh -l $RSYNC_USER $RSYNC_HOST "df -P $RSYNC_PATH" >$TMP_DIR/rs_size
ec6e77
-        StopIfError "Failed to determine size of $RSYNC_PATH"
ec6e77
+        LogPrint "Calculating size of ${host}:${path}"
ec6e77
+        ssh $(rsync_remote_ssh "$BACKUP_URL") "df -P ${path}" >$TMP_DIR/rs_size
ec6e77
+        StopIfError "Failed to determine size of ${path}"
ec6e77
         _div=1 # 1024-blocks
ec6e77
         grep -q "512-blocks" $TMP_DIR/rs_size && _div=2 # HPUX: divide with 2 to get kB size
ec6e77
         _remote_size=$( tail -n 1 $TMP_DIR/rs_size | awk '{print $2}' )
ec6e77
         _remote_size=$(( _remote_size / _div ))
ec6e77
         [[ $_remote_size -gt $_local_size ]]
ec6e77
-        StopIfError "Not enough disk space available on $RSYNC_HOST:$RSYNC_PATH ($_remote_size < $_local_size)"
ec6e77
+        StopIfError "Not enough disk space available on ${host}:${path} ($_remote_size < $_local_size)"
ec6e77
         ;;
ec6e77
     (rsync)
ec6e77
         # TODO: how can we calculate the free size on remote system via rsync protocol??
ec6e77
diff --git a/usr/share/rear/backup/RSYNC/default/500_make_rsync_backup.sh b/usr/share/rear/backup/RSYNC/default/500_make_rsync_backup.sh
ec6e77
index 750a04ca..aa8192c0 100644
ec6e77
--- a/usr/share/rear/backup/RSYNC/default/500_make_rsync_backup.sh
ec6e77
+++ b/usr/share/rear/backup/RSYNC/default/500_make_rsync_backup.sh
ec6e77
@@ -5,6 +5,11 @@
ec6e77
 local backup_prog_rc
ec6e77
 local backup_log_message
ec6e77
 
ec6e77
+local host path
ec6e77
+
ec6e77
+host="$(rsync_host "$BACKUP_URL")"
ec6e77
+path="$(rsync_path "$BACKUP_URL")"
ec6e77
+
ec6e77
 Log "Include list:"
ec6e77
 while read -r ; do
ec6e77
 	Log "  $REPLY"
ec6e77
@@ -14,26 +19,27 @@ while read -r ; do
ec6e77
 	Log " $REPLY"
ec6e77
 done < $TMP_DIR/backup-exclude.txt
ec6e77
 
ec6e77
-LogPrint "Creating $BACKUP_PROG backup on '${RSYNC_HOST}:${RSYNC_PATH}'"
ec6e77
+LogPrint "Creating $BACKUP_PROG backup on '${host}:${path}'"
ec6e77
 
ec6e77
 ProgressStart "Running backup operation"
ec6e77
 (
ec6e77
 	case "$(basename $BACKUP_PROG)" in
ec6e77
 
ec6e77
 		(rsync)
ec6e77
+			# We are in a subshell, so this change will not propagate to later scripts
ec6e77
 			BACKUP_RSYNC_OPTIONS+=( --one-file-system --delete --exclude-from=$TMP_DIR/backup-exclude.txt --delete-excluded )
ec6e77
 
ec6e77
-			case $RSYNC_PROTO in
ec6e77
+			case $(rsync_proto "$BACKUP_URL") in
ec6e77
 
ec6e77
 				(ssh)
ec6e77
-					Log $BACKUP_PROG "${BACKUP_RSYNC_OPTIONS[@]}" $(cat $TMP_DIR/backup-include.txt) "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/backup"
ec6e77
+					Log $BACKUP_PROG "${BACKUP_RSYNC_OPTIONS[@]}" $(cat $TMP_DIR/backup-include.txt) "$(rsync_remote_full "$BACKUP_URL")/backup"
ec6e77
 					$BACKUP_PROG "${BACKUP_RSYNC_OPTIONS[@]}" $(cat $TMP_DIR/backup-include.txt) \
ec6e77
-					"${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/backup"
ec6e77
+					"$(rsync_remote_full "$BACKUP_URL")/backup"
ec6e77
 					;;
ec6e77
 
ec6e77
 				(rsync)
ec6e77
 					$BACKUP_PROG "${BACKUP_RSYNC_OPTIONS[@]}" $(cat $TMP_DIR/backup-include.txt) \
ec6e77
-					"${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/backup"
ec6e77
+					"$(rsync_remote_full "$BACKUP_URL")/backup"
ec6e77
 					;;
ec6e77
 
ec6e77
 			esac
ec6e77
@@ -57,11 +63,11 @@ get_size() {
ec6e77
 }
ec6e77
 
ec6e77
 check_remote_df() {
ec6e77
-	echo $(ssh ${RSYNC_USER}@${RSYNC_HOST} df -P ${RSYNC_PATH} 2>/dev/null | tail -1 | awk '{print $5}' | sed -e 's/%//')
ec6e77
+	echo $(ssh $(rsync_remote_ssh "$BACKUP_URL") df -P ${path} 2>/dev/null | tail -1 | awk '{print $5}' | sed -e 's/%//')
ec6e77
 }
ec6e77
 
ec6e77
 check_remote_du() {
ec6e77
-	x=$(ssh ${RSYNC_USER}@${RSYNC_HOST} du -sb ${RSYNC_PATH}/${RSYNC_PREFIX}/backup 2>/dev/null | awk '{print $1}')
ec6e77
+	x=$(ssh $(rsync_remote_ssh "$BACKUP_URL") du -sb $(rsync_path_full "$BACKUP_URL")/backup 2>/dev/null | awk '{print $1}')
ec6e77
 	[[ -z "${x}" ]] && x=0
ec6e77
 	echo $x
ec6e77
 }
ec6e77
@@ -81,7 +87,7 @@ case "$(basename $BACKUP_PROG)" in
ec6e77
 			case $i in
ec6e77
 
ec6e77
 			300)
ec6e77
-			[[ $(check_remote_df) -eq 100 ]] && Error "Disk is full on system ${RSYNC_HOST}"
ec6e77
+			[[ $(check_remote_df) -eq 100 ]] && Error "Disk is full on system ${host}"
ec6e77
 			;;
ec6e77
 
ec6e77
 			15|30|45|60|75|90|105|120|135|150|165|180|195|210|225|240|255|270|285)
ec6e77
diff --git a/usr/share/rear/backup/RSYNC/default/700_copy_backup_log.sh b/usr/share/rear/backup/RSYNC/default/700_copy_backup_log.sh
ec6e77
index b90d459b..76b9f971 100644
ec6e77
--- a/usr/share/rear/backup/RSYNC/default/700_copy_backup_log.sh
ec6e77
+++ b/usr/share/rear/backup/RSYNC/default/700_copy_backup_log.sh
ec6e77
@@ -1,26 +1,27 @@
ec6e77
 
ec6e77
 # copy the backup.log & rear.log file to remote destination with timestamp added
ec6e77
-local timestamp
ec6e77
+local timestamp proto
ec6e77
 
ec6e77
 timestamp=$( date +%Y%m%d.%H%M )
ec6e77
+proto="$(rsync_proto "$BACKUP_URL")"
ec6e77
 
ec6e77
 # compress the log file first
ec6e77
 gzip "$TMP_DIR/$BACKUP_PROG_ARCHIVE.log" || Error "Failed to 'gzip $TMP_DIR/$BACKUP_PROG_ARCHIVE.log'"
ec6e77
 
ec6e77
-case $RSYNC_PROTO in
ec6e77
+case $proto in
ec6e77
     (ssh)
ec6e77
         # FIXME: Add an explanatory comment why "2>/dev/null" is useful here
ec6e77
         # or remove it according to https://github.com/rear/rear/issues/1395
ec6e77
         $BACKUP_PROG -a "${TMP_DIR}/${BACKUP_PROG_ARCHIVE}.log.gz" \
ec6e77
-        "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/${BACKUP_PROG_ARCHIVE}-${timestamp}.log.gz" 2>/dev/null
ec6e77
+        "$(rsync_remote_full "$BACKUP_URL")/${BACKUP_PROG_ARCHIVE}-${timestamp}.log.gz" 2>/dev/null
ec6e77
 
ec6e77
-        $BACKUP_PROG -a "$RUNTIME_LOGFILE" "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/rear-${timestamp}.log" 2>/dev/null
ec6e77
+        $BACKUP_PROG -a "$RUNTIME_LOGFILE" "$(rsync_remote_full "$BACKUP_URL")/rear-${timestamp}.log" 2>/dev/null
ec6e77
         ;;
ec6e77
     (rsync)
ec6e77
         $BACKUP_PROG -a "${TMP_DIR}/${BACKUP_PROG_ARCHIVE}.log.gz" "${BACKUP_RSYNC_OPTIONS[@]}" \
ec6e77
-        "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/${BACKUP_PROG_ARCHIVE}-${timestamp}.log.gz"
ec6e77
+        "$(rsync_remote_full "$BACKUP_URL")/${BACKUP_PROG_ARCHIVE}-${timestamp}.log.gz"
ec6e77
 
ec6e77
-        $BACKUP_PROG -a "$RUNTIME_LOGFILE" "${BACKUP_RSYNC_OPTIONS[@]}" "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}//rear-${timestamp}.log"
ec6e77
+        $BACKUP_PROG -a "$RUNTIME_LOGFILE" "${BACKUP_RSYNC_OPTIONS[@]}" "$(rsync_remote_full "$BACKUP_URL")//rear-${timestamp}.log"
ec6e77
         ;;
ec6e77
 esac
ec6e77
 
ec6e77
diff --git a/usr/share/rear/lib/global-functions.sh b/usr/share/rear/lib/global-functions.sh
ec6e77
index 32aeb8ca..2edb64a6 100644
ec6e77
--- a/usr/share/rear/lib/global-functions.sh
ec6e77
+++ b/usr/share/rear/lib/global-functions.sh
ec6e77
@@ -259,7 +259,7 @@ function url_scheme() {
ec6e77
     # the scheme is the leading part up to '://'
ec6e77
     local scheme=${url%%://*}
ec6e77
     # rsync scheme does not have to start with rsync:// it can also be scp style
ec6e77
-    # see the comments in usr/share/rear/prep/RSYNC/default/100_check_rsync.sh
ec6e77
+    # see the comments in usr/share/rear/lib/rsync-functions.sh
ec6e77
     echo $scheme | grep -q ":" && echo rsync || echo $scheme
ec6e77
 }
ec6e77
 
ec6e77
diff --git a/usr/share/rear/lib/rsync-functions.sh b/usr/share/rear/lib/rsync-functions.sh
ec6e77
new file mode 100644
ec6e77
index 00000000..443a9625
ec6e77
--- /dev/null
ec6e77
+++ b/usr/share/rear/lib/rsync-functions.sh
ec6e77
@@ -0,0 +1,178 @@
ec6e77
+# Functions for manipulation of rsync URLs (both OUTPUT_URL and BACKUP_URL)
ec6e77
+
ec6e77
+#### OLD STYLE:
ec6e77
+# BACKUP_URL=[USER@]HOST:PATH           # using ssh (no rsh)
ec6e77
+#
ec6e77
+# with rsync protocol PATH is a MODULE name defined in remote /etc/rsyncd.conf file
ec6e77
+# BACKUP_URL=[USER@]HOST::PATH          # using rsync
ec6e77
+# BACKUP_URL=rsync://[USER@]HOST[:PORT]/PATH    # using rsync (is not compatible with new style!!!)
ec6e77
+
ec6e77
+#### NEW STYLE:
ec6e77
+# BACKUP_URL=rsync://[USER@]HOST[:PORT]/PATH    # using ssh
ec6e77
+# BACKUP_URL=rsync://[USER@]HOST[:PORT]::/PATH  # using rsync
ec6e77
+
ec6e77
+function rsync_validate () {
ec6e77
+    local url="$1"
ec6e77
+
ec6e77
+    if [[ "$(url_scheme "$url")" != "rsync" ]]; then # url_scheme still recognizes old style
ec6e77
+        BugError "Non-rsync URL $url !"
ec6e77
+    fi
ec6e77
+}
ec6e77
+
ec6e77
+# Determine whether the URL specifies the use of the rsync protocol (rsyncd) or ssh
ec6e77
+# Do not call on non-rsync URLs (use url_scheme first)
ec6e77
+function rsync_proto () {
ec6e77
+    local url="$1"
ec6e77
+
ec6e77
+    rsync_validate "$url"
ec6e77
+    if egrep -q '(::)' <<< $url ; then # new style '::' means rsync protocol
ec6e77
+        echo rsync
ec6e77
+    else
ec6e77
+        echo ssh
ec6e77
+    fi
ec6e77
+}
ec6e77
+
ec6e77
+# Functions to parse the URL into its components:
ec6e77
+# USER, HOST, PORT, PATH
ec6e77
+
ec6e77
+function rsync_user () {
ec6e77
+    local url="$1"
ec6e77
+    local host
ec6e77
+
ec6e77
+    host=$(url_host "$url")
ec6e77
+
ec6e77
+    if grep -q '@' <<< $host ; then
ec6e77
+        echo "${host%%@*}"    # grab user name
ec6e77
+    else
ec6e77
+        echo root
ec6e77
+    fi
ec6e77
+}
ec6e77
+
ec6e77
+function rsync_host () {
ec6e77
+    local url="$1"
ec6e77
+    local host
ec6e77
+    local path
ec6e77
+
ec6e77
+    host=$(url_host "$url")
ec6e77
+    path=$(url_path "$url")
ec6e77
+    # remove USER@ if present
ec6e77
+    local tmp2="${host#*@}"
ec6e77
+
ec6e77
+    case "$(rsync_proto "$url")" in
ec6e77
+        (rsync)
ec6e77
+            # tmp2=witsbebelnx02::backup or tmp2=witsbebelnx02::
ec6e77
+            echo "${tmp2%%::*}"
ec6e77
+            ;;
ec6e77
+        (ssh)
ec6e77
+            # tmp2=host or tmp2=host:
ec6e77
+            echo "${tmp2%%:*}"
ec6e77
+            ;;
ec6e77
+    esac
ec6e77
+}
ec6e77
+
ec6e77
+function rsync_path () {
ec6e77
+    local url="$1"
ec6e77
+    local host
ec6e77
+    local path
ec6e77
+    local url_without_scheme
ec6e77
+    local url_without_scheme_user
ec6e77
+
ec6e77
+    host=$(url_host "$url")
ec6e77
+    path=$(url_path "$url")
ec6e77
+    local tmp2="${host#*@}"
ec6e77
+
ec6e77
+    url_without_scheme="${url#*//}"
ec6e77
+    url_without_scheme_user="${url_without_scheme#$(rsync_user "$url")@}"
ec6e77
+
ec6e77
+    case "$(rsync_proto "$url")" in
ec6e77
+
ec6e77
+        (rsync)
ec6e77
+            if grep -q '::' <<< $url_without_scheme_user ; then
ec6e77
+                # we can not use url_path here, it uses / as separator, not ::
ec6e77
+                local url_after_separator="${url_without_scheme_user##*::}"
ec6e77
+                # remove leading / - this is a module name
ec6e77
+                echo "${url_after_separator#/}"
ec6e77
+            else
ec6e77
+                echo "${path#*/}"
ec6e77
+            fi
ec6e77
+            ;;
ec6e77
+        (ssh)
ec6e77
+            if [ "$url_without_scheme" == "$url" ]; then
ec6e77
+                # no scheme - old-style URL
ec6e77
+                if grep -q ':' <<< $url_without_scheme_user ; then
ec6e77
+                    echo "${url_without_scheme_user##*:}"
ec6e77
+                else
ec6e77
+                    BugError "Old-style rsync URL $url without : !"
ec6e77
+                fi
ec6e77
+            else
ec6e77
+                echo "$path"
ec6e77
+            fi
ec6e77
+            ;;
ec6e77
+
ec6e77
+    esac
ec6e77
+}
ec6e77
+
ec6e77
+function rsync_port () {
ec6e77
+    # XXX changing port not implemented yet
ec6e77
+    echo 873
ec6e77
+}
ec6e77
+
ec6e77
+# Full path to the destination directory on the remote server,
ec6e77
+# includes RSYNC_PREFIX. RSYNC_PREFIX is not given by the URL,
ec6e77
+# it is a global parameter (by default derived from hostname).
ec6e77
+function rsync_path_full () {
ec6e77
+    local url="$1"
ec6e77
+
ec6e77
+    echo "$(rsync_path "$url")/${RSYNC_PREFIX}"
ec6e77
+}
ec6e77
+
ec6e77
+# Argument for the ssh command to log in to the remote host ("user@host")
ec6e77
+function rsync_remote_ssh () {
ec6e77
+    local url="$1"
ec6e77
+
ec6e77
+    local user host
ec6e77
+
ec6e77
+    user="$(rsync_user "$url")"
ec6e77
+    host="$(rsync_host "$url")"
ec6e77
+
ec6e77
+    echo "${user}@${host}"
ec6e77
+}
ec6e77
+
ec6e77
+# Argument for the rsync command to reach the remote host, without path.
ec6e77
+function rsync_remote_base () {
ec6e77
+    local url="$1"
ec6e77
+
ec6e77
+    local user host port
ec6e77
+
ec6e77
+    user="$(rsync_user "$url")"
ec6e77
+    host="$(rsync_host "$url")"
ec6e77
+    port="$(rsync_port "$url")"
ec6e77
+
ec6e77
+    case "$(rsync_proto "$url")" in
ec6e77
+
ec6e77
+        (rsync)
ec6e77
+            echo "rsync://${user}@${host}:${port}/"
ec6e77
+            ;;
ec6e77
+        (ssh)
ec6e77
+            echo "$(rsync_remote_ssh "$url"):"
ec6e77
+            ;;
ec6e77
+
ec6e77
+    esac
ec6e77
+}
ec6e77
+
ec6e77
+# Complete argument to rsync to reach the remote location identified by URL,
ec6e77
+# but without the added RSYNC_PREFIX.
ec6e77
+# This essentially converts our rsync:// URLs into a form accepted by the rsync command.
ec6e77
+function rsync_remote () {
ec6e77
+    local url="$1"
ec6e77
+
ec6e77
+    echo "$(rsync_remote_base "$url")$(rsync_path "$url")"
ec6e77
+}
ec6e77
+
ec6e77
+# Complete argument to rsync including even RSYNC_PREFIX.
ec6e77
+# Determined from the URL and RSYNC_PREFIX.
ec6e77
+function rsync_remote_full () {
ec6e77
+    local url="$1"
ec6e77
+
ec6e77
+    echo "$(rsync_remote_base "$url")$(rsync_path_full "$url")"
ec6e77
+}
ec6e77
diff --git a/usr/share/rear/output/RSYNC/default/200_make_prefix_dir.sh b/usr/share/rear/output/RSYNC/default/200_make_prefix_dir.sh
ec6e77
index 519febf5..d00d15e4 100644
ec6e77
--- a/usr/share/rear/output/RSYNC/default/200_make_prefix_dir.sh
ec6e77
+++ b/usr/share/rear/output/RSYNC/default/200_make_prefix_dir.sh
ec6e77
@@ -1,20 +1,32 @@
ec6e77
 # Create RSYNC_PREFIX under the local TMP_DIR and also on remote rsync server
ec6e77
 # RSYNC_PREFIX=$HOSTNAME as set in default.conf
ec6e77
 
ec6e77
-# create temporary local work-spaces to collect files (we already make the remote backup dir with the correct mode!!)
ec6e77
+local proto host scheme
ec6e77
+
ec6e77
+scheme="$(url_scheme "$OUTPUT_URL")"
ec6e77
+
ec6e77
+# we handle only rsync:// output schemes.
ec6e77
+# ToDo: why does handling of the output URL scheme belong under RSYNC (which is a backup method)?
ec6e77
+# OUTPUT_URL is independent on the chosen backup method, so this code should be moved to be backup-independent.
ec6e77
+test "rsync" = "$scheme" || return 0
ec6e77
+
ec6e77
+proto="$(rsync_proto "$OUTPUT_URL")"
ec6e77
+host="$(rsync_host "$OUTPUT_URL")"
ec6e77
+
ec6e77
+# create temporary local work-spaces to collect files
ec6e77
 mkdir -p $v -m0750 "${TMP_DIR}/rsync/${RSYNC_PREFIX}" >&2 || Error "Could not mkdir '${TMP_DIR}/rsync/${RSYNC_PREFIX}'"
ec6e77
-mkdir -p $v -m0755 "${TMP_DIR}/rsync/${RSYNC_PREFIX}/backup" >&2 || Error "Could not mkdir '${TMP_DIR}/rsync/${RSYNC_PREFIX}/backup'"
ec6e77
 
ec6e77
-case $RSYNC_PROTO in
ec6e77
+case $proto in
ec6e77
 
ec6e77
 	(ssh)
ec6e77
-		$BACKUP_PROG -a $v -r "${TMP_DIR}/rsync/${RSYNC_PREFIX}" "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}" >/dev/null 2>&1 \
ec6e77
-                    || Error "Could not create '${RSYNC_PATH}/${RSYNC_PREFIX}' on remote ${RSYNC_HOST}"
ec6e77
+		$BACKUP_PROG -a $v -r "${TMP_DIR}/rsync/${RSYNC_PREFIX}" "$(rsync_remote "$OUTPUT_URL")" >/dev/null 2>&1 \
ec6e77
+                    || Error "Could not create '$(rsync_path_full "$OUTPUT_URL")' on remote ${host}"
ec6e77
 		;;
ec6e77
 
ec6e77
 	(rsync)
ec6e77
-		$BACKUP_PROG -a $v -r "${TMP_DIR}/rsync/${RSYNC_PREFIX}" "${BACKUP_RSYNC_OPTIONS[@]}" "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/" >/dev/null \
ec6e77
-                    || Error "Could not create '${RSYNC_PATH}/${RSYNC_PREFIX}' on remote ${RSYNC_HOST}"
ec6e77
+		# This must run before the backup stage. Otherwise --relative gets added to BACKUP_RSYNC_OPTIONS
ec6e77
+		$BACKUP_PROG -a $v -r "${TMP_DIR}/rsync/${RSYNC_PREFIX}" "${BACKUP_RSYNC_OPTIONS[@]}" "$(rsync_remote "$OUTPUT_URL")/" >/dev/null \
ec6e77
+                    || Error "Could not create '$(rsync_path_full "$OUTPUT_URL")' on remote ${host}"
ec6e77
 		;;
ec6e77
 
ec6e77
 esac
ec6e77
diff --git a/usr/share/rear/output/RSYNC/default/900_copy_result_files.sh b/usr/share/rear/output/RSYNC/default/900_copy_result_files.sh
ec6e77
index 96b62da1..4ddf3cb4 100644
ec6e77
--- a/usr/share/rear/output/RSYNC/default/900_copy_result_files.sh
ec6e77
+++ b/usr/share/rear/output/RSYNC/default/900_copy_result_files.sh
ec6e77
@@ -1,6 +1,17 @@
ec6e77
 #
ec6e77
 # copy resulting files to remote network (backup) location
ec6e77
 
ec6e77
+local proto scheme
ec6e77
+
ec6e77
+scheme="$(url_scheme "$OUTPUT_URL")"
ec6e77
+
ec6e77
+# we handle only rsync:// output schemes.
ec6e77
+# ToDo: why does handling of the output URL scheme belong under RSYNC (which is a backup method)?
ec6e77
+# OUTPUT_URL is independent on the chosen backup method, so this code should be moved to be backup-independent.
ec6e77
+test "rsync" = "$scheme" || return 0
ec6e77
+
ec6e77
+proto="$(rsync_proto "$OUTPUT_URL")"
ec6e77
+
ec6e77
 LogPrint "Copying resulting files to $OUTPUT_URL location"
ec6e77
 
ec6e77
 # if called as mkbackuponly then we just don't have any result files.
ec6e77
@@ -19,21 +30,21 @@ cp $v $(get_template "RESULT_usage_$OUTPUT.txt") "${TMP_DIR}/rsync/${RSYNC_PREFI
ec6e77
 cat "$RUNTIME_LOGFILE" >"${TMP_DIR}/rsync/${RSYNC_PREFIX}/rear.log" \
ec6e77
     || Error "Could not copy $RUNTIME_LOGFILE to local rsync location"
ec6e77
 
ec6e77
-case $RSYNC_PROTO in
ec6e77
+case $proto in
ec6e77
 
ec6e77
     (ssh)
ec6e77
-    Log "$BACKUP_PROG -a ${TMP_DIR}/rsync/${RSYNC_PREFIX}/ ${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/"
ec6e77
+    Log "$BACKUP_PROG -a ${TMP_DIR}/rsync/${RSYNC_PREFIX}/ $(rsync_remote_full "$OUTPUT_URL")/"
ec6e77
     # FIXME: Add an explanatory comment why "2>/dev/null" is useful here
ec6e77
     # or remove it according to https://github.com/rear/rear/issues/1395
ec6e77
-    $BACKUP_PROG -a "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/" 2>/dev/null \
ec6e77
+    $BACKUP_PROG -a "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" "$(rsync_remote_full "$OUTPUT_URL")/" 2>/dev/null \
ec6e77
         || Error "Could not copy '${RESULT_FILES[*]}' to $OUTPUT_URL location"
ec6e77
     ;;
ec6e77
 
ec6e77
     (rsync)
ec6e77
-    Log "$BACKUP_PROG -a ${TMP_DIR}/rsync/${RSYNC_PREFIX}/ ${BACKUP_RSYNC_OPTIONS[*]} ${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/"
ec6e77
+    Log "$BACKUP_PROG -a ${TMP_DIR}/rsync/${RSYNC_PREFIX}/ ${BACKUP_RSYNC_OPTIONS[*]} $(rsync_remote_full "$OUTPUT_URL")/"
ec6e77
     # FIXME: Add an explanatory comment why "2>/dev/null" is useful here
ec6e77
     # or remove it according to https://github.com/rear/rear/issues/1395
ec6e77
-    $BACKUP_PROG -a "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" "${BACKUP_RSYNC_OPTIONS[@]}" "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/" 2>/dev/null \
ec6e77
+    $BACKUP_PROG -a "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" "${BACKUP_RSYNC_OPTIONS[@]}" "$(rsync_remote_full "$OUTPUT_URL")/" 2>/dev/null \
ec6e77
         || Error "Could not copy '${RESULT_FILES[*]}' to $OUTPUT_URL location"
ec6e77
     ;;
ec6e77
 
ec6e77
diff --git a/usr/share/rear/prep/RSYNC/GNU/Linux/200_selinux_in_use.sh b/usr/share/rear/prep/RSYNC/GNU/Linux/200_selinux_in_use.sh
ec6e77
index eb7df29e..84500039 100644
ec6e77
--- a/usr/share/rear/prep/RSYNC/GNU/Linux/200_selinux_in_use.sh
ec6e77
+++ b/usr/share/rear/prep/RSYNC/GNU/Linux/200_selinux_in_use.sh
ec6e77
@@ -25,8 +25,10 @@ case $(basename $BACKUP_PROG) in
ec6e77
 
ec6e77
 	(rsync)
ec6e77
 		if grep -q "no xattrs" "$TMP_DIR/rsync_protocol"; then
ec6e77
+			local host
ec6e77
+			host="$(rsync_host "$BACKUP_URL")"
ec6e77
 			# no xattrs compiled in remote rsync, so saving SELinux attributes are not possible
ec6e77
-			Log "WARNING: --xattrs not possible on system ($RSYNC_HOST) (no xattrs compiled in rsync)"
ec6e77
+			Log "WARNING: --xattrs not possible on system ($host) (no xattrs compiled in rsync)"
ec6e77
 			# $TMP_DIR/selinux.mode is a trigger during backup to disable SELinux
ec6e77
 			cat $SELINUX_ENFORCE > $TMP_DIR/selinux.mode
ec6e77
 			RSYNC_SELINUX=		# internal variable used in recover mode (empty means disable SELinux)
ec6e77
diff --git a/usr/share/rear/prep/RSYNC/default/100_check_rsync.sh b/usr/share/rear/prep/RSYNC/default/100_check_rsync.sh
ec6e77
index c964a148..448a1b1a 100644
ec6e77
--- a/usr/share/rear/prep/RSYNC/default/100_check_rsync.sh
ec6e77
+++ b/usr/share/rear/prep/RSYNC/default/100_check_rsync.sh
ec6e77
@@ -3,97 +3,40 @@
ec6e77
 # This file is part of Relax-and-Recover, licensed under the GNU General
ec6e77
 # Public License. Refer to the included COPYING for full text of license.
ec6e77
 
ec6e77
-#### OLD STYLE:
ec6e77
-# BACKUP_URL=[USER@]HOST:PATH           # using ssh (no rsh)
ec6e77
-#
ec6e77
-# with rsync protocol PATH is a MODULE name defined in remote /etc/rsyncd.conf file
ec6e77
-# BACKUP_URL=[USER@]HOST::PATH          # using rsync
ec6e77
-# BACKUP_URL=rsync://[USER@]HOST[:PORT]/PATH    # using rsync (is not compatible with new style!!!)
ec6e77
-
ec6e77
-#### NEW STYLE:
ec6e77
-# BACKUP_URL=rsync://[USER@]HOST[:PORT]/PATH    # using ssh
ec6e77
-# BACKUP_URL=rsync://[USER@]HOST[:PORT]::/PATH  # using rsync
ec6e77
-
ec6e77
 if test -z "$BACKUP_URL" ; then
ec6e77
     Error "Missing BACKUP_URL=rsync://[USER@]HOST[:PORT][::]/PATH !"
ec6e77
 fi
ec6e77
 
ec6e77
-local host=$(url_host $BACKUP_URL)
ec6e77
 local scheme=$(url_scheme $BACKUP_URL)  # url_scheme still recognizes old style
ec6e77
-local path=$(url_path $BACKUP_URL)
ec6e77
 
ec6e77
 if [[ "$scheme" != "rsync" ]]; then
ec6e77
     Error "Missing BACKUP_URL=rsync://[USER@]HOST[:PORT][::]/PATH !"
ec6e77
 fi
ec6e77
 
ec6e77
-RSYNC_PROTO=                    # ssh or rsync
ec6e77
-RSYNC_USER=
ec6e77
-RSYNC_HOST=
ec6e77
-RSYNC_PORT=873                  # default port (of rsync server)
ec6e77
-RSYNC_PATH=
ec6e77
-
ec6e77
-
ec6e77
-if egrep -q '(::)' <<< $BACKUP_URL ; then # new style '::' means rsync protocol
ec6e77
-    RSYNC_PROTO=rsync
ec6e77
-else
ec6e77
-    RSYNC_PROTO=ssh
ec6e77
-fi
ec6e77
-
ec6e77
-if grep -q '@' <<< $host ; then
ec6e77
-    RSYNC_USER="${host%%@*}"    # grab user name
ec6e77
-else
ec6e77
-    RSYNC_USER=root
ec6e77
-fi
ec6e77
-
ec6e77
-# remove USER@ if present (we don't need it anymore)
ec6e77
-local tmp2="${host#*@}"
ec6e77
-
ec6e77
-case "$RSYNC_PROTO" in
ec6e77
-
ec6e77
-    (rsync)
ec6e77
-        # tmp2=witsbebelnx02::backup or tmp2=witsbebelnx02::
ec6e77
-        RSYNC_HOST="${tmp2%%::*}"
ec6e77
-        # path=/gdhaese1@witsbebelnx02::backup or path=/backup
ec6e77
-        if grep -q '::' <<< $path ; then
ec6e77
-            RSYNC_PATH="${path##*::}"
ec6e77
-        else
ec6e77
-            RSYNC_PATH="${path##*/}"
ec6e77
-        fi
ec6e77
-        ;;
ec6e77
-    (ssh)
ec6e77
-        # tmp2=host or tmp2=host:
ec6e77
-        RSYNC_HOST="${tmp2%%:*}"
ec6e77
-        RSYNC_PATH=$path
ec6e77
-        ;;
ec6e77
-
ec6e77
-esac
ec6e77
-
ec6e77
-#echo RSYNC_PROTO=$RSYNC_PROTO
ec6e77
-#echo RSYNC_USER=$RSYNC_USER
ec6e77
-#echo RSYNC_HOST=$RSYNC_HOST
ec6e77
-#echo RSYNC_PORT=$RSYNC_PORT
ec6e77
-#echo RSYNC_PATH=$RSYNC_PATH
ec6e77
+local host proto
ec6e77
+host="$(rsync_host "$BACKUP_URL")"
ec6e77
+proto="$(rsync_proto "$BACKUP_URL")"
ec6e77
 
ec6e77
 # check if host is reachable
ec6e77
 if test "$PING" ; then
ec6e77
-    ping -c 2 "$RSYNC_HOST" >/dev/null || Error "Backup host [$RSYNC_HOST] not reachable."
ec6e77
+    ping -c 2 "$host" >/dev/null || Error "Backup host [$host] not reachable."
ec6e77
 else
ec6e77
     Log "Skipping ping test"
ec6e77
 fi
ec6e77
 
ec6e77
 # check protocol connectivity
ec6e77
-case "$RSYNC_PROTO" in
ec6e77
+case "$proto" in
ec6e77
 
ec6e77
     (rsync)
ec6e77
-        Log "Test: $BACKUP_PROG ${BACKUP_RSYNC_OPTIONS[*]} ${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/"
ec6e77
-        $BACKUP_PROG "${BACKUP_RSYNC_OPTIONS[@]}" ${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/ >/dev/null \
ec6e77
-            || Error "Rsync daemon not running on $RSYNC_HOST"
ec6e77
+        Log "Test: $BACKUP_PROG ${BACKUP_RSYNC_OPTIONS[*]} $(rsync_remote_base "$BACKUP_URL")"
ec6e77
+        $BACKUP_PROG "${BACKUP_RSYNC_OPTIONS[@]}" $(rsync_remote_base "$BACKUP_URL") >/dev/null \
ec6e77
+            || Error "Rsync daemon not running on $host"
ec6e77
         ;;
ec6e77
 
ec6e77
     (ssh)
ec6e77
-        Log "Test: ssh ${RSYNC_USER}@${RSYNC_HOST} /bin/true"
ec6e77
-        ssh ${RSYNC_USER}@${RSYNC_HOST} /bin/true >/dev/null 2>&1 \
ec6e77
-            || Error "Secure shell connection not setup properly [$RSYNC_USER@$RSYNC_HOST]"
ec6e77
+        Log "Test: ssh $(rsync_remote_ssh "$BACKUP_URL") /bin/true"
ec6e77
+        ssh $(rsync_remote_ssh "$BACKUP_URL") /bin/true >/dev/null 2>&1 \
ec6e77
+            || Error "Secure shell connection not setup properly [$(rsync_remote_ssh "$BACKUP_URL")]"
ec6e77
         ;;
ec6e77
 
ec6e77
 esac
ec6e77
diff --git a/usr/share/rear/prep/RSYNC/default/150_check_rsync_protocol_version.sh b/usr/share/rear/prep/RSYNC/default/150_check_rsync_protocol_version.sh
ec6e77
index e9103531..becf35a0 100644
ec6e77
--- a/usr/share/rear/prep/RSYNC/default/150_check_rsync_protocol_version.sh
ec6e77
+++ b/usr/share/rear/prep/RSYNC/default/150_check_rsync_protocol_version.sh
ec6e77
@@ -3,15 +3,18 @@
ec6e77
 # Public License. Refer to the included COPYING for full text of license.
ec6e77
 # try to grab the rsync protocol version of rsync on the remote server
ec6e77
 
ec6e77
-local remote_mountpoint
ec6e77
+local remote_mountpoint host path proto
ec6e77
+host="$(rsync_host "$BACKUP_URL")"
ec6e77
+path="$(rsync_path "$BACKUP_URL")"
ec6e77
+proto="$(rsync_proto "$BACKUP_URL")"
ec6e77
 
ec6e77
 if [ -z "$RSYNC_PROTOCOL_VERSION" ]; then
ec6e77
 
ec6e77
-    case $RSYNC_PROTO in
ec6e77
+    case $proto in
ec6e77
 
ec6e77
     (ssh)
ec6e77
-        ssh ${RSYNC_USER}@${RSYNC_HOST} rsync --version >"$TMP_DIR/rsync_protocol" 2>&1 \
ec6e77
-            || Error "Secure shell connection not setup properly [$RSYNC_USER@$RSYNC_HOST]"
ec6e77
+        ssh $(rsync_remote_ssh "$BACKUP_URL") rsync --version >"$TMP_DIR/rsync_protocol" 2>&1 \
ec6e77
+            || Error "Secure shell connection not setup properly [$(rsync_remote_ssh "$BACKUP_URL")]"
ec6e77
         if grep -q "protocol version" "$TMP_DIR/rsync_protocol" ; then
ec6e77
             RSYNC_PROTOCOL_VERSION=$(grep 'protocol version' "$TMP_DIR/rsync_protocol" | awk '{print $6}')
ec6e77
         else
ec6e77
@@ -24,29 +27,29 @@ if [ -z "$RSYNC_PROTOCOL_VERSION" ]; then
ec6e77
         RSYNC_PROTOCOL_VERSION=29 # being conservative (old rsync)
ec6e77
         ;;
ec6e77
     esac
ec6e77
-    Log "Remote rsync system ($RSYNC_HOST) uses rsync protocol version $RSYNC_PROTOCOL_VERSION"
ec6e77
+    Log "Remote rsync system ($host) uses rsync protocol version $RSYNC_PROTOCOL_VERSION"
ec6e77
 
ec6e77
 else
ec6e77
 
ec6e77
-    Log "Remote rsync system ($RSYNC_HOST) uses rsync protocol version $RSYNC_PROTOCOL_VERSION (overruled by user)"
ec6e77
+    Log "Remote rsync system ($host) uses rsync protocol version $RSYNC_PROTOCOL_VERSION (overruled by user)"
ec6e77
 
ec6e77
 fi
ec6e77
 
ec6e77
-if [ "${RSYNC_USER}" != "root" -a $RSYNC_PROTO = "ssh" ]; then
ec6e77
+if [ "$(rsync_user "$BACKUP_URL")" != "root" -a $proto = "ssh" ]; then
ec6e77
     if [ $RSYNC_PROTOCOL_VERSION -gt 29 ]; then
ec6e77
         if grep -q "no xattrs" "$TMP_DIR/rsync_protocol"; then
ec6e77
             # no xattrs available in remote rsync, so --fake-super is not possible
ec6e77
-            Error "rsync --fake-super not possible on system ($RSYNC_HOST) (no xattrs compiled in rsync)"
ec6e77
+            Error "rsync --fake-super not possible on system ($host) (no xattrs compiled in rsync)"
ec6e77
         else
ec6e77
             # when using --fake-super we must have user_xattr mount options on the remote mntpt
ec6e77
-            remote_mountpoint=$(ssh ${RSYNC_USER}@${RSYNC_HOST} 'cd ${RSYNC_PATH}; df -P .' 2>/dev/null | tail -1 | awk '{print $6}')
ec6e77
-            ssh ${RSYNC_USER}@${RSYNC_HOST} "cd ${RSYNC_PATH} && touch .is_xattr_supported && setfattr -n user.comment -v 'File created by ReaR to test if this filesystems supports extended attributes.' .is_xattr_supported && getfattr -n user.comment .is_xattr_supported 1>/dev/null; find .is_xattr_supported -empty -delete" \
ec6e77
+            remote_mountpoint=$(ssh $(rsync_remote_ssh "$BACKUP_URL") 'cd ${path}; df -P .' 2>/dev/null | tail -1 | awk '{print $6}')
ec6e77
+            ssh $(rsync_remote_ssh "$BACKUP_URL") "cd ${path} && touch .is_xattr_supported && setfattr -n user.comment -v 'File created by ReaR to test if this filesystems supports extended attributes.' .is_xattr_supported && getfattr -n user.comment .is_xattr_supported 1>/dev/null; find .is_xattr_supported -empty -delete" \
ec6e77
                 || Error "Remote file system $remote_mountpoint does not have user_xattr mount option set!"
ec6e77
             #BACKUP_RSYNC_OPTIONS+=( --xattrs --rsync-path="rsync --fake-super" )
ec6e77
             # see issue #366 for explanation of removing --xattrs
ec6e77
             BACKUP_RSYNC_OPTIONS+=( --rsync-path="rsync --fake-super" )
ec6e77
         fi
ec6e77
     else
ec6e77
-        Error "rsync --fake-super not possible on system ($RSYNC_HOST) (please upgrade rsync to 3.x)"
ec6e77
+        Error "rsync --fake-super not possible on system ($host) (please upgrade rsync to 3.x)"
ec6e77
     fi
ec6e77
 fi
ec6e77
diff --git a/usr/share/rear/restore/RSYNC/default/400_restore_rsync_backup.sh b/usr/share/rear/restore/RSYNC/default/400_restore_rsync_backup.sh
ec6e77
index 993088be..0fa08587 100644
ec6e77
--- a/usr/share/rear/restore/RSYNC/default/400_restore_rsync_backup.sh
ec6e77
+++ b/usr/share/rear/restore/RSYNC/default/400_restore_rsync_backup.sh
ec6e77
@@ -7,7 +7,11 @@ get_size() {
ec6e77
 local backup_prog_rc
ec6e77
 local restore_log_message
ec6e77
 
ec6e77
-LogPrint "Restoring $BACKUP_PROG backup from '${RSYNC_HOST}:${RSYNC_PATH}'"
ec6e77
+local host path
ec6e77
+host="$(rsync_host "$BACKUP_URL")"
ec6e77
+path="$(rsync_path "$BACKUP_URL")"
ec6e77
+
ec6e77
+LogPrint "Restoring $BACKUP_PROG backup from '${host}:${path}'"
ec6e77
 
ec6e77
 ProgressStart "Restore operation"
ec6e77
 (
ec6e77
@@ -15,18 +19,18 @@ ProgressStart "Restore operation"
ec6e77
 
ec6e77
 		(rsync)
ec6e77
 
ec6e77
-			case $RSYNC_PROTO in
ec6e77
+			case $(rsync_proto "$BACKUP_URL") in
ec6e77
 
ec6e77
 				(ssh)
ec6e77
-					Log $BACKUP_PROG "${BACKUP_RSYNC_OPTIONS[@]}" "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/backup"/ $TARGET_FS_ROOT/
ec6e77
+					Log $BACKUP_PROG "${BACKUP_RSYNC_OPTIONS[@]}" "$(rsync_remote_full "$BACKUP_URL")/backup"/ $TARGET_FS_ROOT/
ec6e77
 					$BACKUP_PROG "${BACKUP_RSYNC_OPTIONS[@]}" \
ec6e77
-					"${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/backup"/ \
ec6e77
+					"$(rsync_remote_full "$BACKUP_URL")/backup"/ \
ec6e77
 					$TARGET_FS_ROOT/
ec6e77
 					;;
ec6e77
 
ec6e77
 				(rsync)
ec6e77
 					$BACKUP_PROG "${BACKUP_RSYNC_OPTIONS[@]}" \
ec6e77
-					"${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/backup"/ $TARGET_FS_ROOT/
ec6e77
+					"$(rsync_remote_full "$BACKUP_URL")/backup"/ $TARGET_FS_ROOT/
ec6e77
 					;;
ec6e77
 
ec6e77
 			esac
ec6e77
diff --git a/usr/share/rear/verify/RSYNC/default/550_check_remote_backup_archive.sh b/usr/share/rear/verify/RSYNC/default/550_check_remote_backup_archive.sh
ec6e77
index b2fb72f5..76132794 100644
ec6e77
--- a/usr/share/rear/verify/RSYNC/default/550_check_remote_backup_archive.sh
ec6e77
+++ b/usr/share/rear/verify/RSYNC/default/550_check_remote_backup_archive.sh
ec6e77
@@ -1,14 +1,14 @@
ec6e77
 # check the backup archive on remote rsync server
ec6e77
 
ec6e77
-case $RSYNC_PROTO in
ec6e77
+case $(rsync_proto "$BACKUP_URL") in
ec6e77
 
ec6e77
 	(ssh)
ec6e77
-		ssh ${RSYNC_USER}@${RSYNC_HOST} "ls -ld ${RSYNC_PATH}/${RSYNC_PREFIX}/backup" >/dev/null 2>&1 \
ec6e77
-		    || Error "Archive not found on [$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}]"
ec6e77
+		ssh $(rsync_remote_ssh "$BACKUP_URL") "ls -ld $(rsync_path_full "$BACKUP_URL")/backup" >/dev/null 2>&1 \
ec6e77
+		    || Error "Archive not found on [$(rsync_remote_full "$BACKUP_URL")]"
ec6e77
 		;;
ec6e77
 
ec6e77
 	(rsync)
ec6e77
-		$BACKUP_PROG "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/backup" >/dev/null 2>&1 \
ec6e77
-		    || Error "Archive not found on [$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}]"
ec6e77
+		$BACKUP_PROG "$(rsync_remote_full "$BACKUP_URL")/backup" >/dev/null 2>&1 \
ec6e77
+		    || Error "Archive not found on [$(rsync_remote_full "$BACKUP_URL")]"
ec6e77
 		;;
ec6e77
 esac