调整定时备份相关
This commit is contained in:
parent
9ac1b9fdf5
commit
19ed3f1b1b
|
|
@ -2,8 +2,10 @@ package com.electromagnetic.industry.software.manage;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import com.electromagnetic.industry.software.manage.pojo.models.FileBackupLog;
|
|||
import com.electromagnetic.industry.software.manage.pojo.models.UserAccessLog;
|
||||
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
||||
import com.electromagnetic.industry.software.manage.service.serviceimpl.CommonService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -33,6 +34,7 @@ import java.util.List;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class BackupTask {
|
||||
|
||||
@Resource
|
||||
|
|
@ -50,7 +52,7 @@ public class BackupTask {
|
|||
@Resource
|
||||
private BackupHandler backupHandler;
|
||||
|
||||
@Scheduled(cron = "0 0 1 * * ?")
|
||||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void backup() {
|
||||
|
||||
// 首先查看备份失败的文件
|
||||
|
|
@ -158,6 +160,7 @@ public class BackupTask {
|
|||
|
||||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void backupSql() {
|
||||
try {
|
||||
String sqlDirs = elePropertyConfig.getSqlDirs();
|
||||
File[] files = new File(sqlDirs).listFiles((file, name) -> name.endsWith(".sql"));
|
||||
File maxModifyTimeFile = null;
|
||||
|
|
@ -171,7 +174,6 @@ public class BackupTask {
|
|||
maxModifyTimeFile = file;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxModifyTimeFile == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -183,6 +185,7 @@ public class BackupTask {
|
|||
if (CollUtil.isNotEmpty(successBacks)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
BackupFileResLog resLog = backupHandler.backupSql(maxModifyTimeFile.getAbsolutePath());
|
||||
long endTime = System.currentTimeMillis();
|
||||
|
|
@ -210,7 +213,9 @@ public class BackupTask {
|
|||
.set(FileBackupLog::getFailInfoDetail, resLog.getFailInfoDetail())
|
||||
.set(FileBackupLog::isBackupSuccess, resLog.getBackupSuccess()));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("备份SQL文件异常,原因 {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue