|
|
|
@ -2,6 +2,7 @@ package com.dsideal.YunXiaoTools.Utils;
|
|
|
|
|
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.obs.services.ObsClient;
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.util.zip.*;
|
|
|
|
|
|
|
|
|
@ -26,7 +27,7 @@ public class MysqlRestoreUtil {
|
|
|
|
|
this.obsBucket = PropKit.get("obs_bucket_name");
|
|
|
|
|
|
|
|
|
|
// 目标数据库配置
|
|
|
|
|
String jdbcUrl=PropKit.get("write.jdbcUrl");
|
|
|
|
|
String jdbcUrl = PropKit.get("write.jdbcUrl");
|
|
|
|
|
this.dbHost = CommonUtil.getHostFromJdbcUrl(jdbcUrl);
|
|
|
|
|
this.dbPort = CommonUtil.getPortFromJdbcUrl(jdbcUrl);
|
|
|
|
|
this.dbUser = PropKit.get("write.user");
|
|
|
|
@ -36,6 +37,7 @@ public class MysqlRestoreUtil {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 执行完整的还原流程
|
|
|
|
|
*
|
|
|
|
|
* @param obsKey OBS上的文件路径
|
|
|
|
|
*/
|
|
|
|
|
public void restore(String obsKey) {
|
|
|
|
@ -113,7 +115,7 @@ public class MysqlRestoreUtil {
|
|
|
|
|
private void restoreDatabase(String sqlFile) {
|
|
|
|
|
try {
|
|
|
|
|
// 获取mysql命令路径
|
|
|
|
|
String mysqlPath = getMySQLPath();
|
|
|
|
|
String mysqlPath = CommonUtil.getMySQLPath();
|
|
|
|
|
|
|
|
|
|
// 构建还原命令
|
|
|
|
|
ProcessBuilder pb = new ProcessBuilder(
|
|
|
|
@ -164,20 +166,4 @@ public class MysqlRestoreUtil {
|
|
|
|
|
throw new RuntimeException("还原数据库失败: " + e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取mysql命令路径
|
|
|
|
|
*/
|
|
|
|
|
private String getMySQLPath() {
|
|
|
|
|
try {
|
|
|
|
|
String resourcePath = getClass().getClassLoader()
|
|
|
|
|
.getResource("mysql.exe").getPath();
|
|
|
|
|
if (resourcePath.startsWith("/")) {
|
|
|
|
|
resourcePath = resourcePath.substring(1);
|
|
|
|
|
}
|
|
|
|
|
return java.net.URLDecoder.decode(resourcePath, "UTF-8");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException("获取mysql路径失败", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|