Created
November 6, 2014 19:25
-
-
Save mikeadmire/6031cb6e0210154fda98 to your computer and use it in GitHub Desktop.
Read a list of files from a text file and use the ruby AWS SDK to restore them from Glacier storage.
This file contains 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 ruby | |
require 'aws-sdk' | |
require 'logger' | |
s3 = AWS::S3.new( | |
access_key_id: '<ACCESS KEY>', | |
secret_access_key: '<SECRET KEY>' | |
) | |
logger = Logger.new('./s3_restores.log') | |
bucket = s3.buckets['<BUCKET NAME>'] | |
File.foreach('./files_to_restore.txt') do |line| | |
line.chomp! | |
logger.info("restoring #{line}") | |
begin | |
object = bucket.objects[line] | |
object.restore(options = {days: 5}) | |
rescue => e | |
logger.error("#{e}:: #{line}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text file with file names to be restored should be the full object name (full path) excluding the bucket name.
Example:
All restores from Glacier are temporary. The default for the SDK is 1 day (last I checked), so I'm overwriting that to 5 days here. In order to permanently restore a file from Glacier you need to change the storage type from Glacier. One method of doing this is to execute a copy on the file or bucket to overwrite the existing Glacier file with the restored file. This only works after the file has been restored.
Change storage class for one file:
Change storage class for all files in a bucket: