Last active
September 1, 2020 04:31
-
-
Save daliborgogic/77ae6ac76b2bc922996c8e773699fb87 to your computer and use it in GitHub Desktop.
Delete files older than n in S3
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: . ./awss3deleteolderthan.sh [bucket] [path] "20 minutes ago" | |
endpoint="https://ams3.digitaloceanspaces.com" | |
aws s3 ls s3://$1/$2 --endpoint $endpoint --recursive | while read -r line; | |
do | |
createDate=`echo $line|awk {'print $1" "$2'}` | |
createDate=`date -d"$createDate" +%s` | |
olderThan=`date --date "$3" +%s` | |
if [[ $createDate -lt $olderThan ]]; then | |
fileName=`echo $line|awk {'print $4'}` | |
if [[ $fileName != "" ]] | |
then | |
aws s3 rm s3://$1/$fileName --endpoint $endpoint | |
fi | |
fi | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
expires
option is not implemented on Digital Ocean Spaces.