Skip to content

Instantly share code, notes, and snippets.

@joshnuss
Last active September 27, 2015 00:58
Show Gist options
  • Save joshnuss/1186957 to your computer and use it in GitHub Desktop.
Save joshnuss/1186957 to your computer and use it in GitHub Desktop.
Copy S3 bucket
require 'right_aws'
old_name = "old-bucket"
new_name = "new-bucket"
s3 = RightAws::S3.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
old_bucket = s3.bucket(old_name)
new_bucket = s3.bucket(new_name)
old_bucket.keys.each do |old_key|
puts "Copying #{old_key.name} to #{new_bucket.name}"
new_key = RightAws::S3::Key.create(new_bucket, old_key.name)
old_key.copy(new_key)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment