Created
September 3, 2015 21:00
-
-
Save senderista/fa8fb3e7c6d5ffc346eb to your computer and use it in GitHub Desktop.
Delete all delete markers in a versioned S3 bucket, to "undelete" all deleted objects that still have a version before the delete marker
This file contains hidden or 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
| #!/usr/bin/env python | |
| import sys | |
| import boto | |
| bucket_name = sys.argv[1] | |
| s3 = boto.connect_s3() | |
| bucket = s3.get_bucket(bucket_name) | |
| for v in bucket.list_versions(): | |
| if isinstance(v, boto.s3.deletemarker.DeleteMarker) and v.is_latest: | |
| print v.name, v.version_id, v.last_modified | |
| bucket.delete_key(v.name, version_id=v.version_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment