Browse Source

实现备份和还原功能

master
VIVIMAN 3 years ago
parent
commit
2dad3507a0
  1. 2
      src/main/java/com/insigma/service/Computer.java
  2. 28
      src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java
  3. 4
      src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java

2
src/main/java/com/insigma/service/Computer.java

@ -24,5 +24,5 @@ public abstract class Computer {
* @param path 还原文件路径 * @param path 还原文件路径
* @return 是否备份成功 * @return 是否备份成功
*/ */
public abstract boolean runRestore(String path); public abstract boolean runRestore(String path) throws Exception;
} }

28
src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java

@ -64,8 +64,10 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
log.info("启动 数据库 服务..."); log.info("启动 数据库 服务...");
ws.startService(); ws.startService();
retBool = true;
} else {
retBool = false;
} }
retBool = true;
} else { } else {
retBool = false; retBool = false;
} }
@ -91,11 +93,33 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
} }
@Override @Override
public boolean runRestore(String path) { public boolean runRestore(String path) throws Exception {
boolean retBool; boolean retBool;
boolean b = cn.hutool.core.io.FileUtil.isFile(path); boolean b = cn.hutool.core.io.FileUtil.isFile(path);
if(b){ 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("判断文件:{}...存在:{}", 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; retBool = true;
}else{ }else{
log.error("判断文件:{}...不存在,请检查!", path); log.error("判断文件:{}...不存在,请检查!", path);

4
src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java

@ -27,7 +27,7 @@ public class WindowsTomcatMysqlTest {
WindowsTomcatMysql windowsTomcatMysql = new WindowsTomcatMysql(); WindowsTomcatMysql windowsTomcatMysql = new WindowsTomcatMysql();
@Test @Test
public void rebuildIndex() { public void rebuildIndex() throws Exception {
assertTrue(windowsTomcatMysql.rebuildIndex(IndexObj.getData())); assertTrue(windowsTomcatMysql.rebuildIndex(IndexObj.getData()));
log.info("测试完成!"); log.info("测试完成!");
} }
@ -81,7 +81,7 @@ public class WindowsTomcatMysqlTest {
} }
@Test @Test
public void runRestore() { public void runRestore() throws Exception {
assertTrue(windowsTomcatMysql.runRestore("")); assertTrue(windowsTomcatMysql.runRestore(""));
log.info("测试完成!"); log.info("测试完成!");
} }

Loading…
Cancel
Save