Skip to content

Instantly share code, notes, and snippets.

@kiwimato
Created December 13, 2022 22:46
Show Gist options
  • Save kiwimato/ed4dcc1eba95b607f0aeed7cf30a8a6b to your computer and use it in GitHub Desktop.
Save kiwimato/ed4dcc1eba95b607f0aeed7cf30a8a6b to your computer and use it in GitHub Desktop.
Delete old versions in a Digital Ocean spaces bucket
#!/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