Created
May 1, 2019 21:29
-
-
Save res0nat0r/df3d6fb4f9d8d1ddab37dd0f70898c91 to your computer and use it in GitHub Desktop.
Restore s3 objects from glacier with boto
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
import boto3 | |
s3 = boto3.resource('s3') | |
bucket = s3.Bucket('glacier-bucket') | |
for obj_sum in bucket.objects.all(): | |
obj = s3.Object(obj_sum.bucket_name, obj_sum.key) | |
if obj.storage_class == 'GLACIER': | |
# Try to restore the object if the storage class is glacier and | |
# the object does not have a completed or ongoing restoration | |
# request. | |
if obj.restore is None: | |
print('Submitting restoration request: %s' % obj.key) | |
obj.restore_object(RestoreRequest={'Days': 1}) | |
# Print out objects whose restoration is on-going | |
elif 'ongoing-request="true"' in obj.restore: | |
print('Restoration in-progress: %s' % obj.key) | |
# Print out objects whose restoration is complete | |
elif 'ongoing-request="false"' in obj.restore: | |
print('Restoration complete: %s' % obj.key) |
This is script worked for me. Thank you
Good to hear!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Saved my bacon. Thanks!