diff src/goodjava/lucene/backup/BackupServer.java @ 1509:0ba144491a42

lucene.backup zip
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 17 May 2020 14:29:33 -0600
parents d80395468b4e
children 31b543826ca9
line wrap: on
line diff
--- a/src/goodjava/lucene/backup/BackupServer.java	Sat May 16 17:56:02 2020 -0600
+++ b/src/goodjava/lucene/backup/BackupServer.java	Sun May 17 14:29:33 2020 -0600
@@ -1,17 +1,24 @@
 package goodjava.lucene.backup;
 
 import java.io.File;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.io.BufferedOutputStream;
 import java.io.IOException;
 import java.util.Map;
 import java.net.Socket;
 import java.net.ServerSocket;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ExecutorService;
+import javax.net.ssl.SSLSocket;
 import javax.net.ssl.SSLServerSocket;
 import goodjava.util.SoftCacheMap;
 import goodjava.io.IoUtils;
 import goodjava.rpc.RpcServer;
 import goodjava.rpc.RpcCall;
+import goodjava.rpc.RpcClient;
+import goodjava.rpc.RpcResult;
+import goodjava.rpc.RpcException;
 import goodjava.logging.Logger;
 import goodjava.logging.LoggerFactory;
 
@@ -85,4 +92,29 @@
 		}
 	}
 
+
+	// for client
+
+	public static RpcClient rpcClient(String backupDomain) throws IOException {
+		Socket socket;
+		if( BackupServer.cipherSuites == null ) {
+			socket = new Socket(backupDomain,BackupServer.port);
+		} else {
+			socket = IoUtils.getSSLSocketFactory().createSocket(backupDomain,BackupServer.port);
+			((SSLSocket)socket).setEnabledCipherSuites(BackupServer.cipherSuites);
+		}
+		return new RpcClient(socket);
+	}
+
+	public static void getBackup(String backupDomain,String name,File zip) throws IOException, RpcException {
+		RpcClient rpc = BackupServer.rpcClient(backupDomain);
+		RpcCall call = new RpcCall("zip",name);
+		rpc.write(call);
+		RpcResult result = rpc.read();
+		OutputStream out = new BufferedOutputStream(new FileOutputStream(zip));
+		IoUtils.copyAll(result.in,out);
+		out.close();
+		rpc.close();
+	}
+
 }