From 2dad3507a0463227745f08b2a7c7c785a5ee1272 Mon Sep 17 00:00:00 2001 From: VIVIMAN Date: Tue, 26 Apr 2022 16:21:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=A4=87=E4=BB=BD=E5=92=8C?= =?UTF-8?q?=E8=BF=98=E5=8E=9F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/insigma/service/Computer.java | 2 +- .../service/impl/WindowsTomcatMysql.java | 28 +++++++++++++++++-- .../service/impl/WindowsTomcatMysqlTest.java | 4 +-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/insigma/service/Computer.java b/src/main/java/com/insigma/service/Computer.java index e872f55..688c0ec 100644 --- a/src/main/java/com/insigma/service/Computer.java +++ b/src/main/java/com/insigma/service/Computer.java @@ -24,5 +24,5 @@ public abstract class Computer { * @param path 还原文件路径 * @return 是否备份成功 */ - public abstract boolean runRestore(String path); + public abstract boolean runRestore(String path) throws Exception; } diff --git a/src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java b/src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java index 0f72e57..a6dc046 100644 --- a/src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java +++ b/src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java @@ -64,8 +64,10 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware log.info("启动 数据库 服务..."); ws.startService(); + retBool = true; + } else { + retBool = false; } - retBool = true; } else { retBool = false; } @@ -91,11 +93,33 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware } @Override - public boolean runRestore(String path) { + public boolean runRestore(String path) throws Exception { boolean retBool; boolean b = cn.hutool.core.io.FileUtil.isFile(path); if(b){ + String namePath = path.substring(0, path.indexOf(".gz")); + String picPath = File.separatorChar + "tomcat8" + File.separatorChar + "HZBPHOTOS"; + String dbPath = AppCfg.HZB + File.separatorChar + "mysql" + File.separatorChar + "data"; log.info("判断文件:{}...存在:{}", path, b); + log.info("解压文件..."); + ZipUtil.unZip7Z(path, namePath); + + WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); + if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ + ws.stopService(); + } + log.info("删除原数据文件..."); + cn.hutool.core.io.FileUtil.del(dbPath); + + log.info("解压数据库文件..."); + ZipUtil.unZip7Z(namePath + File.separatorChar + "data", dbPath); + + log.info("删除原照片文件..."); + cn.hutool.core.io.FileUtil.del(AppCfg.HZB + picPath); + + log.info("移动照片文件..."); + cn.hutool.core.io.FileUtil.copy(namePath + picPath, AppCfg.HZB + picPath, true); + ws.startService(); retBool = true; }else{ log.error("判断文件:{}...不存在,请检查!", path); diff --git a/src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java b/src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java index 54e78dc..1c22b09 100644 --- a/src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java +++ b/src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java @@ -27,7 +27,7 @@ public class WindowsTomcatMysqlTest { WindowsTomcatMysql windowsTomcatMysql = new WindowsTomcatMysql(); @Test - public void rebuildIndex() { + public void rebuildIndex() throws Exception { assertTrue(windowsTomcatMysql.rebuildIndex(IndexObj.getData())); log.info("测试完成!"); } @@ -81,7 +81,7 @@ public class WindowsTomcatMysqlTest { } @Test - public void runRestore() { + public void runRestore() throws Exception { assertTrue(windowsTomcatMysql.runRestore("")); log.info("测试完成!"); }