|
@@ -26,6 +26,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
@@ -55,8 +56,8 @@ public class OutMysqlServiceImpl extends OutBaseService implements IOutMysqlServ
|
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(params);
|
|
|
|
|
|
-// String hostname = jsonObject.getString("host");
|
|
|
-// int port = jsonObject.getIntValue("port");
|
|
|
+ String host = jsonObject.getString("host");
|
|
|
+ int port = jsonObject.getIntValue("port");
|
|
|
|
|
|
String user = jsonObject.getString("user");
|
|
|
String pass = jsonObject.getString("pass");
|
|
@@ -68,10 +69,27 @@ public class OutMysqlServiceImpl extends OutBaseService implements IOutMysqlServ
|
|
|
String syncDir = syncDIr();
|
|
|
String exportName = String.format("%s_%s.sql", db, time);
|
|
|
String exportPath = tmpDir + exportName;
|
|
|
- String cmd = String.format("mysqldump -u%s -p%s %s > %s", user, pass, db, exportPath);
|
|
|
- LinuxCommand.exec(cmd);
|
|
|
+
|
|
|
+ List<String> commands = new ArrayList<>();
|
|
|
+ commands.add("/usr/bin/mysqldump");
|
|
|
+ commands.add("-u" + user);
|
|
|
+ commands.add("-h");
|
|
|
+ commands.add(host);
|
|
|
+ commands.add("-P");
|
|
|
+ commands.add(port + "");
|
|
|
+ commands.add("-p" + pass);
|
|
|
+ commands.add("-B");
|
|
|
+ commands.add(db);
|
|
|
+ commands.add("--set-gtid-purged=off");
|
|
|
+ commands.add("--default-character-set=utf8");
|
|
|
+ commands.add("--skip-tz-utc");
|
|
|
+ commands.add("--lock-tables=false");
|
|
|
+ commands.add("--skip-add-locks");
|
|
|
+
|
|
|
|
|
|
try {
|
|
|
+
|
|
|
+ LinuxCommand.mysqlExport(commands, exportPath);
|
|
|
//移动备份文件
|
|
|
Path target = Paths.get(syncDir + exportName);
|
|
|
Files.move(Paths.get(exportPath), target, StandardCopyOption.REPLACE_EXISTING);
|
|
@@ -87,8 +105,9 @@ public class OutMysqlServiceImpl extends OutBaseService implements IOutMysqlServ
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
mapper.writeValue(descFile, desc);
|
|
|
//生成描述json文件--end
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("mysql备份文件从临时目录移动至同步目录失败!", exportPath, syncDir + exportName);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("mysql备份文件从临时目录{}移动至同步目录{}失败!", exportPath, syncDir + exportName);
|
|
|
}
|
|
|
}
|
|
|
}
|