Created
June 24, 2020 06:35
-
-
Save kristm/7a965192d3a27b8931f38f32a41bf76e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'csv' | |
def usage | |
puts "s3_migrate.rb \nUsage: $0 <bucket_name> <input_csv>" | |
end | |
IMAGE = 0 | |
ORG_ID = 2 | |
CLASS_ID = 3 | |
YEAR = 4 | |
MONTH = 5 | |
def main | |
if ARGV.size < 2 | |
usage() | |
exit | |
end | |
bucket = ARGV[0] | |
csv = CSV.read(ARGV[1], {}).to_a | |
csv.each do |row| | |
puts "processing #{row[IMAGE]}" | |
copy_command = "aws s3 cp s3://#{bucket}/#{row[IMAGE]} s3://#{bucket}/#{row[ORG_ID]}/#{row[CLASS_ID]}/#{row[YEAR]}/#{row[MONTH]}/#{row[IMAGE]}" | |
system copy_command | |
end | |
end | |
main if __FILE__ == $0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment