|
|
|
@ -15,9 +15,9 @@ import java.util.zip.*;
|
|
|
|
|
|
|
|
|
|
public class MysqlRestoreService {
|
|
|
|
|
|
|
|
|
|
private final String jdbcUrl;
|
|
|
|
|
private final String username;
|
|
|
|
|
private final String password;
|
|
|
|
|
public final String jdbcUrl;
|
|
|
|
|
public final String username;
|
|
|
|
|
public final String password;
|
|
|
|
|
|
|
|
|
|
public MysqlRestoreService() {
|
|
|
|
|
jdbcUrl = PropKit.get("write.jdbcUrl");
|
|
|
|
@ -30,10 +30,11 @@ public class MysqlRestoreService {
|
|
|
|
|
*
|
|
|
|
|
* @param obsKey OBS上的文件路径
|
|
|
|
|
*/
|
|
|
|
|
public void restore(String jdbcUrl, String username, String password, String obsKey) {
|
|
|
|
|
public int restore(String jdbcUrl, String username, String password, String obsKey) {
|
|
|
|
|
String tempDir = System.getProperty("java.io.tmpdir");
|
|
|
|
|
String sqlFile = null;
|
|
|
|
|
String zipFile = tempDir + obsKey.split("/")[2];
|
|
|
|
|
int total;
|
|
|
|
|
try {
|
|
|
|
|
// 1. 从OBS下载ZIP文件
|
|
|
|
|
downloadFromObs(obsKey, tempDir);
|
|
|
|
@ -52,7 +53,7 @@ public class MysqlRestoreService {
|
|
|
|
|
conn.setAutoCommit(false); // 开启事务
|
|
|
|
|
|
|
|
|
|
try (Statement stmt = conn.createStatement()) {
|
|
|
|
|
int total = sqlStatements.size();
|
|
|
|
|
total = sqlStatements.size();
|
|
|
|
|
int current = 0;
|
|
|
|
|
|
|
|
|
|
for (String sql : sqlStatements) {
|
|
|
|
@ -93,6 +94,7 @@ public class MysqlRestoreService {
|
|
|
|
|
new File(sqlFile).delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return total;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -190,7 +192,6 @@ public class MysqlRestoreService {
|
|
|
|
|
PropKit.use("application.properties");
|
|
|
|
|
//获取最后一次上传的数据库文件
|
|
|
|
|
String key = CommonUtil.getLastDataBaseZip();
|
|
|
|
|
|
|
|
|
|
//还原数据库
|
|
|
|
|
MysqlRestoreService mr = new MysqlRestoreService();
|
|
|
|
|
mr.restore(mr.jdbcUrl, mr.username, mr.password, key);
|
|
|
|
|