Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 39598
1
2
async = require('async')
3
fs = require('fs')
4
child_process = require('child_process')
5
6
hosts = ("cloud#{i}.math.washington.edu" for i in [10..21])
7
8
#hosts = ["cloud10.math.washington.edu"]
9
#hosts = ("cloud#{i}.math.washington.edu" for i in [10,11,12])
10
11
THREADS = hosts.length
12
13
OLDEST = fs.readFileSync('date').toString('ascii').trim()
14
15
split = (s) ->
16
r = s.match(/\S+/g)
17
if r
18
return r
19
else
20
return []
21
22
cmd = (s, cb) ->
23
console.log(s)
24
t0 = new Date() - 0
25
child_process.exec s, (err, stdout, stderr) ->
26
#console.log("stdout='#{stdout}'")
27
#console.log("stderr='#{stderr}'")
28
if err
29
console.log("ERROR running s='#{s}': #{err}")
30
console.log("DONE with #{s}: time=#{(new Date() - t0)/1000}s")
31
cb?()
32
33
update_project_times_from_host = (host, cb) ->
34
# ssh [email protected] -p 2222 "ls -lt --time-style=full-iso /bup/bups |grep -v ^total " > t
35
cmd("ssh root@#{host} -o StrictHostKeyChecking=no -p 2222 'ls -lt --time-style=full-iso /bup/bups |grep -v ^total' > bup/bups/ls-lt/#{host}", cb)
36
37
update_project_times = (cb) ->
38
console.log "Fetching project timestamp information..."
39
async.map(hosts, update_project_times_from_host, cb)
40
41
num_to_get = undefined
42
num = 0
43
start = new Date() - 0
44
f = (x, cb) ->
45
date = x[0]; host=x[1]; project_id = x[2]; j = x[3]
46
num += 1
47
elapsed = (new Date() - start)/1000.0
48
per = elapsed / num
49
remaining = ((num_to_get-num) * per)/60.0/60.0
50
console.log("#{date}: Syncing #{num}/#{num_to_get} -- (from #{host}) -- elapsed=#{elapsed/60/60}h; remaining=#{remaining}h or #{remaining*60}m ...")
51
s = "time rsync -axvH -e 'ssh -o StrictHostKeyChecking=no -p 2222' --delete --exclude /bup/bups/#{project_id}/cache/ root@#{host}:/bup/bups/#{project_id}/ bup/bups/#{host}/#{project_id}/ > /dev/null 2>/dev/null"
52
cmd(s, cb)
53
54
g = (cb) ->
55
to_get = []
56
j = 0
57
for host in hosts
58
for x in fs.readFileSync("bup/bups/ls-lt/#{host}").toString().split('\n')
59
v = split(x)
60
#console.log(x); console.log(v)
61
if v.length < 9
62
continue
63
if v[5] < OLDEST
64
console.log("Halting scan of #{host} at '#{x}'.")
65
break
66
j += 1
67
to_get.push([v[5],host,v[8],j])
68
69
num_to_get = to_get.length
70
to_get.sort (a,b) ->
71
a_key = "#{a[0]}-#{a[2]}"
72
b_key = "#{b[0]}-#{b[2]}"
73
if a_key < b_key
74
return 1
75
else
76
return -1
77
console.log("to_get length = #{to_get.length}")
78
async.mapLimit(to_get, THREADS, f, (err) -> cb?(err))
79
cb?()
80
81
82
async.series([
83
(cb) ->
84
update_project_times(cb)
85
(cb) ->
86
start = new Date() - 0
87
g(cb)
88
], (err) ->
89
console.log("Done updating backups: err=#{err}")
90
)
91
92
93