annotate src/goodjava/lucene/backup/BackupServer.java @ 1799:1578324d2aac

backup logging
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 22 Feb 2024 08:34:55 -0700
parents 2dbcc8360a3e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.lucene.backup;
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 import java.io.File;
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 import java.io.IOException;
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 import java.util.Map;
1690
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
6 import java.net.InetAddress;
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 import java.net.Socket;
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 import java.net.ServerSocket;
1690
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
9 import java.net.UnknownHostException;
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 import java.util.concurrent.Executors;
1502
8a7b6b32c691 minor threads
Franklin Schmidt <fschmidt@gmail.com>
parents: 1501
diff changeset
11 import java.util.concurrent.ExecutorService;
1509
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
12 import javax.net.ssl.SSLSocket;
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 import javax.net.ssl.SSLServerSocket;
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 import goodjava.util.SoftCacheMap;
1501
Franklin Schmidt <fschmidt@gmail.com>
parents: 1499
diff changeset
15 import goodjava.io.IoUtils;
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 import goodjava.rpc.RpcServer;
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 import goodjava.rpc.RpcCall;
1509
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
18 import goodjava.rpc.RpcClient;
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
19 import goodjava.rpc.RpcResult;
1512
31b543826ca9 lucene.backup login
Franklin Schmidt <fschmidt@gmail.com>
parents: 1509
diff changeset
20 import goodjava.rpc.Rpc;
1509
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
21 import goodjava.rpc.RpcException;
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 import goodjava.logging.Logger;
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import goodjava.logging.LoggerFactory;
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25
1672
8dd8c556c449 backup work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1512
diff changeset
26 public final class BackupServer {
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 private static final Logger logger = LoggerFactory.getLogger(BackupServer.class);
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28
1675
Franklin Schmidt <fschmidt@gmail.com>
parents: 1674
diff changeset
29 public static int port = 9102;
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 public static String[] cipherSuites = new String[] {
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 "TLS_DH_anon_WITH_AES_128_GCM_SHA256",
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 "TLS_DH_anon_WITH_AES_128_CBC_SHA256",
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 "TLS_ECDH_anon_WITH_AES_128_CBC_SHA",
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 "TLS_DH_anon_WITH_AES_128_CBC_SHA",
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA",
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA",
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 "TLS_ECDH_anon_WITH_RC4_128_SHA",
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 "SSL_DH_anon_WITH_RC4_128_MD5",
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 "SSL_DH_anon_WITH_DES_CBC_SHA",
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA",
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 };
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 private final File backupDir;
1502
8a7b6b32c691 minor threads
Franklin Schmidt <fschmidt@gmail.com>
parents: 1501
diff changeset
45 private static final ExecutorService threadPool = Executors.newCachedThreadPool();
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 private static final Map<String,Backup> backups = new SoftCacheMap<String,Backup>();
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47
1501
Franklin Schmidt <fschmidt@gmail.com>
parents: 1499
diff changeset
48 public BackupServer(File backupDir) throws IOException {
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 this.backupDir = backupDir;
1501
Franklin Schmidt <fschmidt@gmail.com>
parents: 1499
diff changeset
50 IoUtils.mkdirs(backupDir);
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 }
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 public synchronized void start() throws IOException {
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 final ServerSocket ss;
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 if( cipherSuites == null ) {
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 ss = new ServerSocket(port);
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 } else {
1506
d80395468b4e ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents: 1502
diff changeset
58 ss = IoUtils.getSSLServerSocketFactory().createServerSocket(port);
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 ((SSLServerSocket)ss).setEnabledCipherSuites(cipherSuites);
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 }
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 threadPool.execute(new Runnable(){public void run() {
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 try {
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 while(!threadPool.isShutdown()) {
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 final Socket socket = ss.accept();
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 threadPool.execute(new Runnable(){public void run() {
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 handle(socket);
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 }});
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 }
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 } catch(IOException e) {
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 logger.error("",e);
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 }
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 }});
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 logger.info("started server on port "+port);
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 }
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75
1690
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
76 private static String getName(RpcServer rpc,Object[] args) {
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
77 String domain = (String)args[0];
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
78 InetAddress addr;
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
79 try {
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
80 addr = InetAddress.getByName(domain);
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
81 } catch(UnknownHostException e) {
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
82 rpc.write( new RpcException("domain lookup failed") );
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
83 rpc.close();
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
84 return null;
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
85 }
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
86 if( !rpc.socket.getInetAddress().equals(addr) ) {
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
87 rpc.write( new RpcException("domain doesn't match client") );
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
88 rpc.close();
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
89 return null;
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
90 }
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
91 String name = (String)args[1];
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
92 return name==null ? domain : domain + "~" + name;
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
93 }
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
94
1697
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
95 private Backup getBackup(String name) {
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
96 synchronized(backups) {
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
97 Backup backup = backups.get(name);
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
98 if( backup == null ) {
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
99 backup = new Backup( new File(backupDir,name) );
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
100 backups.put(name,backup);
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
101 }
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
102 return backup;
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
103 }
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
104 }
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
105
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106 private void handle(Socket socket) {
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 RpcServer rpc = new RpcServer(socket);
1674
af18eacf187c automatic restore
Franklin Schmidt <fschmidt@gmail.com>
parents: 1673
diff changeset
108 Backup backup = null;
af18eacf187c automatic restore
Franklin Schmidt <fschmidt@gmail.com>
parents: 1673
diff changeset
109 while( !rpc.isClosed() ) {
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110 RpcCall call = rpc.read();
1674
af18eacf187c automatic restore
Franklin Schmidt <fschmidt@gmail.com>
parents: 1673
diff changeset
111 if( call == null )
af18eacf187c automatic restore
Franklin Schmidt <fschmidt@gmail.com>
parents: 1673
diff changeset
112 break;
af18eacf187c automatic restore
Franklin Schmidt <fschmidt@gmail.com>
parents: 1673
diff changeset
113 if( call.cmd.equals("exists") ) {
1690
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
114 String name = getName(rpc,call.args);
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
115 if( name==null ) return;
1674
af18eacf187c automatic restore
Franklin Schmidt <fschmidt@gmail.com>
parents: 1673
diff changeset
116 rpc.write( new RpcResult(new Object[]{new File(backupDir,name).exists()}) );
af18eacf187c automatic restore
Franklin Schmidt <fschmidt@gmail.com>
parents: 1673
diff changeset
117 } else if( call.cmd.equals("login") ) {
1690
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
118 String name = getName(rpc,call.args);
973d3039c421 backup server checks client domain
Franklin Schmidt <fschmidt@gmail.com>
parents: 1675
diff changeset
119 if( name==null ) return;
1697
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
120 backup = getBackup(name);
1674
af18eacf187c automatic restore
Franklin Schmidt <fschmidt@gmail.com>
parents: 1673
diff changeset
121 rpc.write(Rpc.OK);
af18eacf187c automatic restore
Franklin Schmidt <fschmidt@gmail.com>
parents: 1673
diff changeset
122 } else if( backup != null ) {
af18eacf187c automatic restore
Franklin Schmidt <fschmidt@gmail.com>
parents: 1673
diff changeset
123 backup.handle(rpc,call);
1697
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
124 } else if( call.cmd.equals("copy") ) {
1698
2dbcc8360a3e backup security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1697
diff changeset
125 try {
2dbcc8360a3e backup security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1697
diff changeset
126 if( !IoUtils.getInetAddresses().contains(rpc.socket.getInetAddress()) ) {
2dbcc8360a3e backup security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1697
diff changeset
127 rpc.write( new RpcException("only localhost allowed") );
2dbcc8360a3e backup security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1697
diff changeset
128 rpc.close();
2dbcc8360a3e backup security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1697
diff changeset
129 return;
2dbcc8360a3e backup security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1697
diff changeset
130 }
2dbcc8360a3e backup security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1697
diff changeset
131 } catch(IOException e) {
2dbcc8360a3e backup security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1697
diff changeset
132 throw new RuntimeException(e);
2dbcc8360a3e backup security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1697
diff changeset
133 }
1697
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
134 String dirName = (String)call.args[0];
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
135 copy(new File(dirName));
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
136 rpc.write(Rpc.OK);
1674
af18eacf187c automatic restore
Franklin Schmidt <fschmidt@gmail.com>
parents: 1673
diff changeset
137 } else {
1512
31b543826ca9 lucene.backup login
Franklin Schmidt <fschmidt@gmail.com>
parents: 1509
diff changeset
138 rpc.write( new RpcException("login expected") );
31b543826ca9 lucene.backup login
Franklin Schmidt <fschmidt@gmail.com>
parents: 1509
diff changeset
139 rpc.close();
31b543826ca9 lucene.backup login
Franklin Schmidt <fschmidt@gmail.com>
parents: 1509
diff changeset
140 return;
31b543826ca9 lucene.backup login
Franklin Schmidt <fschmidt@gmail.com>
parents: 1509
diff changeset
141 }
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142 }
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 }
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144
1697
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
145 private void copy(File dir) {
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
146 try {
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
147 IoUtils.deleteRecursively(dir);
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
148 IoUtils.mkdirs(dir);
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
149 for( File f : backupDir.listFiles() ) {
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
150 if( f.isDirectory() && new File(f,"index.json").exists() ) {
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
151 String name = f.getName();
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
152 Backup backup = getBackup(name);
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
153 backup.copyTo( new File(dir,name) );
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
154 }
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
155 }
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
156 } catch(IOException e) {
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
157 throw new RuntimeException(e);
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
158 }
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
159 }
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
160
1509
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
161
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
162 // for client
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
163
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
164 public static RpcClient rpcClient(String backupDomain) throws IOException {
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
165 Socket socket;
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
166 if( BackupServer.cipherSuites == null ) {
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
167 socket = new Socket(backupDomain,BackupServer.port);
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
168 } else {
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
169 socket = IoUtils.getSSLSocketFactory().createSocket(backupDomain,BackupServer.port);
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
170 ((SSLSocket)socket).setEnabledCipherSuites(BackupServer.cipherSuites);
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
171 }
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
172 return new RpcClient(socket);
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
173 }
0ba144491a42 lucene.backup zip
Franklin Schmidt <fschmidt@gmail.com>
parents: 1506
diff changeset
174
1697
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
175 public static void copyBackupTo(String dirName) throws IOException, RpcException {
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
176 RpcClient rpc = BackupServer.rpcClient("localhost");
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
177 rpc.write( new RpcCall("copy",dirName) );
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
178 RpcResult result = rpc.read();
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
179 rpc.close();
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
180 }
aff2309ae510 add copy_backups.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1690
diff changeset
181
1499
22e15cf73040 lucene.backup
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182 }