Forked from mchv/find-incomplete-s3-multipart-upload.sh
Created
October 24, 2019 15:14
-
-
Save mbaetaoliveira/e08eabc24a6c18bad3f69e7793855a4b to your computer and use it in GitHub Desktop.
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
for bucket in $(aws s3api list-buckets --query 'Buckets[*].{Name:Name}' --output text) | |
do | |
echo "$bucket:" | |
region=$(aws s3api get-bucket-location --bucket $bucket --query 'LocationConstraint' --output text | awk '{sub(/None/,"eu-west-1")}; 1') | |
parts=$(aws s3api list-multipart-uploads --bucket $bucket --region $region --query 'Uploads[*].{Key:Key,UploadId:UploadId}' --output text) | |
if [ "$parts" != "None" ]; then | |
IFS=$'\n' | |
for part in $parts | |
do | |
keyname=$(echo $part | awk '{print $1}') | |
upload_id=$(echo $part | awk '{print $2}') | |
id_size=$(aws s3api list-parts --upload-id $upload_id --bucket $bucket --key $keyname | grep "Size" | egrep -o '[0-9]+' | awk '{ SUM += $1} END { print SUM }') | |
echo "size: $id_size bytes" | |
# uncomment below to delete instead of printing the size | |
#aws s3api abort-multipart-upload --bucket --key $keyname --upload-id $upload_id | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment