Skip to content

Instantly share code, notes, and snippets.

@yannski
Created July 4, 2012 08:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yannski/3046102 to your computer and use it in GitHub Desktop.
Save yannski/3046102 to your computer and use it in GitHub Desktop.
Copy from one Amazon S3 bucket to another with two different accounts
#!/usr/bin/env ruby
require 'rubygems'
require 'right_aws'
# it's possible to copy files from one bucket to another, even it the account is not the same
# in that case, the original file should be public
srcBkt = 'XXX'
destBkt = 'YYY'
# Put credentials of destination account
old_account = RightAws::S3Interface.new('access_key_1', 'secret_access_key_1')
new_account = RightAws::S3Interface.new('access_key_2', 'secret_access_key_2')
i = 0
old_account.incrementally_list_bucket(srcBkt){|h|
h[:contents].each{|o|
key = o[:key]
puts "##{i} #{key} moved"
begin
new_account.copy(srcBkt, key, destBkt, key, :copy, { 'x-amz-acl' => 'public-read' })
rescue e
puts e.inspect
end
i+=1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment