main
黄海 7 months ago
parent e9bbce4844
commit 098745d8bc

@ -43,7 +43,8 @@ public class MysqlBackupUtil {
"-h" + host, "-h" + host,
"-P" + port, "-P" + port,
"-u" + user, "-u" + user,
"--ssl-mode=DISABLED", //"--ssl-mode=DISABLED",
"--skip-ssl", // MariaDB 使用 --skip-ssl
"--no-tablespaces", // 避免权限问题 "--no-tablespaces", // 避免权限问题
"--default-character-set=utf8", "--default-character-set=utf8",
"--single-transaction", "--single-transaction",

@ -20,17 +20,18 @@ public class MysqlRestoreUtil {
public MysqlRestoreUtil() { public MysqlRestoreUtil() {
// 从配置文件读取配置 // 从配置文件读取配置
this.obsEndpoint = PropKit.get("obs.endPoint"); this.obsEndpoint = PropKit.get("obs_endpoint");
this.obsAccessKey = PropKit.get("obs.accessKey"); this.obsAccessKey = PropKit.get("obs_accessKeyId");
this.obsSecretKey = PropKit.get("obs.secretKey"); this.obsSecretKey = PropKit.get("obs_accessKeySecret");
this.obsBucket = PropKit.get("obs.bucketName"); this.obsBucket = PropKit.get("obs_bucket_name");
// 目标数据库配置 // 目标数据库配置
this.dbHost = CommonUtil.getHostFromJdbcUrl(PropKit.get("write.jdbcUrl")); String jdbcUrl=PropKit.get("write.jdbcUrl");
this.dbPort = CommonUtil.getPortFromJdbcUrl(PropKit.get("write.jdbcUrl")); this.dbHost = CommonUtil.getHostFromJdbcUrl(jdbcUrl);
this.dbPort = CommonUtil.getPortFromJdbcUrl(jdbcUrl);
this.dbUser = PropKit.get("write.user"); this.dbUser = PropKit.get("write.user");
this.dbPassword = PropKit.get("write.password"); this.dbPassword = PropKit.get("write.password");
this.dbName = CommonUtil.getDatabaseFromJdbcUrl(PropKit.get("write.jdbcUrl")); this.dbName = CommonUtil.getDatabaseFromJdbcUrl(jdbcUrl);
} }
/** /**
@ -100,11 +101,9 @@ public class MysqlRestoreUtil {
} }
} }
} }
if (extractedFile == null) { if (extractedFile == null) {
throw new RuntimeException("ZIP文件中没有找到SQL文件"); throw new RuntimeException("ZIP文件中没有找到SQL文件");
} }
return extractedFile; return extractedFile;
} }
@ -159,9 +158,8 @@ public class MysqlRestoreUtil {
// 等待命令执行完成 // 等待命令执行完成
int exitCode = process.waitFor(); int exitCode = process.waitFor();
if (exitCode != 0) { if (exitCode != 0) {
throw new RuntimeException("数据库还原失败:\n" + errorOutput.toString()); throw new RuntimeException("数据库还原失败:\n" + errorOutput);
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("还原数据库失败: " + e.getMessage(), e); throw new RuntimeException("还原数据库失败: " + e.getMessage(), e);
} }

Loading…
Cancel
Save