Created
April 12, 2012 22:30
-
-
Save jaimeiniesta/2371467 to your computer and use it in GitHub Desktop.
Copy all files from a S3 bucket to another. Works between different S3 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
require 'right_aws' | |
s3_credentials = { | |
:source_key => "...", | |
:source_secret => "...", | |
:source_bucket => "...", | |
:destination_key => "...", | |
:destination_secret => "...", | |
:destination_bucket => "..." | |
} | |
puts "Start copying files..." | |
s3_source = RightAws::S3.new(s3_credentials[:source_key], s3_credentials[:source_secret]) | |
source_bucket = s3_source.bucket(s3_credentials[:source_bucket]) | |
s3_destination = RightAws::S3.new(s3_credentials[:destination_key], s3_credentials[:destination_secret]) | |
destination_bucket = s3_destination.bucket(s3_credentials[:destination_bucket]) | |
source_bucket.keys.each_with_index do |source_file, i| | |
puts "#{i}.- Copying #{source_file.name} to #{s3_credentials[:destination_bucket]}" | |
destination_file = RightAws::S3::Key.create(destination_bucket, source_file.name) | |
destination_file.put(source_file.data) | |
end | |
puts "Finished!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment