All Downloads are FREE. Search and download functionalities are using the official Maven repository.

refcodes-batch.1.0.2.source-code.replicate-folder-to-folder-mirror-over-ssh-client-to-ssh-server.job Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
#!/bin/bash

if [[ $HELP = y ]] ; then
	echo "The switch \"-j $JOB\" rsyncs a local site's folder structure                   " >&2
	echo "via SSH remotely. Local files are copied into the remote folder structure, any  " >&2
	echo "remote files not exisiting locally are removed from the remote folder structure." >&2
	logSeparator
fi

. $SCRIPT_DIR/validate-folder-config.job
. $SCRIPT_DIR/validate-folder-mirror-config.job
. $SCRIPT_DIR/validate-ssh-minimal-config.job

if [[ $HELP = y ]] ; then
	exit $EXIT_SUCCESS
fi

exitOnConfigOff "FOLDER"
exitOnConfigOff "FOLDER_MIRROR"
exitOnConfigOff "SSH_MINIMAL"

SSH_CLIENT_KEY_FILE=$SSH_CLIENT_KEY_DIR/$SSH_KEY_FILE_NAME

EXCLUDE=""
if [ ! -z "${FOLDER_MIRROR_DO_NOT_TOUCH}" ] ; then
	EXCLUDE="--exclude ${FOLDER_MIRROR_DO_NOT_TOUCH}"
fi

INCLUDE=""
if [ ! -z "${FOLDER_INCLUDE_FILE}" ] ; then
	exitOnMissingPropertyPath "${FOLDER_INCLUDE_FILE}"
	INCLUDE="--include-from="${FOLDER_INCLUDE_FILE}""
fi

if [[ $VERBOSE = y ]] ; then
	echo "Assuming the path \"$FOLDER_DIR\" to exist ..." >&2
	echo "Assuming the path \"$SSH_CLIENT_KEY_FILE\" to exist ..." >&2
	logSeparator
	echo "Using exclude pattern \"$FOLDER_MIRROR_DO_NOT_TOUCH\" (when set) ..." >&2
	echo "Using include file \"$FOLDER_INCLUDE_FILE\" (when set) ..." >&2
	logSeparator
fi

exitOnMissingPropertyPath "FOLDER_DIR"
exitOnMissingVariablePath "SSH_CLIENT_KEY_FILE"

if [[ $VERBOSE = y ]] ; then
	echo "Replicating folder \"$FOLDER_DIR\" to folder mirror \"$FOLDER_MIRROR_DIR@$SSH_SERVER_HOSTNAME\" ..." >&2
	logSeparator
fi

rsync -avzP --delete ${EXCLUDE} ${INCLUDE} -e "ssh -i $SSH_CLIENT_KEY_FILE" $FOLDER_DIR/ $SSH_SERVER_USER_NAME@$SSH_SERVER_HOSTNAME:$FOLDER_MIRROR_DIR/
exitOnError "Unable to replicate folder \"$FOLDER_DIR\" to folder mirror \"$FOLDER_MIRROR_DIR@$SSH_SERVER_HOSTNAME\" !!!"
logSeparator

# ----------------------------------------------
# Consider an exit code 23 still as scuccessful:
# ----------------------------------------------
# EXIT_CODE=$?
# if [[ $EXIT_CODE != 23 ]] && [[ $EXIT_CODE != 0 ]] ; then
# 	$(exit $EXIT_CODE)
# 	exitOnError "Unable replicate folder \"$FOLDER_DIR\" to folder mirror \"$FOLDER_MIRROR_DIR@$SSH_SERVER_HOSTNAME\" !!!"
# fi

showSuccess "Replicated folder \"$FOLDER_DIR\" to folder mirror \"$SSH_SERVER_HOSTNAME@$FOLDER_MIRROR_DIR\" !"




© 2015 - 2024 Weber Informatics LLC | Privacy Policy