refcodes-batch.0.3.0.source-code.replicate-folder-to-folder-mirror.job Maven / Gradle / Ivy
#!/bin/bash
if [[ $HELP = y ]] ; then
echo "The switch \"-j $JOB\" rsyncs your local folder structure. " >&2
echo "Local files are copied into the local folder mirror structure, any files " >&2
echo "not exisiting are removed from the local folder mirror structure. " >&2
logSeparator
fi
. $SCRIPT_DIR/validate-folder-config.job
. $SCRIPT_DIR/validate-folder-mirror-config.job
if [[ $HELP = y ]] ; then
exit $EXIT_SUCCESS
fi
exitOnConfigOff "FOLDER"
exitOnConfigOff "FOLDER_MIRROR"
EXCLUDES=""
if [ ! -z "${FOLDER_MIRROR_EXCLUDES}" ] ; then
for exclude in ${FOLDER_MIRROR_EXCLUDES} ; do
EXCLUDES="${EXCLUDES} --exclude ${exclude}"
done
fi
if [[ $VERBOSE = y ]] ; then
echo "Replicating folder \"${FOLDER_DIR}\" to folder mirror \"${FOLDER_MIRROR_DIR}\" ..." >&2
logSeparator
fi
# Try "--no-p" (no permissions) and "--no-g" (no group)
if [ ! -z "${FOLDER_MIRROR_INCLUDES}" ] ; then
for folder in ${FOLDER_MIRROR_INCLUDES} ; do
rsync -avzh --modify-window=1 --delete ${EXCLUDES} "${FOLDER_DIR}/${folder}/" "${FOLDER_MIRROR_DIR}/${folder}/"
exitCode=$?
if [[ $exitCode != 23 ]] && [[ $exitCode != 0 ]] ; then
$(exit $exitCode)
exitOnError "Unable to replicate folder \"${FOLDER_DIR}/${folder}\" to folder mirror \"${FOLDER_MIRROR_DIR}/${folder}\" !!!"
fi
done
else
rsync -avzh --modify-window=1 --delete ${EXCLUDES} "${FOLDER_DIRS}" "${FOLDER_MIRROR_DIR}"
exitCode=$?
if [[ $exitCode != 23 ]] && [[ $exitCode != 0 ]] ; then
$(exit $exitCode)
exitOnError "Unable to replicate folder \"${FOLDER_DIR}\" to folder mirror \"${FOLDER_MIRROR_DIR}\" !!!"
fi
fi
showSuccess "Replicated folder \"$FOLDER_DIR\" to folder mirror \"$FOLDER_MIRROR_DIR\" !"