Created
July 26, 2022 11:14
-
-
Save flavono123/f89fcd5defb9c70886cb76113b89fbf0 to your computer and use it in GitHub Desktop.
Sum incomplete multipart upload sizes in AWS S3
This file contains hidden or 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 | |
| # ref. https://stackoverflow.com/questions/43192556/using-jq-with-bash-to-run-command-for-each-object-in-array | |
| bucket=$1 | |
| aws s3api list-multipart-uploads --bucket "${bucket}" | \ | |
| jq -r '.Uploads[] | [.UploadId, .Key] | @tsv' | \ | |
| while IFS=$'\t' read -r upload_id key; do | |
| AWS_PAGER="" aws s3api list-parts --bucket "${bucket}" --key "${key}" --upload-id "${upload_id}" | |
| done | \ | |
| jq 'select(has("Parts")) | .Parts[].Size' | \ | |
| paste -sd+ | bc | numfmt --to=iec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment