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
|
# File 'lib/pig-media-server/backup.rb', line 26
def restore_from path
raise unless File.exist? path
pit_config = Pit.get 'Pig Media Server'
Dir.glob("#{pit_config['groonga']}/**/*").each{|x| FileUtils.rm x}
Groonga::Database.create path: pit_config['groonga']+"/search"
Dir.mktmpdir do |tmpdir|
FileUtils.cd tmpdir
FileUtils.cp path, "."
system 'tar', 'xvf', Dir.glob("*.gz").first
system 'ls'
FileUtils.rm Dir.glob("*.gz").first
Groonga::Schema.restore(open('groonga.schema').read){|schema| schema.define }
$f = Groonga['Files']
json =open("backup.json").read.split("\n")
json.each_with_index{|x,i|
x = JSON.parse x
$f.add(x[0])
$f[x[0]].path = x[1]
$f[x[0]].metadata = x[2]
$f[x[0]].srt = x[3]
$f[x[0]].mtime = x[4]
$f[x[0]].size = x[5]
puts "#{i+1} / #{json.count}" if i%100 == 0 or i+1 == json.count
}
end
ary = $f.select.to_a
lost = []
ary.each_with_index{|x,i|
if x.path.nil?
$f.delete x._key
next
end
puts "#{i+1} / #{ary.count}" if (i+1)%1000 == 0 or i+1 == ary.count
}
lost.sort.each{|x| puts x}
end
|