JadedEvan
3/29/2010 - 10:37 PM

Copy files from one S3 bucket to another

Copy files from one S3 bucket to another

#!usr/bin/env ruby

# This script takes a list of filenames from a given file and copies
# each of those files from one S3 bucket to another using the s3mcd library.
# Inputfile should have each filename termination by a newline character.

file, from, to = ARGV[0], ARGV[1], ARGV[2]

if file.nil? || from.nil? || to.nil?
  puts "Invalid arguements. Should be filename from-s3-bucket to-s3-bucket"
  exit
end

sizes = %w{106x 145x}

file = File.open(file, 'r')
file.each_line do |filename|
  sizes.each do |size|
    puts `s3cmd cp --acl-public s3://#{from}/Item/#{size}/#{filename.strip} s3://#{to}/Item/#{size}/#{filename.strip}`
  end
end