Added rsync-append-flags method and method to specify id_rsa for ssh (#134)

* added rsync-append-flag method and method to specify id_rsa for ssh

* fixed formatting

* fixed formatting
This commit is contained in:
DeeeeLAN
2019-01-18 05:17:34 -07:00
committed by Laurent Cozic
parent ae564afa9c
commit 72d694d8e4
+23
View File
@@ -37,8 +37,10 @@ fn_display_usage() {
echo "Options"
echo " -p, --port SSH port."
echo " -h, --help Display this help message."
echo " -i, --id_rsa Specify the private ssh key to use."
echo " --rsync-get-flags Display the default rsync flags that are used for backup."
echo " --rsync-set-flags Set the rsync flags that are going to be used for backup."
echo " --rsync-append-flags Append the rsync flags that are going to be used for backup."
echo " --log-dir Set the log file directory. If this flag is set, generated files will"
echo " not be managed by the script - in particular they will not be"
echo " automatically deleted."
@@ -146,14 +148,22 @@ fn_parse_ssh() {
SSH_USER=$(echo "$DEST_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\1/')
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}"
else
SSH_CMD="ssh -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.\-]+\:.+$'
then
SSH_USER=$(echo "$SRC_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\1/')
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}"
else
SSH_CMD="ssh -p $SSH_PORT ${SSH_USER}@${SSH_HOST}"
fi
SSH_SRC_FOLDER_PREFIX="${SSH_USER}@${SSH_HOST}:"
fi
}
@@ -207,6 +217,7 @@ SSH_CMD=""
SSH_DEST_FOLDER_PREFIX=""
SSH_SRC_FOLDER_PREFIX=""
SSH_PORT="22"
ID_RSA=""
SRC_FOLDER=""
DEST_FOLDER=""
@@ -228,6 +239,10 @@ while :; do
shift
SSH_PORT=$1
;;
-i|--id_rsa)
shift
ID_RSA="$1"
;;
--rsync-get-flags)
shift
echo $RSYNC_FLAGS
@@ -237,6 +252,10 @@ while :; do
shift
RSYNC_FLAGS="$1"
;;
--rsync-append-flags)
shift
RSYNC_FLAGS="$RSYNC_FLAGS $1"
;;
--strategy)
shift
EXPIRATION_STRATEGY="$1"
@@ -444,8 +463,12 @@ while : ; do
CMD="rsync"
if [ -n "$SSH_CMD" ]; then
if [ -n "$ID_RSA" ] ; then
CMD="$CMD -e 'ssh -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'"
fi
fi
CMD="$CMD $RSYNC_FLAGS"
CMD="$CMD --log-file '$LOG_FILE'"
if [ -n "$EXCLUSION_FILE" ]; then