Created
February 17, 2021 07:49
-
-
Save Diablo2050/32f74de0a15d6a1d6b6daad97a09ef55 to your computer and use it in GitHub Desktop.
S3 recover deleted folders with versioning enabled.
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 | |
# if you have profiles other than default unhash the below line and profide the profile name | |
#export AWS_PROFILE=NAME | |
recoverfiles=$(aws s3api list-object-versions --bucket BUCKET_NAME --prefix FOLDER_NAME/ --query "DeleteMarkers[?IsLatest && starts_with(LastModified,'2021-02-16')].{Key:Key,VersionId:VersionId}") | |
for row in $(echo "${recoverfiles}" | jq -c '.[]'); do | |
key=$(echo "${row}" | jq -r '.Key' ) | |
# versionId=$(echo "${row}" | jq -r '.VersionId' ) | |
aws s3api delete-object --bucket inno-themes-prod --key $key --version-id null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From
https://stackoverflow.com/questions/45207055/undelete-folders-from-aws-s3#:~:text=You%20cannot%20undelete%20a%20common,will%20reverse%20the%20deletion%2C%20or