Skip to content

Instantly share code, notes, and snippets.

@oivoodoo
Created March 6, 2013 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oivoodoo/5099330 to your computer and use it in GitHub Desktop.
Save oivoodoo/5099330 to your computer and use it in GitHub Desktop.
S3 buckets migration to another account.
source :rubygems
gem 'aws-sdk'
gem 'exceptional'
group :development do
gem 'heroku'
gem 'debugger'
end
require 'aws-sdk'
require 'json'
from_config = AWS.config.with(
access_key_id: ENV['from_access_key'],
secret_access_key: ENV['from_secret_acccess_key']
)
to_config = AWS.config.with(
access_key_id: ENV['to_access_key'],
secret_access_key: ENV['to_secret_acccess_key']
)
from_account = AWS::S3.new(config: from_config)
to_account = AWS::S3.new(config: to_config)
list = JSON.parse(ENV['list']) # "{from_bucket: new_bucket, from_bucket2: new_bucket2}"
list.each do |from, to|
from_bucket = from_account.buckets[from]
to_bucket = to_account.buckets[to]
begin
from_bucket.objects.each do |o|
o.copy_to(to_bucket.objects[o.key])
end
rescue Exception => ex
puts ex.message
end
end
worker: bundle exec ruby migration.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment