Преглед изворни кода

添加备份任务调度功能

reghao пре 5 година
родитељ
комит
f538db556d
20 измењених фајлова са 350 додато и 166 уклоњено
  1. 6 1
      README.md
  2. 77 119
      common/src/main/java/cn/reghao/autodop/common/shell/ShellExecutor.java
  3. 20 9
      dmaster/pom.xml
  4. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/AppCompile.java
  5. 1 4
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/ConfigService.java
  6. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/CodeCompiler.java
  7. 5 19
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/ShellCompiler.java
  8. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/jwt/JwtTokenFilter.java
  9. 3 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/BackupController.java
  10. 79 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/BackupScheduler.java
  11. 20 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/BackupService.java
  12. 28 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/BackupServiceImpl.java
  13. 44 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/ScriptBakJob.java
  14. 17 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/entity/BakLog.java
  15. 25 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/entity/BakService.java
  16. 12 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/repository/BakServiceRepository.java
  17. 3 0
      dmaster/src/main/resources/application-dev.yml
  18. 1 0
      rsyncd_secret
  19. 5 5
      scripts/build_and_deploy.sh
  20. 0 0
      scripts/svn_post_commit

+ 6 - 1
README.md

@@ -1 +1,6 @@
-# autodop
+# autodop
+
+DevOps 自动化:
+- 构建部署
+- 运行监控
+- 备份还原

+ 77 - 119
common/src/main/java/cn/reghao/autodop/common/shell/ShellExecutor.java

@@ -9,137 +9,88 @@ import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.UUID;
 
 /**
  * @author reghao
  * @date 2019-08-20 23:45:06
  */
 public class ShellExecutor {
-    @Deprecated
-    private InputStreamReader outstream;
-    @Deprecated
-    private InputStreamReader errstream;
+    private final String PATH;
+    private final String SHELL;
+    private TextFile textFile;
+
+    public ShellExecutor() {
+        this.PATH = System.getenv("PATH");
+        this.SHELL = System.getenv("SHELL");
+        this.textFile = new TextFile();
+    }
 
     /**
-     * @param scriptPath shell 脚本绝对路径
-     * @param args 日志文件以 .log 为后缀,且必须为数组的第一个元素(若存在日志文件)
+     * 执行 shell 命令
+     *
+     * @param dir 执行命令所处的目录
+     * @param cmd shell 命令
+     * @param longLog shell 命令是否会输出长日志(长日志会重定向到一个临时文件)
      * @return
-     * @date 2020-11-09 下午7:22
+     * @date 2020-11-09 下午11:22
      */
-    public ShellResult execute(String scriptPath, String... args) throws Exception {
-        List<String> commands = new ArrayList<>();
-        commands.add("sh");
-        commands.add(scriptPath);
-        commands.addAll(Arrays.asList(args));
-        ProcessBuilder pb = new ProcessBuilder(commands);
-        ShellResult shellResult = exec(pb);
-        if (args.length != 0 && args[0].endsWith(".log")) {
-            // 读取日志文件的内容
-            TextFile textFile = new TextFile();
-            if (shellResult.hasError()) {
-                shellResult.setStderr(textFile.readFile(args[0]));
-            } else {
-                shellResult.setStdout(textFile.readFile(args[0]));
-            }
-        }
-
-        return shellResult;
-    }
-
-    @Deprecated
-    public ShellResult execute(String script) {
-        String dir = System.getProperty("user.home");
-        return execute0(dir, script);
-    }
-
-    @Deprecated
-    public ShellResult execute(String dir, String script) {
+    public ShellResult execCommand(String dir, String cmd, boolean longLog) throws Exception {
         if (dir == null) {
-            return null;
+            dir = System.getProperty("user.home");
         }
 
-        return execute0(dir, script);
-    }
-
-    // TODO: 输出流有大量数据时程序会阻塞
-    @Deprecated
-    private ShellResult execute0(String dir, String script) {
-        String cmd = "cd " + dir + " && ";
-        cmd += script;
-        ShellResult result = new ShellResult();
-        ProcessBuilder pb = new ProcessBuilder("sh", "-c", cmd);
-        try {
-            Process process = pb.start();
-            errstream = new InputStreamReader(process.getErrorStream());
-            outstream = new InputStreamReader(process.getInputStream());
-
-            ShellOutput stderr = new ShellOutput(new BufferedReader(errstream));
-            ShellOutput stdout = new ShellOutput(new BufferedReader(outstream));
-            stderr.start();
-            stdout.start();
-
-            while (!stderr.isFinished() && !stdout.isFinished()) {
-                Thread.sleep(1_000);
-            }
+        List<String> list = new ArrayList<>();
+        list.add("cd " + dir);
+        String logfile = "";
+        if (longLog) {
+            logfile = System.getProperty("java.io.tmpdir") + "/" + UUID.randomUUID().toString() + ".log";
+            list.add(cmd + " > " + logfile + " 2>&1");
+        } else {
+            list.add(cmd);
+        }
+        String scriptPath = System.getProperty("java.io.tmpdir") + "/" + UUID.randomUUID().toString() + ".sh";
+        textFile.write(scriptPath, list);
 
-            result.setStdout(stdout.output());
-            result.setStderr(stderr.output());
-            result.setExitCode(process.waitFor());
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            try {
-                if (errstream != null) {
-                    errstream.close();
-                }
-
-                if (outstream != null) {
-                    outstream.close();
-                }
-            } catch (Exception e) {
-                e.printStackTrace();
+        ProcessBuilder pb = new ProcessBuilder("sh", scriptPath);
+        ShellResult shellResult = exec(pb);
+        if (longLog) {
+            if (shellResult.hasError()) {
+                shellResult.setStderr(textFile.readFile(logfile));
+            } else {
+                shellResult.setStdout(textFile.readFile(logfile));
             }
         }
 
-        // TODO: null 异常
-        return result;
+        return shellResult;
     }
 
-    @Deprecated
-    static class ShellOutput extends Thread {
-        private BufferedReader in;
-        private StringBuilder output = new StringBuilder();
-        private boolean isFinished = false;
-
-        private ShellOutput(BufferedReader in) {
-            this.in = in;
-        }
-
-        private String output() {
-            return output.toString();
-        }
-
-        private boolean isFinished() {
-            return this.isFinished;
-        }
+    /**
+     * 执行 shell 脚本
+     *
+     * @param scriptPath shell 脚本绝对路径
+     * @param args 日志文件以 .log 为后缀,且必须为数组的第一个元素(若存在日志文件)
+     * @return
+     * @date 2020-11-09 下午7:22
+     */
+    public ShellResult execScript(String scriptPath, String... args) throws Exception {
+        String logfile = System.getProperty("java.io.tmpdir") + "/" + UUID.randomUUID().toString() + ".log";
+        List<String> commands = new ArrayList<>();
+        commands.add("sh");
+        commands.add(scriptPath);
+        commands.add(logfile);
+        commands.addAll(Arrays.asList(args));
 
-        @Override
-        public void run() {
-            readStream(in);
+        ProcessBuilder pb = new ProcessBuilder(commands);
+        ShellResult shellResult = exec(pb);
+        // 读取日志文件的内容
+        if (shellResult.hasError()) {
+            shellResult.setStderr(textFile.readFile(logfile));
+        } else {
+            shellResult.setStdout(textFile.readFile(logfile));
         }
 
-        private void readStream(BufferedReader reader) {
-            String line;
-            try {
-                while ((line = reader.readLine()) != null) {
-                    output.append(line).append(System.lineSeparator());
-                }
-                reader.close();
-                isFinished = true;
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
+        return shellResult;
     }
 
     private ShellResult exec(ProcessBuilder pb) throws Exception {
@@ -169,15 +120,22 @@ public class ShellExecutor {
     }
 
     public static void main(String[] args) throws Exception {
-        String script = "/home/reghao/scripts/cron/cron_rsync.sh";
-        script = "/home/reghao/work/azy/svn/test/4-运维管理/构建部署/自动化脚本/build_app.sh";
-        String[] arr = new String[2];
-        //arr[0] = "/tmp/content1.log";
-        arr[0] = "content";
-        arr[1] = "/home/reghao/opt/data/autodop/compile-dir/content/ContentService/4-ContentPresentation/Com.IQuizoo.ContentService";
-
-        ShellExecutor shellExecutor = new ShellExecutor();
-        ShellResult shellResult = shellExecutor.execute(script, arr);
-        System.out.println();
+        String cmd = "rsync -avzP --delete --password-file=/home/reghao/scripts/cron/rsyncd_secret azy@192.168.0.50::nexus /home/reghao/opt/data/backup/nexus/";
+        String script = "/home/reghao/work/azy/svn/test/4-运维管理/备份还原/rsync.sh";
+
+        ShellExecutor executor = new ShellExecutor();
+        /*ShellResult result = executor.execCommand(null, cmd, false);
+        if (result.hasError()) {
+            System.out.println(result.getStderr());
+        } else {
+            System.out.println(result.getStdout());
+        }*/
+
+        ShellResult shellResult = executor.execScript(script);
+        if (shellResult.hasError()) {
+            System.out.println(shellResult.getStderr());
+        } else {
+            System.out.println(shellResult.getStdout());
+        }
     }
 }

+ 20 - 9
dmaster/pom.xml

@@ -34,6 +34,16 @@
             <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-mongodb</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
@@ -45,11 +55,6 @@
             <version>3.3.1</version>
         </dependency>
 
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-data-jpa</artifactId>
-        </dependency>
-
         <dependency>
             <groupId>org.tmatesoft.svnkit</groupId>
             <artifactId>svnkit</artifactId>
@@ -74,13 +79,13 @@
         </dependency>
 
         <dependency>
-            <groupId>com.github.ben-manes.caffeine</groupId>
-            <artifactId>caffeine</artifactId>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-security</artifactId>
         </dependency>
 
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-security</artifactId>
+            <groupId>com.github.ben-manes.caffeine</groupId>
+            <artifactId>caffeine</artifactId>
         </dependency>
 
         <dependency>
@@ -130,6 +135,12 @@
             <artifactId>dom4j</artifactId>
             <version>2.1.1</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.quartz-scheduler</groupId>
+            <artifactId>quartz</artifactId>
+            <version>2.3.2</version>
+        </dependency>
     </dependencies>
 
     <profiles>

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/AppCompile.java

@@ -21,7 +21,7 @@ public class AppCompile extends BaseEntity {
     private String compilerName;
     private String compilerHome;
     private String versionCmd;
-    private String script;
+    private String compileCmd;
 
     public AppCompile vo() {
         this.setId(null);

+ 1 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/ConfigService.java

@@ -153,10 +153,7 @@ public class ConfigService {
     }
 
     private void checkScript(String script) throws Exception {
-        ShellResult shellResult = shellExecutor.execute(script);
-        if (shellResult.hasError()) {
-            throw new Exception(shellResult.getStdout());
-        }
+        // TODO 检查脚本
     }
 
     public PageList getByPage(String configType, PageRequest pageRequest) throws Exception {

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/CodeCompiler.java

@@ -9,10 +9,10 @@ package cn.reghao.autodop.dmaster.app.service.tools.compiler;
 public interface CodeCompiler {
     /**
      * @param appName 应用名字
-     * @param appDir 应用目录
+     * @param appHome 应用目录
      * @param env 应用环境
      * @return
      * @date 2020-01-21 下午4:20
      */
-    void compile(String appName, String appDir, String env) throws Exception;
+    void compile(String appName, String appHome, String env) throws Exception;
 }

+ 5 - 19
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/ShellCompiler.java

@@ -5,10 +5,6 @@ import cn.reghao.autodop.common.shell.ShellResult;
 import cn.reghao.autodop.common.utils.JsonUtil;
 import cn.reghao.autodop.dmaster.app.entity.build.AppCompile;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 /**
  * 编译代码
  *
@@ -16,29 +12,19 @@ import java.util.Map;
  * @date 2019-10-12 23:55:01
  */
 public class ShellCompiler implements CodeCompiler {
-    private String script;
+    private String cmd;
     private ShellExecutor shell;
 
     public ShellCompiler(AppCompile appCompile) {
-        this.script = appCompile.getCompilerHome() + "/" + appCompile.getScript();
+        this.cmd = appCompile.getCompilerHome() + "/" + appCompile.getCompileCmd();
         this.shell = new ShellExecutor();
     }
 
     @Override
-    public void compile(String appName, String appDir, String env) throws Exception {
-        String logfile = System.getProperty("java.io.tmpdir") + "/" + appName;
-        String[] arr = new String[3];
-        arr[0] = logfile;
-        arr[1] = appName;
-        arr[2] = appDir;
-        //ShellResult result1 = shell.execute(script, arr);
-
-        ShellResult result = shell.execute(appDir, script);
+    public void compile(String appName, String appHome, String env) throws Exception {
+        ShellResult result = shell.execCommand(appHome, cmd, true);
         if (result.hasError()) {
-            Map<String, String> map = new HashMap<>();
-            map.put("stdout", result.getStdout());
-            map.put("stderr", result.getStderr());
-            throw new Exception(JsonUtil.objectToJson(map));
+            throw new Exception(JsonUtil.objectToJson(result.getStderr()));
         }
     }
 }

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/jwt/JwtTokenFilter.java

@@ -29,7 +29,7 @@ public class JwtTokenFilter extends OncePerRequestFilter {
         String uri = request.getRequestURI();
         String method = request.getMethod();
         // TODO 不处理 OPTIONS 请求、webhook 接口和非 /api 开头的请求
-        if ("OPTIONS".equals(method) || uri.startsWith("/api/monitor") || uri.startsWith("/api/vm") || !uri.startsWith("/api")) {
+        if ("OPTIONS".equals(method) || uri.startsWith("/api/backup") || uri.startsWith("/api/monitor") || uri.startsWith("/api/vm") || !uri.startsWith("/api")) {
             chain.doFilter(request, response);
             return;
         }

+ 3 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/BackupController.java

@@ -1,6 +1,7 @@
 package cn.reghao.autodop.dmaster.backup;
 
 import cn.reghao.autodop.common.result.WebResult;
+import cn.reghao.autodop.dmaster.backup.entity.BakService;
 import io.swagger.annotations.Api;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -11,7 +12,7 @@ import org.springframework.web.bind.annotation.RestController;
  * @author reghao
  * @date 2019-11-15 08:44:50
  */
-@Api(tags = "备份接口")
+@Api(tags = "数据备份和还原接口")
 @RestController
 @RequestMapping("/api/backup")
 public class BackupController {
@@ -22,7 +23,7 @@ public class BackupController {
     }
 
     @PostMapping("/service")
-    public String addService() {
+    public String addService(BakService bakService) {
         return WebResult.success("ok");
     }
 

+ 79 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/BackupScheduler.java

@@ -0,0 +1,79 @@
+package cn.reghao.autodop.dmaster.backup;
+
+import cn.reghao.autodop.common.shell.ShellExecutor;
+import cn.reghao.autodop.dmaster.backup.entity.BakService;
+import org.quartz.*;
+import org.quartz.impl.StdSchedulerFactory;
+import org.springframework.stereotype.Service;
+
+/**
+ * 备份调度器
+ *
+ * @author reghao
+ * @date 2020-11-10 13:41:11
+ */
+@Service
+public class BackupScheduler {
+    private Scheduler scheduler;
+    private ShellExecutor executor;
+
+    public BackupScheduler() throws SchedulerException {
+        this.scheduler = StdSchedulerFactory.getDefaultScheduler();
+        this.executor = new ShellExecutor();
+    }
+
+    public void add(BakService bakService) throws SchedulerException {
+        JobDataMap jobDataMap = new JobDataMap();
+        // 只传入一组 KV
+        jobDataMap.put(bakService.getBakScript(), executor);
+        JobDetail jobDetail = JobBuilder.newJob(ScriptBakJob.class)
+                .withIdentity(bakService.getServiceName())
+                .usingJobData(jobDataMap)
+                .build();
+
+        TriggerBuilder<CronTrigger> triggerBuilder = TriggerBuilder
+                .newTrigger()
+                .withIdentity(bakService.getServiceName() + "@trigger")
+                .withSchedule(CronScheduleBuilder.cronSchedule(bakService.getCronExp()));
+        CronTrigger cronTrigger = triggerBuilder.build();
+
+        scheduler.scheduleJob(jobDetail, cronTrigger);
+    }
+
+    public void remove() {
+    }
+
+    public void start() throws SchedulerException {
+        if (!scheduler.isShutdown()) {
+            scheduler.start();
+        }
+    }
+
+    public void pause() throws SchedulerException {
+        if (!scheduler.isShutdown()) {
+            scheduler.pauseAll();
+        }
+    }
+
+    public static void main(String[] args) throws SchedulerException {
+        BakService bakService = new BakService();
+        bakService.setServiceName("nexus");
+        bakService.setIp("192.168.0.50");
+        String bakScript = "logfile=$1\n" +
+                "\n" +
+                "cat > rsyncd_secret << EOF\n" +
+                "123456\n" +
+                "EOF\n" +
+                "chmod 600 rsyncd_secret\n" +
+                "\n" +
+                "rsync -avzP --delete --password-file=./rsyncd_secret azy@192.168.0.50::nexus /home/reghao/opt/data/backup/nexus > ${logfile} 2>&1";
+        bakScript = "/home/reghao/work/azy/svn/test/4-运维管理/备份还原/rsync_nexus.sh";
+        bakService.setBakScript(bakScript);
+        String cronExp = "0 */1 * * * ?";
+        bakService.setCronExp(cronExp);
+
+        BackupScheduler scheduler = new BackupScheduler();
+        scheduler.add(bakService);
+        scheduler.start();
+    }
+}

+ 20 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/BackupService.java

@@ -1,11 +1,28 @@
 package cn.reghao.autodop.dmaster.backup;
 
-import org.springframework.stereotype.Service;
+import cn.reghao.autodop.dmaster.backup.entity.BakService;
 
 /**
  * @author reghao
  * @date 2020-10-22 17:51:56
  */
-@Service
-public class BackupService {
+public interface BackupService {
+    /**
+     * 备份数据
+     *
+     * @param bakService 需要备份的服务
+     * @return 备份的 ID
+     * @date 2020-11-09 下午8:53
+     */
+    String backup(BakService bakService) throws Exception;
+
+    /**
+     * 还原数据
+     *
+     * @param serviceName 需要还原的服务名字
+     * @param bakId 备份 ID
+     * @return
+     * @date 2020-11-09 下午8:53
+     */
+    void restore(String serviceName, String bakId);
 }

+ 28 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/BackupServiceImpl.java

@@ -0,0 +1,28 @@
+package cn.reghao.autodop.dmaster.backup;
+
+import cn.reghao.autodop.dmaster.backup.entity.BakService;
+import org.quartz.SchedulerException;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author reghao
+ * @date 2020-11-10 15:20:04
+ */
+@Service
+public class BackupServiceImpl implements BackupService {
+    private BackupScheduler backupScheduler;
+
+    public BackupServiceImpl(BackupScheduler backupScheduler) {
+        this.backupScheduler = backupScheduler;
+    }
+
+    @Override
+    public String backup(BakService bakService) throws SchedulerException {
+        backupScheduler.add(bakService);
+        return null;
+    }
+
+    @Override
+    public void restore(String serviceName, String bakId) {
+    }
+}

+ 44 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/ScriptBakJob.java

@@ -0,0 +1,44 @@
+package cn.reghao.autodop.dmaster.backup;
+
+import cn.reghao.autodop.common.shell.ShellExecutor;
+import cn.reghao.autodop.common.shell.ShellResult;
+import cn.reghao.autodop.common.utils.DateTimeUtil;
+import cn.reghao.autodop.dmaster.backup.entity.BakLog;
+import lombok.extern.slf4j.Slf4j;
+import org.quartz.*;
+
+/**
+ * 脚本备份任务
+ *
+ * @author reghao
+ * @date 2020-11-10 13:43:55
+ */
+@Slf4j
+public class ScriptBakJob implements Job {
+    @Override
+    public void execute(JobExecutionContext context) throws JobExecutionException {
+        JobKey jobKey = context.getJobDetail().getKey();
+        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
+        String script = jobDataMap.getKeys()[0];
+        BakLog bakLog = new BakLog();
+        bakLog.setServiceName(jobKey.getName());
+        bakLog.setBakTime(DateTimeUtil.now());
+
+        ShellExecutor executor = (ShellExecutor) jobDataMap.get(script);
+        log.info("执行 {} 定时任务...", jobKey.getName());
+        try {
+            ShellResult shellResult = executor.execScript(script);
+            if (!shellResult.hasError()) {
+                bakLog.setSuccess(true);
+                bakLog.setResult(shellResult.getStdout());
+            } else {
+                bakLog.setSuccess(false);
+                bakLog.setResult(shellResult.getStderr());
+            }
+        } catch (Exception e) {
+            bakLog.setSuccess(false);
+            bakLog.setResult(e.getMessage());
+        }
+        log.info("bakLog -> {}", bakLog);
+    }
+}

+ 17 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/entity/BakLog.java

@@ -0,0 +1,17 @@
+package cn.reghao.autodop.dmaster.backup.entity;
+
+import lombok.Data;
+
+/**
+ * 备份日志
+ *
+ * @author reghao
+ * @date 2020-11-10 17:15:59
+ */
+@Data
+public class BakLog {
+    private String serviceName;
+    private String bakTime;
+    private boolean isSuccess;
+    private String result;
+}

+ 25 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/entity/BakService.java

@@ -0,0 +1,25 @@
+package cn.reghao.autodop.dmaster.backup.entity;
+
+import cn.reghao.autodop.dmaster.app.entity.BaseEntity;
+import lombok.Data;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+
+/**
+ * 需要数据备份和还原的服务
+ *
+ * @author reghao
+ * @date 2020-11-09 20:42:38
+ */
+@Data
+@Entity
+public class BakService extends BaseEntity {
+    @Column(nullable = false, unique = true)
+    private String serviceName;
+    private String ip;
+    private int port;
+    private String bakScript;
+    private String bakDir;
+    private String cronExp;
+}

+ 12 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/backup/repository/BakServiceRepository.java

@@ -0,0 +1,12 @@
+package cn.reghao.autodop.dmaster.backup.repository;
+
+import cn.reghao.autodop.dmaster.backup.entity.BakService;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+/**
+ * @author reghao
+ * @date 2020-01-21 14:53:03
+ */
+public interface BakServiceRepository extends JpaRepository<BakService, Long> {
+
+}

+ 3 - 0
dmaster/src/main/resources/application-dev.yml

@@ -3,6 +3,9 @@ spring:
     url: jdbc:mysql://localhost:3306/reghao_autodop_rdb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8
     username: reghao
     password: 12345678
+  data:
+    mongodb:
+      uri: mongodb://localhost/test
   rabbitmq:
     host: mq.srv.iquizoo.com
     port: 5672

+ 1 - 0
rsyncd_secret

@@ -0,0 +1 @@
+123456

+ 5 - 5
scripts/build-and-deploy.sh → scripts/build_and_deploy.sh

@@ -6,11 +6,11 @@
 #sh build.sh test dmaster
 #sh deploy.sh autodop-dmaster 192.168.0.50 azy &
 
-#sh build.sh test dagent
-#sh deploy.sh autodop-dagent 192.168.0.171 azy &
-#sh deploy.sh autodop-dagent 192.168.0.172 azy &
-#sh deploy.sh autodop-dagent 192.168.0.173 azy &
-#sh deploy.sh autodop-dagent 192.168.0.174 azy &
+sh build.sh test dagent
+sh deploy.sh autodop-dagent 192.168.0.171 azy &
+sh deploy.sh autodop-dagent 192.168.0.172 azy &
+sh deploy.sh autodop-dagent 192.168.0.173 azy &
+sh deploy.sh autodop-dagent 192.168.0.174 azy &
 
 #sh deploy.sh autodop-dagent 192.168.0.214 azy &
 #sh deploy.sh autodop-dagent 192.168.0.220 azy &

+ 0 - 0
scripts/post-commit → scripts/svn_post_commit