Created
July 26, 2023 17:56
-
-
Save wrburgess/f03fe229bd2cbdc5e335a479d7992a48 to your computer and use it in GitHub Desktop.
aws cli s3 delete all delete markers from bucket bash script
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 | |
export AWS_PAGER="" | |
bucket_name="bucket-name" | |
# List all versions in the bucket | |
versions=$(aws s3api list-object-versions --bucket $bucket_name --query 'DeleteMarkers') | |
# Loop through the list of delete markers and delete each one | |
for version in $(echo "$versions" | jq -r '.[] | @base64'); do | |
version_json=$(echo "$version" | base64 --decode) | |
version_id=$(echo "$version_json" | jq -r '.VersionId') | |
key=$(echo "$version_json" | jq -r '.Key') | |
# Delete the delete marker | |
aws s3api delete-object --bucket $bucket_name --key "$key" --version-id $version_id | |
# echo "Deleted delete marker for: $key (Version ID: $version_id)" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment