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