Last active
August 17, 2020 22:07
-
-
Save jeffrade/6ed3e967d1329178912d82a666118f2c to your computer and use it in GitHub Desktop.
Bash Script (infinite loop) to Upload Files to AWS S3 Glacier
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
#!/bin/bash | |
QUEUE_DIR="./queue" | |
COMPLETED_DIR="./completed" | |
S3_BUCKET_NAME="<YOUR_BUCKET_NAME_HERE>" | |
OLDEST_FILENAME="" | |
echo "Running..." | |
while :; do | |
echo "Finding oldest file..." | |
OLDEST_FILENAME="$(find $QUEUE_DIR -type f -printf '%T+ %p\n' | sort | head -n 1 | grep -o " .*")" | |
if [[ -n "$OLDEST_FILENAME" ]] ; then | |
echo "Found $OLDEST_FILENAME" | |
echo "Uploading $OLDEST_FILENAME to S3..." | |
aws s3 cp --storage-class=GLACIER --force-glacier-transfer --only-show-errors $OLDEST_FILENAME s3://$S3_BUCKET_NAME | |
echo "Done Uploading. Moving to $COMPLETED_DIR..." | |
mv $OLDEST_FILENAME $COMPLETED_DIR | |
else | |
sleep 1s | |
fi | |
sleep 30s | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO:
QUEUE_DIR
.