Created
September 12, 2012 06:34
-
-
Save lazypower/3704724 to your computer and use it in GitHub Desktop.
Call Center Recording Dump - Push to S3
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 | |
#Utility to perform routine backups for CallCenter Recordings | |
require 'rubygems' | |
require 'aws/s3' | |
#Parent of directory tree for recordings | |
directory = ARGV.shift | |
#We're shipping the output to S3, so we need to define creds | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => '', | |
:secret_access_key => '' | |
) | |
#parent method that controls execution flow | |
# traverse directories using recursion | |
def processdir(directory) | |
Dir.chdir(directory) | |
Dir.foreach(Dir.getwd) do |dir| | |
next if dir == '.' or dir == '..' | |
unless File.directory?(dir) | |
#known assumption - the format here is Affiliate / Date - so use that to set the bucket | |
wd = File.absolute_path(dir).split('/') | |
remote_path = wd[wd.length - 3] + "/" + wd[wd.length - 2] | |
puts "Uploading #{remote_path}/#{dir}" | |
#Send the archive off to target, the S3 bucket | |
AWS::S3::S3Object.store( | |
dir, | |
open(dir), | |
"recording-backup/#{remote_path}" | |
) | |
else | |
puts "Found directory #{dir}... changing working directory" | |
#recursively call same method if we hit another directory | |
processdir(dir) | |
end | |
end | |
#puts CWD one directory above current | |
puts "Finished processing directory - returning one level" | |
Dir.chdir('..') | |
end | |
#kick it off, and run the method | |
processdir(directory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment