Created
March 10, 2012 09:34
-
-
Save aloon/2010980 to your computer and use it in GitHub Desktop.
download and delete from S3
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 'fileutils' | |
require 'aws/s3' | |
AWS_ACCESS_KEY_ID = '...' | |
AWS_SECRET_ACCESS_KEY = '...' | |
DOWNLOAD_DIR = 'files' | |
cont = true | |
while cont do | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => AWS_ACCESS_KEY_ID, | |
:secret_access_key => AWS_SECRET_ACCESS_KEY) | |
AWS::S3::Service.buckets.each{ |b| | |
puts 'bucket:' + b.name | |
cont = false if b.objects.size == 0 | |
b.objects.each{ |o| | |
puts o.key | |
if o.key[-12,12][0,8] == 'original' | |
k = Dir.pwd + '/' + DOWNLOAD_DIR + '/' + b.name + '/' + o.key | |
FileUtils.mkdir_p File.dirname(k) | |
myfile = File.open(k,'w') | |
myfile.puts o.value | |
o.delete | |
puts 'descargado' | |
else | |
o.delete | |
puts 'borrado' | |
end | |
} | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment