-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_all
More file actions
executable file
·113 lines (100 loc) · 2.92 KB
/
sync_all
File metadata and controls
executable file
·113 lines (100 loc) · 2.92 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env ruby
NETWORK = '10.99.'
SERVERS = [
[],
['0100','0101','0102','0103','0104'],
['0200','0201','0202','0203','0204'],
['0300','0301','0302','0303','0304']
]
if ARGV.size != 1
puts "Usage: #{$0} RACK"
puts " RACK - rack number (1,2, or 3)"
exit 1
end
#add some color to our lives
if ENV["TERM"] == "dumb"
RED=GREEN=BLANK=YELLOW=BLUE=""
else
RED ="\033[1;31m"
GREEN ="\033[1;32m"
YELLOW="\033[1;33m"
BLUE ="\033[1;34m"
BLANK ="\033[0m"
end
REMOVE = [ /^\s*sending incremental file list\s*$\n?/m, /^\s*sent .* bytes received .* bytes .* bytes\/sec\s*$\n?/m, /\s*total size is .* speedup is .*\s*\n?/m, /^\s*$\n?/m ]
class String
def indent
self.gsub(/^/," ")
end
end
def display_results(array)
array.sort.each do |obj|
server = obj[0]
out = obj[1]
puts "\n\n#{BLUE}Output for #{YELLOW}#{server}#{BLANK}\n"
puts out.indent
end
end
def exec(banner, cmd)
#out = "#{cmd}"
out = `#{cmd}`
REMOVE.each do |rem|
out.gsub!(rem,'')
end
out += "\n" unless out == ""
#success = true
success = $?.success?
if success
out += "#{GREEN}Succeded#{BLANK}"
else
out += "#{RED}Failed#{BLANK}"
end
["\n#{BLUE}#{banner}#{BLANK}\n"+out.indent, success]
end
goods = []
bads = []
threads = []
2.times { puts "" }
SERVERS[ARGV[0].to_i].each do |server_id|
server = NETWORK+sprintf("%d", server_id.to_i(16) >> 8)+'.'+sprintf("%d", server_id.to_i(16) & 0xff)
rack_id = sprintf("%02x", ((server_id.to_i(16) >> 8) & 0xff))
server_uid = sprintf("%02x", (server_id.to_i(16) & 0xff))
puts "Threading for server #{YELLOW}#{server}#{BLANK} on rack #{BLUE}#{rack_id}#{BLANK}".indent
threads << Thread.new do
failed = false
out = ""
#sync global files
o,s = exec("Rsyncing global files", "rsync -rtvl --exclude-from rsync-exclusions.txt --delete global/ dwadmin@#{server}:/home/dwadmin/")
out += o
failed = true unless s
unless failed
#sync local files
`mkdir -p locals/#{rack_id}/all`
o,s = exec("Rsyncing local rack files", "rsync -rtvl --delete locals/#{rack_id}/all/ dwadmin@#{server}:/home/dwadmin/local/")
out += o
failed = true unless s
unless failed
#sync local files
`mkdir -p locals/#{rack_id}/#{server_uid}`
o,s = exec("Rsyncing local server files", "rsync -rtvl locals/#{rack_id}/#{server_uid}/ dwadmin@#{server}:/home/dwadmin/local/")
out += o
failed = true unless s
end
end
if failed
bads << [server, out]
else
goods << [server, out]
end
end
end
threads.each { |thr| thr.join }
display_results(goods)
unless bads.empty?
puts RED+"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
puts "FAILURES!!"
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"+BLANK
display_results(bads)
puts RED+"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"+BLANK
exit 1
end