Mercurial Hosting > luan
diff src/goodjava/lucene/backup/Backup.java @ 1697:aff2309ae510
add copy_backups.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 27 Jun 2022 18:36:56 -0600 |
parents | ea7075b7afe1 |
children |
line wrap: on
line diff
--- a/src/goodjava/lucene/backup/Backup.java Sun Jun 26 14:40:08 2022 -0600 +++ b/src/goodjava/lucene/backup/Backup.java Mon Jun 27 18:36:56 2022 -0600 @@ -26,14 +26,20 @@ private final File dir; private final File indexFile; + private boolean updated = false; Backup(File dir) { this.dir = dir; this.indexFile = new File(dir,"index.json"); - dir.setLastModified(System.currentTimeMillis()); } void handle(RpcServer rpc,RpcCall call) { + synchronized(this) { + if( !updated ) { + dir.setLastModified(System.currentTimeMillis()); + updated = true; + } + } try { IoUtils.mkdirs(dir); if( call.cmd.equals("zip") ) { @@ -48,7 +54,7 @@ private static final RpcResult OK = new RpcResult(new Object[]{"ok"}); - synchronized void handle2(RpcServer rpc,RpcCall call) throws IOException { + private synchronized void handle2(RpcServer rpc,RpcCall call) throws IOException { //logger.info(call.cmd+" "+Arrays.asList(call.args)); String fileName = null; if( call.cmd.equals("check") ) { @@ -125,7 +131,7 @@ rpc.write(result); } - void handleZip(RpcServer rpc) throws IOException { + private void handleZip(RpcServer rpc) throws IOException { File zip = File.createTempFile("luan_",".zip"); IoUtils.delete(zip); String cmd = "zip " + zip + " *"; @@ -139,4 +145,17 @@ IoUtils.delete(zip); } + synchronized void copyTo(File dirTo) throws IOException { + IoUtils.mkdirs(dirTo); + for( File f : dir.listFiles() ) { + String name = f.getName(); + File to = new File(dirTo,name); + if( name.equals("index.json") ) { + IoUtils.copy(f,to); + } else { + IoUtils.link(f,to); + } + } + } + }