Skip to content

Instantly share code, notes, and snippets.

@danwald
Last active August 29, 2015 14:19
Show Gist options
  • Save danwald/ed77befe1a82ae7ce63f to your computer and use it in GitHub Desktop.
Save danwald/ed77befe1a82ae7ce63f to your computer and use it in GitHub Desktop.
S3: sync last 7 days from bucket to local
#!/bin/bash
set -e
function get_include_string()
{
local str=""
for i in {7..0}
do
str+="--include \""
str+=`date --date="$i days ago" +"*%Y/%m/%d/*"`
str+="\" "
done
echo $str
}
S3_FOLDER=""
LOCAL_FOLDER=""
INCL_STR=$(get_include_string)
LOG_FILE=""
cmd="aws s3 sync $S3_FOLDER $LOCAL_FOLDER --delete --exclude \"*\" $INCL_STR 2>&1 >> $LOG_FILE"
eval $cmd
aws s3 sync s3://<bucket> <local> --delete --include "`for i in {30..0}; do date --date="$i days ago" +"%Y/%m/%d"; done`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment