1.优化数据库备份功能,每天备份前清除历史备份记录
This commit is contained in:
parent
462af65bd3
commit
438ec17bfe
|
@ -1,6 +1,9 @@
|
||||||
package com.platform.common.scheduled;
|
package com.platform.common.scheduled;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
import com.platform.common.properties.SystemProperties;
|
import com.platform.common.properties.SystemProperties;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -55,8 +58,23 @@ public class BackUpDataBaseManager {
|
||||||
if (!saveFile.exists()) {
|
if (!saveFile.exists()) {
|
||||||
saveFile.mkdirs();
|
saveFile.mkdirs();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
String host = getHost();
|
//每天备份前清除历史备份文件
|
||||||
|
final File[] files = saveFile.listFiles();
|
||||||
|
if(ArrayUtils.isNotEmpty(files)){
|
||||||
|
for(File file : files){
|
||||||
|
if(file.isFile()){
|
||||||
|
FileUtils.delete(file);
|
||||||
|
}else if(file.isDirectory()){
|
||||||
|
FileUtils.deleteDirectory(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("数据库备份目录清除失败", e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
String host = getHost();
|
||||||
String dataBaseName = getDataBaseName();
|
String dataBaseName = getDataBaseName();
|
||||||
String fileName = time + "_" + "cloudpm.sql";
|
String fileName = time + "_" + "cloudpm.sql";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user