Skip to content

Instantly share code, notes, and snippets.

@leventyalcin
Last active October 14, 2016 18:37
Show Gist options
  • Save leventyalcin/7ac3a8a89d9e65a18eb3 to your computer and use it in GitHub Desktop.
Save leventyalcin/7ac3a8a89d9e65a18eb3 to your computer and use it in GitHub Desktop.
Recover deleted files on Amazon S3
aws --output=text --profile=PROFILE s3api list-object-versions --bucket BUCKET_NAME --region=REGION --prefix=DIRNAME \
| grep -e "DELETEMARKERS\tTrue" \
| while read LINE \
do \
KEY=`echo $LINE | awk '{print $3}'` VERSION=`echo $LINE | awk '{print $NF}'` \
aws --profile=PROFILE s3api delete-object --bucket BUCKET_NAME --key $KEY --version-id $VERSION --region=REGION \
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment