Created
October 10, 2016 16:00
-
-
Save erronjason/cc42da83f7582ba61afc8a9830e00c16 to your computer and use it in GitHub Desktop.
Scripts aws-cli to get and push images
This file contains hidden or 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 | |
# Syncs s3 images back and forth for the uploads dir | |
# | |
# Manual commands: | |
# aws s3 sync s3://bucket-name/uploads/ . #Remote bucket to local | |
# aws s3 sync . s3://bucket-name/uploads/ #Local to remote bucket | |
usage=" | |
Usage: | |
$0 (get|put)" | |
if [ $# -ne 1 ]; then | |
echo $usage | |
exit 1 | |
fi | |
arg1=$1 | |
# EXCLUDE='--exclude="somedir/" --exclude="another-dir/"' | |
SCRIPTDIR=$(dirname $0) # Sets a defined start point | |
function get_s3_images { | |
aws s3 sync s3://bucket-name/uploads/ $SCRIPTDIR/../public_html/uploads $EXCLUDE | |
} | |
function put_s3_images { | |
aws s3 sync $SCRIPTDIR/../public_html/uploads s3://bucket-name/uploads/ $EXCLUDE | |
} | |
if [[ $arg1 == "get" ]]; then | |
echo "Syncing images in S3 to local..." | |
get_s3_images | |
echo "Complete!" | |
exit 0 | |
elif [[ $arg1 == "put" ]]; then | |
echo "Syncing local images to S3..." | |
put_s3_images | |
echo "Complete!" | |
exit 0 | |
else | |
echo "Unknown command \"$arg1\"" | |
echo $usage | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes the script resides in a folder parallel to a public_html/ and throws it in public_html/uploads. I'm not concerned with cleaning up the static paths/manual excludes unless this is specifically requested.