Skip to content

Instantly share code, notes, and snippets.

@res0nat0r
Created May 1, 2019 21:29
Show Gist options
  • Save res0nat0r/df3d6fb4f9d8d1ddab37dd0f70898c91 to your computer and use it in GitHub Desktop.
Save res0nat0r/df3d6fb4f9d8d1ddab37dd0f70898c91 to your computer and use it in GitHub Desktop.
Restore s3 objects from glacier with boto
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)
@fotmasta
Copy link

Saved my bacon. Thanks!

@rafa0184
Copy link

rafa0184 commented Sep 6, 2022

This is script worked for me. Thank you

@res0nat0r
Copy link
Author

Good to hear!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment