-
-
Save danwald/ed77befe1a82ae7ce63f to your computer and use it in GitHub Desktop.
S3: sync last 7 days from bucket to local
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 | |
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 | |
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
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