Skip to content

Instantly share code, notes, and snippets.

@jaimeiniesta
Created April 12, 2012 22:30
Show Gist options
  • Select an option

  • Save jaimeiniesta/2371467 to your computer and use it in GitHub Desktop.

Select an option

Save jaimeiniesta/2371467 to your computer and use it in GitHub Desktop.

Revisions

  1. jaimeiniesta created this gist Apr 12, 2012.
    27 changes: 27 additions & 0 deletions copy_bucket.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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!"