|
|
|
@ -3,18 +3,11 @@ package com.dsideal.YunXiaoTools.Service;
|
|
|
|
|
import com.dsideal.YunXiaoTools.Utils.CommonUtil;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.obs.services.ObsClient;
|
|
|
|
|
import com.obs.services.model.ListObjectsRequest;
|
|
|
|
|
import com.obs.services.model.ObjectListing;
|
|
|
|
|
import com.obs.services.model.ObsObject;
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.util.zip.*;
|
|
|
|
|
|
|
|
|
|
public class MysqlRestoreService {
|
|
|
|
|
private final String obsEndpoint;
|
|
|
|
|
private final String obsAccessKey;
|
|
|
|
|
private final String obsSecretKey;
|
|
|
|
|
private final String obsBucket;
|
|
|
|
|
|
|
|
|
|
// 目标数据库配置
|
|
|
|
|
private final String dbHost;
|
|
|
|
@ -24,12 +17,6 @@ public class MysqlRestoreService {
|
|
|
|
|
private final String dbName;
|
|
|
|
|
|
|
|
|
|
public MysqlRestoreService() {
|
|
|
|
|
// 从配置文件读取配置
|
|
|
|
|
this.obsEndpoint = PropKit.get("obs_endpoint");
|
|
|
|
|
this.obsAccessKey = PropKit.get("obs_accessKeyId");
|
|
|
|
|
this.obsSecretKey = PropKit.get("obs_accessKeySecret");
|
|
|
|
|
this.obsBucket = PropKit.get("obs_bucket_name");
|
|
|
|
|
|
|
|
|
|
// 目标数据库配置
|
|
|
|
|
String jdbcUrl = PropKit.get("write.jdbcUrl");
|
|
|
|
|
this.dbHost = CommonUtil.getHostFromJdbcUrl(jdbcUrl);
|
|
|
|
@ -78,10 +65,23 @@ public class MysqlRestoreService {
|
|
|
|
|
* 从OBS下载文件
|
|
|
|
|
*/
|
|
|
|
|
private void downloadFromObs(String obsKey, String localFile) {
|
|
|
|
|
try (ObsClient obsClient = new ObsClient(obsAccessKey, obsSecretKey, obsEndpoint)) {
|
|
|
|
|
obsClient.getObject(obsBucket, obsKey, String.valueOf(new File(localFile)));
|
|
|
|
|
// 从配置文件中读取OBS配置
|
|
|
|
|
String endPoint = PropKit.get("obs_endpoint");
|
|
|
|
|
String ak = PropKit.get("obs_accessKeyId");
|
|
|
|
|
String sk = PropKit.get("obs_accessKeySecret");
|
|
|
|
|
String bucketName = PropKit.get("obs_bucket_name");
|
|
|
|
|
// 创建ObsClient实例
|
|
|
|
|
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
|
|
|
|
|
try {
|
|
|
|
|
obsClient.getObject(bucketName, obsKey, localFile);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException("从OBS下载文件失败: " + e.getMessage(), e);
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
obsClient.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|