Created
July 28, 2015 14:09
-
-
Save Voronenko/1b11d86dda9674b56dc7 to your computer and use it in GitHub Desktop.
Removes backups older than N days from S3 bucket using s3cmd tool
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 | |
# Usage: ./cleanup_s3_bucket "bucketname" "90 days" | |
s3cmd ls s3://$1 | while read -r line; | |
do | |
createDate=`echo $line|awk {'print $1" "$2'}` | |
createDate=`date -d"$createDate" +%s` | |
olderThan=`date -d"-$2" +%s` | |
if [[ $createDate -lt $olderThan ]] | |
then | |
fileName=`echo $line|awk {'print $4'}` | |
echo $fileName | |
if [[ $fileName != "" ]] | |
then | |
s3cmd del "$fileName" | |
fi | |
fi | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment