-
Notifications
You must be signed in to change notification settings - Fork 0
/
cenarius
executable file
·58 lines (45 loc) · 1.4 KB
/
cenarius
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/ruby
BASE_DIR = File.expand_path(File.dirname(__FILE__))
require 'rubygems'
require 'yaml'
require 'ostruct'
require 'cloudfiles'
require 'duration'
require BASE_DIR + '/lib/float'
require 'date'
config = OpenStruct.new(YAML::load_file(BASE_DIR + '/config.yml'))
print "Connecting to RackSpace CloudFiles... "
cf = CloudFiles::Connection.new(config.username, config.api_key)
print "OK!\n"
Dir.chdir "/tmp"
date = Date.today
suffix = date.strftime "%Y%m%d"
config.backups.each do |cont, base_dirs|
puts ">> Processing #{cont}..."
unless cf.container_exists? cont
puts " ### Container did not exist and was created ###"
cf.create_container cont
end
container = cf.container(cont)
base_dirs.each do |base_dir, folders|
folders.each do |folder|
filename = "#{folder}_#{suffix}.tar"
time = Time.now
print " > Processing #{base_dir}/#{folder}... "
system("tar -cf #{filename} #{base_dir}/#{folder} 2> /dev/null")
system("gzip #{filename}")
filename = filename + '.gz'
print "uploading #{File.size(filename).to_f.humanize}... "
file = container.create_object(filename, true)
file.load_from_filename(filename)
elapsed = Time.now - time
if elapsed < 1
print "less than a second.\n"
else
print Duration.new(elapsed).to_s + ".\n"
end
end
end
end
puts "Cleaning up..."
system("rm -f /tmp/*.tar.gz")