|
@@ -3,6 +3,10 @@ package com.ruoyi.quartz.task;
|
3
|
3
|
import org.springframework.stereotype.Component;
|
4
|
4
|
import com.ruoyi.common.utils.StringUtils;
|
5
|
5
|
|
|
6
|
+import java.io.File;
|
|
7
|
+import java.text.SimpleDateFormat;
|
|
8
|
+import java.util.Date;
|
|
9
|
+
|
6
|
10
|
/**
|
7
|
11
|
* 定时任务调度测试
|
8
|
12
|
*
|
|
@@ -25,4 +29,23 @@ public class RyTask
|
25
|
29
|
{
|
26
|
30
|
System.out.println("执行无参方法");
|
27
|
31
|
}
|
|
32
|
+
|
|
33
|
+ public void linuxDump(String dir, String username, String password, String databaseName) throws Exception {
|
|
34
|
+ File file = new File(dir);
|
|
35
|
+ if (!file.exists()) {
|
|
36
|
+ file.mkdir();
|
|
37
|
+ }
|
|
38
|
+ String sqlName = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
|
39
|
+ File datafile = new File(file + File.separator + sqlName + ".sql");
|
|
40
|
+ if (datafile.exists()) {
|
|
41
|
+ System.out.println(sqlName + "文件名已存在,请更换");
|
|
42
|
+ return;
|
|
43
|
+ }
|
|
44
|
+ //拼接cmd命令 windows下 cmd Linux下 /bin/sh
|
|
45
|
+ Process exec = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", "/usr/bin/mysqldump -u " + username + " -p" + password + " " + databaseName + " > " + datafile});
|
|
46
|
+ if (exec.waitFor() == 0) {
|
|
47
|
+ System.out.println("数据库备份成功,备份路径为:" + datafile);
|
|
48
|
+ }
|
|
49
|
+ }
|
|
50
|
+
|
28
|
51
|
}
|