Skip to content

Commit

Permalink
Only pull and move file if ETag has changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
talaris committed Aug 18, 2015
1 parent 3e4f008 commit 8bfc50f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sync.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash -e
CURRENT_ETAG=''

if [ -z "$S3_BUCKET" ] || [ -z "$S3_KEY" ] || [ -z "$DESTINATION" ]; then
echo "Must set S3_BUCKET, S3_KEY, and DESTINATION env vars" 1>&2
Expand All @@ -18,6 +19,12 @@ fi
##
# Fetch file for S3, move it in place atomically
function do_sync {
FILE_ETAG=$(aws s3api head-object --bucket $S3_BUCKET --key $S3_KEY | grep -i etag | tr -d ',')
if [ $FILE_ETAG == $CURRENT_ETAG ]; then
return 0
fi
CURRENT_ETAG=$FILE_ETAG

aws s3api get-object --bucket $S3_BUCKET --key $S3_KEY /tmp/out > /dev/null

# Optionally set file permissions
Expand Down

0 comments on commit 8bfc50f

Please sign in to comment.