实现windows备份,方便测试。
This commit is contained in:
parent
4fa47dc8e5
commit
c76d5c8c78
|
|
@ -30,6 +30,11 @@ public class FileController {
|
|||
@Resource
|
||||
private BackupPro backupPro;
|
||||
|
||||
@RequestMapping("/ping")
|
||||
public String ping() {
|
||||
return "pong";
|
||||
}
|
||||
|
||||
@RequestMapping("/upload")
|
||||
public ElectromagneticResult<?> upload(@RequestParam("file") MultipartFile file) {
|
||||
BackupFileResLog backupFileResLog = BackupFileResLog.builder().backupStartTime(new Date()).fileName(file.getOriginalFilename()).backupSuccess(true).build();
|
||||
|
|
|
|||
|
|
@ -15,4 +15,4 @@ server:
|
|||
|
||||
file:
|
||||
enc:
|
||||
passwd: adknfhkj87654knd
|
||||
passwd: 123456
|
||||
|
|
@ -37,7 +37,7 @@ import com.electromagnetic.industry.software.manage.pojo.resp.FileProjectVO;
|
|||
import com.electromagnetic.industry.software.manage.pojo.resp.FileVersionViewVO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.UploadRecordVO;
|
||||
import com.electromagnetic.industry.software.manage.service.*;
|
||||
import com.electromagnetic.industry.software.manage.tasks.FlushDataStatusList;
|
||||
import com.electromagnetic.industry.software.manage.tasks.EleConstant;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -327,7 +327,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
log.error(info, e);
|
||||
throw new BizException(info);
|
||||
} finally {
|
||||
FlushDataStatusList.add(id);
|
||||
EleConstant.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import cn.hutool.core.text.StrFormatter;
|
|||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.RuntimeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.electromagnetic.industry.software.common.enums.EleDataStatusEnum;
|
||||
|
|
@ -62,8 +63,8 @@ public class BackupTask {
|
|||
|
||||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void backup() {
|
||||
if (EleCommonUtil.isWinOs()) {
|
||||
log.info("运行环境为windows,不需要备份文件");
|
||||
if (!isRemotePortListening(elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort())) {
|
||||
log.info("备份环境连接失败,未备份文件");
|
||||
return;
|
||||
}
|
||||
// 首先查看备份失败的文件
|
||||
|
|
@ -179,7 +180,8 @@ public class BackupTask {
|
|||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void backupSql() {
|
||||
if (EleCommonUtil.isWinOs()) {
|
||||
log.info("运行环境为windows,不需要备份SQL");
|
||||
// if (EleCommonUtil.isRemotePortListening(elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort())) {
|
||||
log.info("windows暂不支持sql文件备份");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
|
@ -279,10 +281,20 @@ public class BackupTask {
|
|||
// 每 2 分钟执行一次
|
||||
@Scheduled(cron = "*/3 * * * * ?")
|
||||
public void updateFileStatus() {
|
||||
String id = FlushDataStatusList.get();
|
||||
String id = EleConstant.get();
|
||||
if (StrUtil.isNotEmpty(id)) {
|
||||
edFileInfoMapper.update(new EdFileInfo(), Wrappers.<EdFileInfo>lambdaUpdate().eq(EdFileInfo::getId, id).set(EdFileInfo::getDataStatus, EleDataStatusEnum.PUBLISHED.code));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isRemotePortListening(String host, int port) {
|
||||
try {
|
||||
String url = StrFormatter.format("http://{}:{}/data/file/backup/ping", host, port);
|
||||
HttpUtil.get(url);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import java.util.Date;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class FlushDataStatusList {
|
||||
public class EleConstant {
|
||||
|
||||
private static final Map<String, Date> MAP = new ConcurrentHashMap<>();
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ prj.folder.max.length=6
|
|||
# backupFiles
|
||||
tmp.file.store.hour=48
|
||||
backup.remote.host=127.0.0.1
|
||||
backup.remote.port=1111
|
||||
backup.remote.port=12491
|
||||
backup.mysql.path=/workspace/mysqlbak/test
|
||||
backup.mysql.script.path=/workspace/mysqlbak/back_dev.sh
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue