Skip to content

Instantly share code, notes, and snippets.

@peterkuiper
Last active August 27, 2015 11:02
Show Gist options
  • Select an option

  • Save peterkuiper/898364f4180bae8309d0 to your computer and use it in GitHub Desktop.

Select an option

Save peterkuiper/898364f4180bae8309d0 to your computer and use it in GitHub Desktop.

Revisions

  1. Peter Kuiper revised this gist Aug 27, 2015. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,11 @@
    Delete all object versions from a bucket:
    # Delete all object versions from a bucket:

    aws --output text s3api list-object-versions --bucket <your bucket> | grep -E "^VERSIONS" | awk '{print "aws s3api delete-object --bucket <your bucket> --key "$4" --version-id "$8";"}'

    Delete all deletion markers from a bucket:
    # Delete all deletion markers from a bucket:

    aws --output text s3api list-object-versions --bucket <your bucket> | grep -E "^DELETEMARKERS" | awk '{print "aws s3api delete-object --bucket <your bucket> --key "$3" --version-id "$5";"}'
    aws --output text s3api list-object-versions --bucket <your bucket> | grep -E "^DELETEMARKERS" | awk '{print "aws s3api delete-object --bucket <your bucket> --key "$3" --version-id "$5";"}'

    # Bucket size

    aws s3api list-objects --bucket sc-backup-bucket --output json --query "[sum(Contents[].Size), length(Contents[])]"
  2. Peter Kuiper created this gist Aug 26, 2015.
    7 changes: 7 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    Delete all object versions from a bucket:

    aws --output text s3api list-object-versions --bucket <your bucket> | grep -E "^VERSIONS" | awk '{print "aws s3api delete-object --bucket <your bucket> --key "$4" --version-id "$8";"}'

    Delete all deletion markers from a bucket:

    aws --output text s3api list-object-versions --bucket <your bucket> | grep -E "^DELETEMARKERS" | awk '{print "aws s3api delete-object --bucket <your bucket> --key "$3" --version-id "$5";"}'