Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for user to specify ssh binary name. #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions rsync_tmbackup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fn_display_usage() {
echo " After 365 days keep one backup every 30 days."
echo " --no-auto-expire Disable automatically deleting backups when out of space. Instead an error"
echo " is logged, and the backup is aborted."
echo " --ssh-bin Specify the name of the ssh binary."
echo ""
echo "For more detailed help, please see the README file:"
echo ""
Expand Down Expand Up @@ -180,9 +181,9 @@ fn_parse_ssh() {
SSH_HOST=$(echo "$DEST_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\2/')
SSH_DEST_FOLDER=$(echo "$DEST_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\3/')
if [ -n "$ID_RSA" ] ; then
SSH_CMD="ssh -p $SSH_PORT -i $ID_RSA ${SSH_USER}@${SSH_HOST}"
SSH_CMD="$SSH_BIN -p $SSH_PORT -i $ID_RSA ${SSH_USER}@${SSH_HOST}"
else
SSH_CMD="ssh -p $SSH_PORT ${SSH_USER}@${SSH_HOST}"
SSH_CMD="$SSH_BIN -p $SSH_PORT ${SSH_USER}@${SSH_HOST}"
fi
SSH_DEST_FOLDER_PREFIX="${SSH_USER}@${SSH_HOST}:"
elif echo "$SRC_FOLDER"|grep -Eq '^[A-Za-z0-9\._%\+\-]+@[A-Za-z0-9.\-]+\:.+$'
Expand All @@ -191,9 +192,9 @@ fn_parse_ssh() {
SSH_HOST=$(echo "$SRC_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\2/')
SSH_SRC_FOLDER=$(echo "$SRC_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\3/')
if [ -n "$ID_RSA" ] ; then
SSH_CMD="ssh -p $SSH_PORT -i $ID_RSA ${SSH_USER}@${SSH_HOST}"
SSH_CMD="$SSH_BIN -p $SSH_PORT -i $ID_RSA ${SSH_USER}@${SSH_HOST}"
else
SSH_CMD="ssh -p $SSH_PORT ${SSH_USER}@${SSH_HOST}"
SSH_CMD="$SSH_BIN -p $SSH_PORT ${SSH_USER}@${SSH_HOST}"
fi
SSH_SRC_FOLDER_PREFIX="${SSH_USER}@${SSH_HOST}:"
fi
Expand Down Expand Up @@ -266,6 +267,7 @@ SSH_HOST=""
SSH_DEST_FOLDER=""
SSH_SRC_FOLDER=""
SSH_CMD=""
SSH_BIN=""
SSH_DEST_FOLDER_PREFIX=""
SSH_SRC_FOLDER_PREFIX=""
SSH_PORT="22"
Expand Down Expand Up @@ -320,6 +322,10 @@ while :; do
--no-auto-expire)
AUTO_EXPIRE="0"
;;
--ssh-bin)
shift
SSH_BIN="$1"
;;
--)
shift
SRC_FOLDER="$1"
Expand Down Expand Up @@ -358,6 +364,10 @@ fi

DEST_FOLDER="${DEST_FOLDER%/}"

if [ -z "$SSH_BIN" ]; then
SSH_BIN="ssh"
fi

fn_parse_ssh

if [ -n "$SSH_DEST_FOLDER" ]; then
Expand Down Expand Up @@ -546,9 +556,9 @@ while : ; do
if [ -n "$SSH_CMD" ]; then
$RSYNC_FLAGS="$RSYNC_FLAGS --compress"
if [ -n "$ID_RSA" ] ; then
CMD="$CMD -e 'ssh -p $SSH_PORT -i $ID_RSA -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'"
CMD="$CMD -e '$SSH_BIN -p $SSH_PORT -i $ID_RSA -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'"
else
CMD="$CMD -e 'ssh -p $SSH_PORT -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'"
CMD="$CMD -e '$SSH_BIN -p $SSH_PORT -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'"
fi
fi
CMD="$CMD $RSYNC_FLAGS"
Expand Down