How do I disable Object Storage bucket versioning?
I followed your documentation guide to enable versioning on my buckets, but now I'd like to disable it. How can I do so?
2 Replies
This should be quite straightforward to accomplish with either Cyberduck or AWS CLI.
Cyberduck
For Cyberduck, disabling bucket versioning should be as simple as reversing these directions for enabling bucket versioning on your bucket.
AWS CLI
Disabling bucket versioning through AWS CLI is also quite easy to accomplish by setting the bucket's versioning status to Suspended
.
You may adapt this example command for the specifics of your bucket, making sure that its name and endpoint match that of your bucket's:
aws s3api put-bucket-versioning --endpoint=http://us-east-1.linodeobjects.com --bucket=bucket-versioning-example --versioning-configuration Status=Suspended
Conclusions
That should be all! You may need to delete hidden files in your buckets using Cyberduck or AWS CLI, but this should otherwise not present you any complications.
While disabling/suspending bucket versioning will help avoid creating more versions in the future, you'll still need to delete all the versions and delete markers for each file before you can delete the bucket. If you have a lot of these, a script could be helpful.
For example, if you run:
aws s3api list-object-versions --bucket $bucketname --endpoint=https://$endpointurl > object_versions.json
Note: substitute $bucketname
and $endpointurl
…and see a lot of versions and delete markers you could run a script like this:
#!/bin/bash
BUCKET_NAME="mybucket"
ENDPOINT="https://us-east-1.linodeobjects.com"
# Step 1: List all versions and delete markers
aws s3api list-object-versions --bucket "$BUCKET_NAME" --endpoint="$ENDPOINT" > object_versions.json
# Step 2: Parse the JSON output and delete each version and delete marker
jq -r '.Versions[] | {Key: .Key, VersionId: .VersionId} | @base64' object_versions.json | while read -r version; do
_jq() {
echo "${version}" | base64 --decode | jq -r "${1}"
}
KEY=$(_jq '.Key')
VERSION_ID=$(_jq '.VersionId')
echo "Deleting version: $VERSION_ID for key: $KEY"
aws s3api delete-object --bucket "$BUCKET_NAME" --key "$KEY" --version-id "$VERSION_ID" --endpoint="$ENDPOINT"
done
jq -r '.DeleteMarkers[] | {Key: .Key, VersionId: .VersionId} | @base64' object_versions.json | while read -r delete_marker; do
_jq() {
echo "${delete_marker}" | base64 --decode | jq -r "${1}"
}
KEY=$(_jq '.Key')
VERSION_ID=$(_jq '.VersionId')
echo "Deleting delete marker: $VERSION_ID for key: $KEY"
aws s3api delete-object --bucket "$BUCKET_NAME" --key "$KEY" --version-id "$VERSION_ID" --endpoint="$ENDPOINT"
done
# Clean up
rm object_versions.json
# (Optional)Remove the bucket
aws s3 rb "s3://$BUCKET_NAME" --force --endpoint="$ENDPOINT"
This will require you to interactively review each version and delete marker, so you might need to redirect the output of jq
to /dev/null
. But I didn't test that specifically since I didn't have an inordinate amount of versions in my bucket.