Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 39598
1
THREADS = 5
2
OLDEST = '2014-12-01'
3
4
async = require('async')
5
fs = require('fs')
6
child_process = require('child_process')
7
8
split = (s) ->
9
r = s.match(/\S+/g)
10
if r
11
return r
12
else
13
return []
14
15
cmd = (s, cb) ->
16
console.log(s)
17
child_process.exec s, (err, stdout, stderr) ->
18
console.log("stdout='#{stdout}'")
19
console.log("stderr='#{stderr}'")
20
cb?(err)
21
22
update_project_times = (cb) ->
23
console.log "Fetching project timestamp information..."
24
cmd("time rsync -axvH --delete [email protected]:/home/salvus/vm/images/bup/bups/ls-lt/ bup/bups/ls-lt/", cb)
25
26
num_to_get = undefined
27
f = (x, cb) ->
28
i=x[0]; project_id = x[1]; j = x[2]
29
console.log("Syncing #{j}/#{num_to_get} -- (from 10.1.#{i}.5)...")
30
cmd("time rsync -axvH --delete --exclude /home/salvus/vm/images/bup/bups/10.1.#{i}.5/#{project_id}/cache/ [email protected]:/home/salvus/vm/images/bup/bups/10.1.#{i}.5/#{project_id}/ bup/bups/10.1.#{i}.5/#{project_id}/", cb)
31
32
g = (cb) ->
33
to_get = []
34
j = 0
35
for i in [1..7]
36
for x in fs.readFileSync("bup/bups/ls-lt/10.1.#{i}.5").toString().split('\n')
37
v = split(x)
38
#console.log(x); console.log(v)
39
if v.length < 9
40
continue
41
if v[5] < OLDEST
42
console.log("Halting scan of 10.1.#{i}.5 at '#{x}'.")
43
break
44
j += 1
45
to_get.push([i,v[8],j])
46
47
num_to_get = to_get.length
48
console.log "Syncing #{num_to_get} projects from 10.1.#{i}.5"
49
async.mapLimit(to_get, THREADS, f, (err) -> cb?(err))
50
cb?()
51
52
sync_db = (cb) ->
53
console.log("Syncing database backup")
54
cmd("time rsync -axvH --delete [email protected]:/home/salvus/vm/images/bup/cassandra-dc1/ bup/cassandra-dc1/")
55
56
async.series([
57
(cb) ->
58
update_project_times(cb)
59
(cb) ->
60
g(cb)
61
(cb) ->
62
sync_db(cb)
63
], (err) ->
64
console.log("Done updating backups: err=#{err}")
65
)
66
67
68