Sha256: 6bd74c5557dee77b1f5db11276c233049d7831abcf97c95d78c853f9ea9a4182

Contents?: true

Size: 1.08 KB

Versions: 66

Compression:

Stored size: 1.08 KB

Contents

#!/usr/bin/env ruby

require 'optparse'
require 'aws-sdk-s3'

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: s3-copy options"

  opts.on("-r", "--region=REGION", "AWS region to use (default us-east-1)") do |v|
    options[:region] = v
  end

  opts.on("-p", "--param=KEY=VALUE", "Specify parameter for new files") do |v|
    options[:params] ||= {}
    k, v = v.split('=', 2)
    options[:params][k.to_sym] = v
  end

  opts.on("-f", "--from=BUCKET:PATH", "Bucket name and key (or path) to copy from") do |v|
    options[:from] = v
  end

  opts.on("-t", "--to=BUCKET:PATH", "Bucket name and key (or path) to write to (may be specified more than once)") do |v|
    options[:to] ||= []
    options[:to] << v
  end
end.parse!

ENV['AWS_REGION'] ||= options[:region] || 'us-east-1'

bucket, key = options.fetch(:from).split(':', 2)

s3 = Aws::S3::Client.new

options.fetch(:to).each do |dest|
  STDERR.puts "Copying to #{dest}"
  dbucket, dkey = dest.split(':', 2)
  s3.copy_object(
    bucket: dbucket,
    key: dkey,
    copy_source: "/#{bucket}/#{key}",
    **options[:params] || {},
  )
end

Version data entries

66 entries across 66 versions & 4 rubygems

Version Path
mogno-1.0.0 spec/shared/bin/s3-copy
mongoid-9.0.0 spec/shared/bin/s3-copy
mongo-2.20.0 spec/shared/bin/s3-copy
mongoid-8.0.8 spec/shared/bin/s3-copy
mongoid-8.1.5 spec/shared/bin/s3-copy
bson-5.0.0-java spec/shared/bin/s3-copy
bson-5.0.0 spec/shared/bin/s3-copy
mongoid-8.1.4 spec/shared/bin/s3-copy
mongo-2.19.3 spec/shared/bin/s3-copy
mongo-2.16.4 spec/shared/bin/s3-copy
mongo-2.17.4 spec/shared/bin/s3-copy
mongo-2.18.3 spec/shared/bin/s3-copy
mongo-2.19.2 spec/shared/bin/s3-copy
mongoid-8.0.7 spec/shared/bin/s3-copy
mongoid-8.1.3 spec/shared/bin/s3-copy
mongoid-8.1.2 spec/shared/bin/s3-copy
mongoid-8.0.6 spec/shared/bin/s3-copy
mongoid-7.5.4 spec/shared/bin/s3-copy
mongo-2.19.1 spec/shared/bin/s3-copy
mongoid-8.1.1 spec/shared/bin/s3-copy