summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbackup.in60
1 files changed, 56 insertions, 4 deletions
diff --git a/backup.in b/backup.in
index b6d87b7..ca4c1ae 100755
--- a/backup.in
+++ b/backup.in
@@ -1,6 +1,6 @@
#!/bin/bash
-rsyncOptions='-6vxcaHAXF'
+rsyncOptions='-vxcaHAXF'
rsync --help | \
grep -q -- --may-modify-others && \
rsyncOptions="${rsyncOptions} --may-modify-others"
@@ -27,6 +27,34 @@ Options:
exit $1
}
+extract_ssh_host() {
+ {
+ printf '%s\n' "$1"
+ if [ -f ~/.ssh/config ]; then
+ sed '
+ /^Host\s\+'"$1"'$/,/^Host\s/ {
+ s/^\s*Hostname\s\+//
+ t
+ }
+ d
+ ' ~/.ssh/config
+ fi
+ } \
+ | tail -n1
+}
+
+extract_ssh_ip_protocols() {
+ getent ahosts "$(extract_ssh_host "$1")" \
+ | sed '
+ s/^\([0-9]\+\.\)\{3\}[0-9]\+\s\+STREAM\(\s.*\)\?$/4/
+ t
+ s/^[0-9a-f][0-9a-f:]\+\s\+STREAM\(\s.*\)\?$/6/
+ t
+ d
+ ' \
+ | sort -u
+}
+
if [ $# -eq 1 ]; then
if [ "$1" == "--help" ]; then
usage 0
@@ -57,17 +85,41 @@ QuellIP=$(echo "$3" | sed "s|^[a-zA-Z]*://||; s|^[a-zA-Z]*@||; s|:\?/.*$||")
if [ "$#" -eq 3 ]; then
Quelle="$3"
+ ipVer=$(
+ extract_ssh_ip_protocols "${QuellIP}" \
+ | sort -n \
+ | tail -n1
+ )
elif [ "$#" -eq 4 ]; then
sshHopp="$4"
lokPort=$[$RANDOM/2+8000]
- rsyncShell="-e ssh -6 -p${lokPort} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
- tunnelBefehl="ssh -6 -t -t -L[::1]:${lokPort}:${QuellIP}:22 ${sshHopp}"
HoppIP="${sshHopp#*@}"
- Quelle="$(echo "$3" | sed "s|${QuellIP}|[::1]|")"
+ ipVer=$(
+ {
+ extract_ssh_ip_protocols "${QuellIP}"
+ extract_ssh_ip_protocols "${HoppIP}"
+ } \
+ | sort -n \
+ | uniq -d \
+ | tail -n1
+ )
+ if [ ${ipVer} -eq 4 ]; then
+ localAddress='127.0.0.1'
+ elif [ ${ipVer} -eq 6 ]; then
+ localAddress='[::1]'
+ else
+ >&2 echo 'ip version of hopp and target must be the same'
+ exit 1
+ fi
+ rsyncShell="-e ssh -${ipVer} -p${lokPort} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
+ tunnelBefehl="ssh -${ipVer} -t -t -L${localAddress}:${lokPort}:${QuellIP}:22 ${sshHopp}"
+ Quelle="$(echo "$3" | sed "s|${QuellIP}|${localAddress}|")"
else
usage
fi
+rsyncOptions="${rsyncOptions}${ipVer}"
+
if [ ! -d ${Basis} ]; then
for neededMount in "${neededMounts[@]}"; do
if ! mountpoint -q "${neededMount}"; then