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