Skip to content

Instantly share code, notes, and snippets.

@aloon
Created March 10, 2012 09:34
Show Gist options
  • Save aloon/2010980 to your computer and use it in GitHub Desktop.
Save aloon/2010980 to your computer and use it in GitHub Desktop.
download and delete from S3
#!/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