Skip to content

Instantly share code, notes, and snippets.

@deogracia
Created February 7, 2021 10:08
Show Gist options
  • Save deogracia/f23b7957a8b4af972ff495a11a4d7d06 to your computer and use it in GitHub Desktop.
Save deogracia/f23b7957a8b4af972ff495a11a4d7d06 to your computer and use it in GitHub Desktop.
undelete files from a deleted directory, s3 bucket with versioning enabled
# taken from https://superuser.com/a/1019940
MY_BUCKET=yourbucket-name
MY_PREFIX=my-directory
echo '#!/usr/bin/env bash' > undeleteScript.sh && aws --output text s3api list-object-versions --bucket ${MY_BUCKET} --prefix ${MY_PREFIX} | grep -E "^DELETEMARKERS" | awk '{FS = "[\t]+"; print "aws s3api delete-object --bucket ${MY_BUCKET} --key \42"$3"\42 --version-id "$5";"}' >> undeleteScript.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment