Skip to content

Instantly share code, notes, and snippets.

@JonCrawford
Created July 3, 2009 19:08
Show Gist options
  • Save JonCrawford/140268 to your computer and use it in GitHub Desktop.
Save JonCrawford/140268 to your computer and use it in GitHub Desktop.
s3_config = YAML.load_file(RAILS_ROOT + "/config/amazon_s3.yml")
s3_config = s3_config['staging'].to_options
@s3 = RightAws::S3.new(s3_config[:access_key_id], s3_config[:secret_access_key])
@s3_interface = RightAws::S3Interface.new(s3_config[:access_key_id], s3_config[:secret_access_key])
to_bucket = @s3.bucket(<bucket_name>)
to_bucket = @s3.bucket(<bucket_name>)
keys = from_bucket.keys('prefix' => 'background_images')
keys.each do |key|
(1..10).each do |try|
begin
puts "Copying #{from_bucket.name}/#{key.name} to #{to_bucket.name}/#{key.name}"
from_bucket.s3.interface.copy(from_bucket.name, key.name, to_bucket.name, key.name)
from_acl = @s3_interface.get_acl(from_bucket.name, key.name)
@s3_interface.put_acl(to_bucket.name, key.name, from_acl[:object])
break
rescue Exception => e
puts "problem, trying again..."
sleep 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment