Skip to content

Instantly share code, notes, and snippets.

@bgkittrell
Created February 4, 2013 14:36
Show Gist options
  • Save bgkittrell/4707053 to your computer and use it in GitHub Desktop.
Save bgkittrell/4707053 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'fog'
require 'find'
require 'set'
# create a connection
connection = Fog::Storage.new({
:provider => 'AWS',
:aws_access_key_id => 'XXXXX',
:aws_secret_access_key => 'XXXXX'
})
s3root = connection.directories.get('dk-media')
fsroot = '/backup/doodlekit/media/AA/'
threads = []
written = File.readlines("writes-cut.log").to_set
start = Time.now
for dir in Dir.entries(fsroot).reject { |d| d =~ /^\./ }.sort.reverse
threads << Thread.new(dir) do |mydir|
for sitedir in Dir.entries(File.join(fsroot, mydir)).reject { |d| d =~ /^\./ }.sort.reverse
puts "Site Directory: #{mydir}/#{sitedir}"
Find.find(File.join(fsroot, mydir, sitedir)) do |path|
s3path = path.slice(24, path.length)
cutpath = path.slice(30, path.length)
begin
if (s3path.index('.') or !File.directory?(path)) and !path.index('/tmp/') and !written.include?("#{cutpath}\n")
s3root.files.create(
:key => s3path,
:body => File.new(path),
:public => true
)
puts "#{path} Written"
File.open "writes-cut.log", "a" do |file|
file.write cutpath + "\n"
end
end
rescue
puts $!
end
end
end
puts "Finished: #{mydir}"
end
end
for thread in threads
thread.join
end
puts Time.now - start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment