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
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)