Created
December 13, 2022 22:46
-
-
Save kiwimato/ed4dcc1eba95b607f0aeed7cf30a8a6b to your computer and use it in GitHub Desktop.
Delete old versions in a Digital Ocean spaces bucket
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 | |
# Always run this command to first show the commands it will run(a dry run) | |
# Of course, modify the key and bucket name with your needs | |
aws s3api list-object-versions --endpoint=https://fra1.digitaloceanspaces.com --bucket dacia-public-bucket --key tmstories | jq -c '.Versions[] | select(.IsLatest == false) | " aws s3api delete-object --endpoint=https://fra1.digitaloceanspaces.com --bucket dacia-public-bucket --key \(.Key) --version-id \(.VersionId)"' -r | |
# and only then uncomment this line which actually deletes them: | |
#eval "$(aws s3api list-object-versions --endpoint=https://fra1.digitaloceanspaces.com --bucket dacia-public-bucket --key tmstories | jq -c '.Versions[] | select(.IsLatest == false) | " aws s3api delete-object --endpoint=https://fra1.digitaloceanspaces.com --bucket dacia-public-bucket --key \(.Key) --version-id \(.VersionId)"' -r)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment