Mercurial Hosting > luan
comparison src/goodjava/lucene/backup/Backup.java @ 1512:31b543826ca9
lucene.backup login
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 23 May 2020 19:01:57 -0600 |
parents | 0ba144491a42 |
children | 736ec76bbf42 |
comparison
equal
deleted
inserted
replaced
1511:fb5be0e8ca54 | 1512:31b543826ca9 |
---|---|
11 import goodjava.io.IoUtils; | 11 import goodjava.io.IoUtils; |
12 import goodjava.io.BufferedInputStream; | 12 import goodjava.io.BufferedInputStream; |
13 import goodjava.rpc.RpcServer; | 13 import goodjava.rpc.RpcServer; |
14 import goodjava.rpc.RpcCall; | 14 import goodjava.rpc.RpcCall; |
15 import goodjava.rpc.RpcResult; | 15 import goodjava.rpc.RpcResult; |
16 import goodjava.rpc.RpcException; | |
16 import goodjava.logging.Logger; | 17 import goodjava.logging.Logger; |
17 import goodjava.logging.LoggerFactory; | 18 import goodjava.logging.LoggerFactory; |
18 import goodjava.lucene.logging.LogFile; | 19 import goodjava.lucene.logging.LogFile; |
19 import goodjava.lucene.logging.LoggingIndexWriter; | 20 import goodjava.lucene.logging.LoggingIndexWriter; |
20 import goodjava.lucene.logging.LogOutputStream; | 21 import goodjava.lucene.logging.LogOutputStream; |
50 //logger.info(call.cmd+" "+Arrays.asList(call.args)); | 51 //logger.info(call.cmd+" "+Arrays.asList(call.args)); |
51 String fileName = null; | 52 String fileName = null; |
52 if( call.cmd.equals("check") ) { | 53 if( call.cmd.equals("check") ) { |
53 // nothing | 54 // nothing |
54 } else if( call.cmd.equals("add") || call.cmd.equals("append") ) { | 55 } else if( call.cmd.equals("add") || call.cmd.equals("append") ) { |
55 fileName = (String)call.args[2]; | 56 fileName = (String)call.args[1]; |
56 File f = new File(dir,fileName); | 57 File f = new File(dir,fileName); |
57 if( call.cmd.equals("add") ) | 58 if( call.cmd.equals("add") ) |
58 IoUtils.delete(f); | 59 IoUtils.delete(f); |
59 LogFile log = new LogFile(f); | 60 LogFile log = new LogFile(f); |
60 LogOutputStream out = log.output(); | 61 LogOutputStream out = log.output(); |
61 IoUtils.copyAll(call.in,out); | 62 IoUtils.copyAll(call.in,out); |
62 out.commit(); | 63 out.commit(); |
63 out.close(); | 64 out.close(); |
64 logger.info(call.cmd+" "+fileName+" "+call.lenIn); | 65 //logger.info(call.cmd+" "+fileName+" "+call.lenIn); |
65 } else | 66 } else { |
66 throw new RuntimeException("cmd "+call.cmd); | 67 logger.error("bad cmd '"+call.cmd+"'"); |
67 List logInfo = (List)call.args[1]; | 68 rpc.write( new RpcException("bad cmd '"+call.cmd+"'") ); |
68 logger.info("check "+logInfo); | 69 return; |
70 } | |
71 List logInfo = (List)call.args[0]; | |
72 //logger.info("check "+logInfo); | |
69 RpcResult result = OK; | 73 RpcResult result = OK; |
70 for( Object obj : logInfo ) { | 74 for( Object obj : logInfo ) { |
71 Map fileInfo = (Map)obj; | 75 Map fileInfo = (Map)obj; |
72 String name = (String)fileInfo.get("name"); | 76 String name = (String)fileInfo.get("name"); |
73 File f = new File(dir,name); | 77 File f = new File(dir,name); |
112 } | 116 } |
113 logs.add( new LogFile(f) ); | 117 logs.add( new LogFile(f) ); |
114 } | 118 } |
115 if( complete ) { | 119 if( complete ) { |
116 LoggingIndexWriter.writeIndex(logs,index); | 120 LoggingIndexWriter.writeIndex(logs,index); |
117 logger.info("write index"); | 121 //logger.info("write index"); |
118 } | 122 } |
119 } | 123 } |
120 rpc.write(result); | 124 rpc.write(result); |
121 } | 125 } |
122 | 126 |
123 void handleZip(RpcServer rpc) throws IOException { | 127 void handleZip(RpcServer rpc) throws IOException { |
124 File zip = File.createTempFile("luan_",".zip"); | 128 File zip = File.createTempFile("luan_",".zip"); |
125 IoUtils.delete(zip); | 129 IoUtils.delete(zip); |
126 String cmd = "zip -r " + zip + " " + dir.getName(); | 130 String cmd = "zip -r " + zip + " " + dir.getName(); |
127 logger.info("cmd = "+cmd); | |
128 synchronized(this) { | 131 synchronized(this) { |
129 Process proc = Runtime.getRuntime().exec(cmd,null,dir.getParentFile()); | 132 Process proc = Runtime.getRuntime().exec(cmd,null,dir.getParentFile()); |
130 IoUtils.waitFor(proc); | 133 IoUtils.waitFor(proc); |
131 } | 134 } |
132 InputStream in = new BufferedInputStream(new FileInputStream(zip)); | 135 InputStream in = new BufferedInputStream(new FileInputStream(zip)); |