Skip to content

Instantly share code, notes, and snippets.

@n2p5
Created September 30, 2020 04:33
Show Gist options
  • Save n2p5/b311a722619acb19162e26f991b9e5ea to your computer and use it in GitHub Desktop.
Save n2p5/b311a722619acb19162e26f991b9e5ea to your computer and use it in GitHub Desktop.
undelete s3 objects that are marked for delete from versioned s3
aws s3api list-object-versions \
--bucket "${BUCKET}" \
--prefix "${PREFIX}" \
--output text | grep "DELETEMARKERS" | while read obj
do
KEY=$( echo "${obj}"| awk '{print "${3}"}')
VERSION_ID=$( echo "${obj}" | awk '{print "${5}"}')
echo "${KEY}"
echo "${VERSION_ID}"
aws s3api delete-object \
--bucket "${BUCEKT}" \
--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