S3 bucket versioning can be a lifesaver. If you accidentally delete an object, you can restore it in the S3 Management Console by deleting the Delete Marker:
But what if you’ve deleted more than a handful of objects? boto to the rescue. Adjust BUCKET_NAME
and DELETE_DATE
to suit.
#!/usr/bin/env python import boto BUCKET_NAME = "examplebucket" DELETE_DATE = "2015-06-08" bucket = boto.connect_s3().get_bucket(BUCKET_NAME) for v in bucket.list_versions(): if (isinstance(v, boto.s3.deletemarker.DeleteMarker) and v.is_latest and DELETE_DATE in v.last_modified): bucket.delete_key(v.name, version_id=v.version_id)
Thanks for the script, this was indeed a lifesaver!
Your code saved my life! Thank you…
We added a little tweak, file counter.
https://gist.github.com/anonymous/3937ca3aaceb5f83e13968a309a395dd
thank you its working nice!!!