Skip to content

Instantly share code, notes, and snippets.

@strukturedkaos
Created July 1, 2014 01:10
Show Gist options
  • Save strukturedkaos/afc2a81305af5e3cc285 to your computer and use it in GitHub Desktop.
Save strukturedkaos/afc2a81305af5e3cc285 to your computer and use it in GitHub Desktop.
Copy files between AWS S3 buckets
s3.buckets['kickdrop-production-assets'].objects['uploads/'].copy_to('uploads/', :bucket_name => 'kickdrop-staging-assets')
source_bucket='kickdrop-production-assets'
target_bucket='kickdrop-staging-assets'
source_key = 'uploads'
target_key = 'uploads'
bucket1 = s3.buckets[source_bucket]
bucket2 = s3.buckets[target_bucket]
obj1 = bucket1.objects.with_prefix("uploads")
obj2 = bucket2.objects.with_prefix("uploads")
target_bucket='kickdrop-staging-assets'
bucket1.objects.with_prefix("uploads").each do |object|
obj2 = bucket2.objects.with_prefix("uploads")[object.key]
object.copy_to(obj2, bucket_name: 'target_bucket', acl: :public_read)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment