Skip to content

Instantly share code, notes, and snippets.

@emzo
Created July 29, 2019 15:26
Show Gist options
  • Save emzo/5b797c4a8ca77fe45668517dc3a731fc to your computer and use it in GitHub Desktop.
Save emzo/5b797c4a8ca77fe45668517dc3a731fc to your computer and use it in GitHub Desktop.
Undelete files form Amazon S3 (versioned buckets only)
#!/bin/bash
BUCKET=$1
PREFIX=$2
aws s3api list-object-versions --bucket $BUCKET --prefix $PREFIX --output text |
grep "DELETEMARKERS" | while read OBJECTS
do
KEY=$( echo $OBJECTS| awk '{print $3}')
VERSION_ID=$( echo $OBJECTS | awk '{print $5}')
echo $KEY
echo $VERSION_ID
aws s3api delete-object --bucket $BUCKET --key $KEY --version-id $VERSION_ID
done
@emzo
Copy link
Author

emzo commented Jul 29, 2019

$ sh s3undelete.sh “bucket” “path/to/files/”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment