Created
July 4, 2012 08:32
-
-
Save yannski/3046102 to your computer and use it in GitHub Desktop.
Copy from one Amazon S3 bucket to another with two different accounts
This file contains hidden or 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 '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