Skip to content

Instantly share code, notes, and snippets.

@acg
Created August 25, 2021 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acg/2b3b396c9556b62ca70754ea11392943 to your computer and use it in GitHub Desktop.
Save acg/2b3b396c9556b62ca70754ea11392943 to your computer and use it in GitHub Desktop.
Delete all old version markers in an S3 bucket. Be extremely careful!
#!/bin/sh
set -e
BUCKET="$1" ; shift
BATCH_SIZE=100
aws s3api list-object-versions --bucket "$BUCKET" |
jq '[.DeleteMarkers[] | {Key, VersionId}]' |
jq -c "_nwise($BATCH_SIZE) | {Objects:., Quiet:false}" |
tr '\n' '\0' |
xargs -0 -n1 aws s3api delete-objects --bucket "$BUCKET" --delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment