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 "Options"
echo " -p, --port SSH port." echo " -p, --port SSH port."
echo " -h, --help Display this help message." 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-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-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 " --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 " not be managed by the script - in particular they will not be"
echo " automatically deleted." 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_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_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/') 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}" SSH_CMD="ssh -p $SSH_PORT ${SSH_USER}@${SSH_HOST}"
fi
SSH_DEST_FOLDER_PREFIX="${SSH_USER}@${SSH_HOST}:" SSH_DEST_FOLDER_PREFIX="${SSH_USER}@${SSH_HOST}:"
elif echo "$SRC_FOLDER"|grep -Eq '^[A-Za-z0-9\._%\+\-]+@[A-Za-z0-9.\-]+\:.+$' elif echo "$SRC_FOLDER"|grep -Eq '^[A-Za-z0-9\._%\+\-]+@[A-Za-z0-9.\-]+\:.+$'
then then
SSH_USER=$(echo "$SRC_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\1/') 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_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/') 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}" SSH_CMD="ssh -p $SSH_PORT ${SSH_USER}@${SSH_HOST}"
fi
SSH_SRC_FOLDER_PREFIX="${SSH_USER}@${SSH_HOST}:" SSH_SRC_FOLDER_PREFIX="${SSH_USER}@${SSH_HOST}:"
fi fi
} }
@@ -207,6 +217,7 @@ SSH_CMD=""
SSH_DEST_FOLDER_PREFIX="" SSH_DEST_FOLDER_PREFIX=""
SSH_SRC_FOLDER_PREFIX="" SSH_SRC_FOLDER_PREFIX=""
SSH_PORT="22" SSH_PORT="22"
ID_RSA=""
SRC_FOLDER="" SRC_FOLDER=""
DEST_FOLDER="" DEST_FOLDER=""
@@ -228,6 +239,10 @@ while :; do
shift shift
SSH_PORT=$1 SSH_PORT=$1
;; ;;
-i|--id_rsa)
shift
ID_RSA="$1"
;;
--rsync-get-flags) --rsync-get-flags)
shift shift
echo $RSYNC_FLAGS echo $RSYNC_FLAGS
@@ -237,6 +252,10 @@ while :; do
shift shift
RSYNC_FLAGS="$1" RSYNC_FLAGS="$1"
;; ;;
--rsync-append-flags)
shift
RSYNC_FLAGS="$RSYNC_FLAGS $1"
;;
--strategy) --strategy)
shift shift
EXPIRATION_STRATEGY="$1" EXPIRATION_STRATEGY="$1"
@@ -444,8 +463,12 @@ while : ; do
CMD="rsync" CMD="rsync"
if [ -n "$SSH_CMD" ]; then 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'" CMD="$CMD -e 'ssh -p $SSH_PORT -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'"
fi fi
fi
CMD="$CMD $RSYNC_FLAGS" CMD="$CMD $RSYNC_FLAGS"
CMD="$CMD --log-file '$LOG_FILE'" CMD="$CMD --log-file '$LOG_FILE'"
if [ -n "$EXCLUSION_FILE" ]; then if [ -n "$EXCLUSION_FILE" ]; then