Last active
September 10, 2021 12:56
-
-
Save thecfguy/ad7e401499619039bf51c1628e5c9cba 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
BUCKET_NAME=YOUR_BUCKKET_NAME | |
KEY_PREFIX="folder/to/restore" | |
# list all files having deleteMarker as latest version, you may use to confirm versionid. | |
aws s3api list-object-versions --bucket $BUCKET_NAME --prefix $KEY_PREFIX --query 'DeleteMarkers[?IsLatest==`true`]' | |
# this will actually restore all files by deleting delete marker from deleted files. | |
aws s3api list-object-versions --bucket $BUCKET_NAME --prefix $KEY_PREFIX --output json --query 'DeleteMarkers[?IsLatest==`true`].[Key, VersionId]' | jq -r '.[] | "--key '\''" + .[0] + "'\'' --version-id " + .[1]' | xargs -L1 aws s3api delete-object --bucket $BUCKET_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment