Created
July 29, 2019 15:26
-
-
Save emzo/5b797c4a8ca77fe45668517dc3a731fc to your computer and use it in GitHub Desktop.
Undelete files form Amazon S3 (versioned buckets only)
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ sh s3undelete.sh “bucket” “path/to/files/”