Mercurial Hosting > luan
comparison src/goodjava/lucene/backup/BackupIndexWriter.java @ 1674:af18eacf187c
automatic restore
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 29 May 2022 23:38:34 -0600 |
parents | 1b9f9fdb3b41 |
children | 445048f9eca7 |
comparison
equal
deleted
inserted
replaced
1673:1b9f9fdb3b41 | 1674:af18eacf187c |
---|---|
1 package goodjava.lucene.backup; | 1 package goodjava.lucene.backup; |
2 | 2 |
3 import java.io.File; | 3 import java.io.File; |
4 import java.io.InputStream; | 4 import java.io.InputStream; |
5 import java.io.OutputStream; | |
6 import java.io.BufferedOutputStream; | |
7 import java.io.FileOutputStream; | |
5 import java.io.IOException; | 8 import java.io.IOException; |
6 import java.net.Socket; | 9 import java.net.Socket; |
7 import java.net.ConnectException; | 10 import java.net.ConnectException; |
8 import java.util.List; | 11 import java.util.List; |
9 import java.util.ArrayList; | 12 import java.util.ArrayList; |
179 for( File f : dir.listFiles() ) { | 182 for( File f : dir.listFiles() ) { |
180 IoUtils.delete(f); | 183 IoUtils.delete(f); |
181 } | 184 } |
182 } | 185 } |
183 | 186 |
187 public static BackupIndexWriter newWithRestore(LuceneIndexWriter indexWriter,File logDir,long logTime,String name) | |
188 throws IOException | |
189 { | |
190 if( !logDir.exists() ) { | |
191 RpcClient rpc = BackupServer.rpcClient(backupDomains[0]); | |
192 try { | |
193 RpcCall call; | |
194 RpcResult result; | |
195 call = new RpcCall("exists",name); | |
196 rpc.write(call); | |
197 result = rpc.read(); | |
198 boolean exists = (Boolean)result.returnValues[0]; | |
199 if( exists ) { | |
200 logger.error("restoring "+logDir+" from backup"); | |
201 File zip = File.createTempFile("luan_",".zip"); | |
202 IoUtils.delete(zip); | |
203 call = new RpcCall("login",name); | |
204 rpc.write(call); | |
205 rpc.read(); | |
206 call = new RpcCall("zip"); | |
207 rpc.write(call); | |
208 result = rpc.read(); | |
209 OutputStream out = new BufferedOutputStream(new FileOutputStream(zip)); | |
210 IoUtils.copyAll(result.in,out); | |
211 out.close(); | |
212 IoUtils.mkdirs(logDir); | |
213 String cmd = "unzip " + zip; | |
214 Process proc = Runtime.getRuntime().exec(cmd,null,logDir); | |
215 IoUtils.waitFor(proc); | |
216 IoUtils.delete(zip); | |
217 } | |
218 } catch(RpcException e) { | |
219 throw new RuntimeException(e); | |
220 } | |
221 rpc.close(); | |
222 } | |
223 return new BackupIndexWriter(indexWriter,logDir,logTime,name); | |
224 } | |
225 | |
184 } | 226 } |