Last active
December 16, 2017 17:37
-
-
Save skorski/7ef564be0cb4fe6196b34ce704d564e1 to your computer and use it in GitHub Desktop.
Stateful Containers Medium Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apt-get update; apt-get install rsync -y | |
BOOTSTRAP_DIR=${BOOTSTRAP_DIR:-/opt/nifi/} | |
OUTPUT_DIR=${OUTPUT_DIR:-/tmp/} | |
INPUT_TIME=$(find ${BOOTSTRAP_DIR} -type f | xargs stat --format '%Y' 2>/dev/null | sort -nr | head -n1) | |
OUTPUT_TIME=$(find ${OUTPUT_DIR} -type f | xargs stat --format '%Y' 2>/dev/null | sort -nr | head -n1) | |
echo IN:${INPUT_TIME} OUT:${OUTPUT_TIME} | |
if [[ ${INPUT_TIME} -gt 0 ]] || [[ ${OUTPUT_TIME} -gt 0 ]] | |
then | |
if [[ ${INPUT_TIME} -eq ${OUTPUT_TIME} ]] | |
then | |
echo "File times match. Skipping Rsync" | |
else | |
if [[ ${INPUT_TIME} -gt ${OUTPUT_TIME} ]] | |
then | |
echo "Input should be copied to output" | |
rsync -razh ${BOOTSTRAP_DIR} ${OUTPUT_DIR} | |
echo copied based on rsync -razh ${BOOTSTRAP_DIR} ${OUTPUT_DIR} | |
fi | |
if [[ ${INPUT_TIME} -lt ${OUTPUT_TIME} ]] | |
then | |
echo "output should be copied to input" | |
rsync -razh ${OUTPUT_DIR} ${BOOTSTRAP_DIR} | |
echo copied based on rsync -razh ${OUTPUT_DIR} ${BOOTSTRAP_DIR} | |
fi | |
fi | |
else | |
echo "No files found" | |
fi | |
echo "file staging is done" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment