Last active
July 6, 2017 10:15
-
-
Save nigelheap/5826ba6e82018f85c65932f8dbe0560d to your computer and use it in GitHub Desktop.
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
# arg1 : bucket | |
# arg2 : max sub folders / days | |
total=`s3cmd ls s3://$1/ | wc -l` | |
# remove old folders if move then max | |
if [ "$total" -gt "$2" ] | |
then | |
# clean up s3 backups | |
s3cmd ls s3://$1/ | while read -r line; | |
do | |
createDate=`echo $line|awk {'print $1" "$2'}` | |
folder=`echo $line|awk {'print $2'}` | |
folderDate=`echo $folder|awk -F\/ {'print $5'}` | |
createDate=`date -d"$folderDate" +%s` | |
olderThan=`date -d"-$2 days" +%s` | |
if [[ $createDate != "" && $createDate -lt $olderThan ]] | |
then | |
if [[ $folder != "" ]] | |
then | |
folder=${folder:0:-1} | |
s3cmd del --recursive "$folder" | |
echo "Deleted $folder" | |
fi | |
fi | |
done; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment