Skip to content

Instantly share code, notes, and snippets.

@dgilperez
Forked from jaimeiniesta/copy_bucket.rb
Created April 27, 2012 19:23
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 dgilperez/2512036 to your computer and use it in GitHub Desktop.
Save dgilperez/2512036 to your computer and use it in GitHub Desktop.
Copy all files from a S3 bucket to another. Works between different S3 accounts.
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