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

refcodes-batch.1.0.2.source-code.replicate-media-folder-to-media-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 your local media folder structure.                " >&2
	echo "via SSH remotely. Local files are copied into the media player's remote folder  " >&2
	echo "structure, any media palyer files not exisiting are removed from the media      " >&2
	echo "palyer's folder structure.                                                      " >&2
	logSeparator
fi

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

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

exitOnConfigOff "MEDIA_FOLDER"
exitOnConfigOff "MEDIA_FOLDER_MIRROR"
exitOnConfigOff "SSH_MINIMAL"

SSH_CLIENT_KEY_FILE=$SSH_CLIENT_KEY_DIR/$SSH_KEY_FILE_NAME

MEDIA_FOLDER_MUSIC_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_MUSIC_SUB_DIR}
MEDIA_FOLDER_PHOTO_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_PHOTO_SUB_DIR}
MEDIA_FOLDER_EBOOK_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_EBOOK_SUB_DIR}
MEDIA_FOLDER_VIDEO_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_VIDEO_SUB_DIR}
MEDIA_FOLDER_MIRROR_MUSIC_DIR=${MEDIA_FOLDER_MIRROR_DIR}/${MEDIA_FOLDER_MIRROR_MUSIC_SUB_DIR}
MEDIA_FOLDER_MIRROR_PHOTO_DIR=${MEDIA_FOLDER_MIRROR_DIR}/${MEDIA_FOLDER_MIRROR_PHOTO_SUB_DIR}
MEDIA_FOLDER_MIRROR_EBOOK_DIR=${MEDIA_FOLDER_MIRROR_DIR}/${MEDIA_FOLDER_MIRROR_EBOOK_SUB_DIR}
MEDIA_FOLDER_MIRROR_VIDEO_DIR=${MEDIA_FOLDER_MIRROR_DIR}/${MEDIA_FOLDER_MIRROR_VIDEO_SUB_DIR}

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

INCLUDE_MUSIC=""
if [ ! -z "${MEDIA_FOLDER_MIRROR_MUSIC_INCLUDE_FILE}" ] ; then
	INCLUDE_MUSIC="--include-from="${MEDIA_FOLDER_MIRROR_MUSIC_INCLUDE_FILE}""
fi


INCLUDE_PHOTO=""
if [ ! -z "${MEDIA_FOLDER_MIRROR_PHOTO_INCLUDE_FILE}" ] ; then
	INCLUDE_PHOTO="--include-from="${MEDIA_FOLDER_MIRROR_PHOTO_INCLUDE_FILE}""
fi


INCLUDE_EBOOK=""
if [ ! -z "${MEDIA_FOLDER_MIRROR_EBOOK_INCLUDE_FILE}" ] ; then
	INCLUDE_EBOOK="--include-from="${MEDIA_FOLDER_MIRROR_EBOOK_INCLUDE_FILE}""
fi


INCLUDE_VIDEO=""
if [ ! -z "${MEDIA_FOLDER_MIRROR_VIDEO_INCLUDE_FILE}" ] ; then
	INCLUDE_VIDEO="--include-from="${MEDIA_FOLDER_MIRROR_VIDEO_INCLUDE_FILE}""
fi

if [ ! -z "${MEDIA_FOLDER_MUSIC_SUB_DIR}" ] && [ ! -z "${MEDIA_FOLDER_MIRROR_MUSIC_SUB_DIR}" ] ; then
	if [[ $VERBOSE = y ]] ; then
		echo "Replicating media folder \"${MEDIA_FOLDER_MUSIC_DIR}\" to media player folder mirror \"${MEDIA_FOLDER_MIRROR_MUSIC_DIR}@${SSH_SERVER_HOSTNAME}\" ..." >&2
		logSeparator
	fi
	
	# Try "--no-p" (no permissions) and "--no-g" (no group)
	rsync -avzP --delete ${EXCLUDE} ${INCLUDE_MUSIC} -e "ssh -i $SSH_CLIENT_KEY_FILE" ${MEDIA_FOLDER_MUSIC_DIR}/ $SSH_SERVER_USER_NAME@$SSH_SERVER_HOSTNAME:$MEDIA_FOLDER_MIRROR_MUSIC_DIR/
	# rsync -avzh --modify-window=1 --delete --include-from="${MEDIA_FOLDER_MIRROR_MUSIC_INCLUDE_FILE}" "${MEDIA_FOLDER_MUSIC_DIR}/" "${MEDIA_FOLDER_MIRROR_MUSIC_DIR}"
	exitCode=$?
	if [[ $exitCode != 23 ]] && [[ $exitCode != 0 ]] ; then
		$(exit $exitCode)
		exitOnError "Unable to replicate folder \"${MEDIA_FOLDER_MUSIC_DIR}\" to folder mirror \"${MEDIA_FOLDER_MIRROR_MUSIC_DIR}@${SSH_SERVER_HOSTNAME}\" !!!"
	fi
	logSeparator
fi

if [ ! -z "${MEDIA_FOLDER_PHOTO_SUB_DIR}" ] && [ ! -z "${MEDIA_FOLDER_MIRROR_PHOTO_SUB_DIR}" ] ; then
	if [[ $VERBOSE = y ]] ; then
		echo "Replicating media folder \"${MEDIA_FOLDER_PHOTO_DIR}\" to media player folder mirror \"${MEDIA_FOLDER_MIRROR_PHOTO_DIR}@${SSH_SERVER_HOSTNAME}\" ..." >&2
		logSeparator
	fi
	
	# Try "--no-p" (no permissions) and "--no-g" (no group)
	rsync -avzP --delete ${EXCLUDE} ${INCLUDE_PHOTO} -e "ssh -i $SSH_CLIENT_KEY_FILE" ${MEDIA_FOLDER_PHOTO_DIR}/ $SSH_SERVER_USER_NAME@$SSH_SERVER_HOSTNAME:$MEDIA_FOLDER_MIRROR_PHOTO_DIR/
	#rsync -avzh --modify-window=1 --delete --include-from="${MEDIA_FOLDER_MIRROR_PHOTO_INCLUDE_FILE}" "${MEDIA_FOLDER_PHOTO_DIR}/"	"${MEDIA_FOLDER_MIRROR_PHOTO_DIR}"
	exitCode=$?
	if [[ $exitCode != 23 ]] && [[ $exitCode != 0 ]] ; then
		$(exit $exitCode)
		exitOnError "Unable to replicate folder \"${MEDIA_FOLDER_PHOTO_DIR}\" to folder mirror \"${MEDIA_FOLDER_MIRROR_PHOTO_DIR}@${SSH_SERVER_HOSTNAME}\" !!!"
	fi
	logSeparator
fi

if [ ! -z "${MEDIA_FOLDER_EBOOK_SUB_DIR}" ] && [ ! -z "${MEDIA_FOLDER_MIRROR_EBOOK_SUB_DIR}" ] ; then
	if [[ $VERBOSE = y ]] ; then
		echo "Replicating media folder \"${MEDIA_FOLDER_EBOOK_DIR}\" to media player folder mirror \"${MEDIA_FOLDER_MIRROR_EBOOK_DIR}@${SSH_SERVER_HOSTNAME}\" ..." >&2
		logSeparator
	fi
	
	# Try "--no-p" (no permissions) and "--no-g" (no group)
	rsync -avzP --delete ${EXCLUDE} ${INCLUDE_EBOOK} -e "ssh -i $SSH_CLIENT_KEY_FILE" ${MEDIA_FOLDER_EBOOK_DIR}/ $SSH_SERVER_USER_NAME@$SSH_SERVER_HOSTNAME:$MEDIA_FOLDER_MIRROR_EBOOK_DIR/	
	# rsync -avzh --modify-window=1 --delete --include-from="${MEDIA_FOLDER_MIRROR_EBOOK_INCLUDE_FILE}" "${MEDIA_FOLDER_EBOOK_DIR}/" "${MEDIA_FOLDER_MIRROR_EBOOK_DIR}"
	exitCode=$?
	if [[ $exitCode != 23 ]] && [[ $exitCode != 0 ]] ; then
		$(exit $exitCode)
		exitOnError "Unable to replicate folder \"${MEDIA_FOLDER_EBOOK_DIR}\" to folder mirror \"${MEDIA_FOLDER_MIRROR_EBOOK_DIR}@${SSH_SERVER_HOSTNAME}\" !!!"
	fi
	logSeparator
fi

if [ ! -z "${MEDIA_FOLDER_VIDEO_SUB_DIR}" ] && [ ! -z "${MEDIA_FOLDER_MIRROR_VIDEO_SUB_DIR}" ] ; then
	if [[ $VERBOSE = y ]] ; then
		echo "Replicating media folder \"${MEDIA_FOLDER_VIDEO_DIR}\" to media player folder mirror \"${MEDIA_FOLDER_MIRROR_VIDEO_DIR}@${SSH_SERVER_HOSTNAME}\" ..." >&2
		logSeparator
	fi
	
	# Try "--no-p" (no permissions) and "--no-g" (no group)
	rsync -avzP --delete ${EXCLUDE} ${INCLUDE_VIDEO} -e "ssh -i $SSH_CLIENT_KEY_FILE" ${MEDIA_FOLDER_VIDEO_DIR}/ $SSH_SERVER_USER_NAME@$SSH_SERVER_HOSTNAME:$MEDIA_FOLDER_MIRROR_VIDEO_DIR/
	# rsync -avzh --modify-window=1 --delete --include-from="${MEDIA_FOLDER_MIRROR_VIDEO_INCLUDE_FILE}" "${MEDIA_FOLDER_VIDEO_DIR}/" "${MEDIA_FOLDER_MIRROR_VIDEO_DIR}"
	exitCode=$?
	if [[ $exitCode != 23 ]] && [[ $exitCode != 0 ]] ; then
		$(exit $exitCode)
		exitOnError "Unable to replicate folder \"${MEDIA_FOLDER_VIDEO_DIR}\" to folder mirror \"${MEDIA_FOLDER_MIRROR_VIDEO_DIR}@${SSH_SERVER_HOSTNAME}\" !!!"
	fi
	logSeparator
fi

showSuccess "Replicated folder \"$MEDIA_FOLDER_DIR\" to folder mirror \"$SSH_SERVER_HOSTNAME@$MEDIA_FOLDER_MIRROR_DIR\" !"




© 2015 - 2024 Weber Informatics LLC | Privacy Policy