Browse Source

工具修改

develop
lau572 8 months ago
parent
commit
8edea34384
  1. 19
      zc-business/src/main/java/com/zc/business/controller/DcMYSQLUtil.java

19
zc-business/src/main/java/com/zc/business/controller/DcMYSQLUtil.java

@ -18,16 +18,19 @@ public class DcMYSQLUtil {
String cmd = "";
String os = System.getProperties().getProperty("os.name");
if (os.contains("Windows")) {
// Windows 需要加上 cmd /c
cmd = "cmd /c mysqldump --single-transaction " + " -h" + host + " -P" + port + " -u" + userName + " -p" + password + " --databases --skip-extended-insert " + dbName + " > " + file.getPath();
} else {
// Linux 需要加上 /usr/local/mysql/bin/
cmd = "bash -c /usr/local/mysql/bin/mysqldump --single-transaction " + " -h" + host + " -P" + port + " -u" + userName + " -p'" + password + "' --databases --skip-extended-insert " + dbName + " > " + file.getPath();
}
System.out.printf("cmd命令为:%s%n", cmd);
try {
Process process = Runtime.getRuntime().exec(cmd);
Process process;
if (os.contains("Windows")) {
// Windows 需要加上 cmd /c
cmd = "cmd /c mysqldump --single-transaction " + " -h" + host + " -P" + port + " -u" + userName + " -p" + password + " --databases --skip-extended-insert " + dbName + " > " + file.getPath();
process = Runtime.getRuntime().exec(cmd);
} else {
// Linux 需要加上 /usr/local/mysql/bin/
cmd = "/usr/local/mysql/bin/mysqldump --single-transaction " + " -h" + host + " -P" + port + " -u" + userName + " -p'" + password + "' --databases --skip-extended-insert " + dbName + " > " + file.getPath();
process = Runtime.getRuntime().exec(new String[]{"bash","-c",cmd});
}
if (process.waitFor() == 0) {
System.out.printf(" 数据库:%s 备份成功!%n", dbName);

Loading…
Cancel
Save