fix: 网站备份时,上级目录不存在的问题 (#1056)

* 增加网站备份,临时文件不存在时创建

* 增加数据导出,临时文件不存在时创建

* 修改整站备份,数据导出,临时文件不存在时创建
pull/1066/head
bruin-sxk 2020-09-12 17:54:45 +08:00 committed by GitHub
parent dd4c602526
commit 236b3c418f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -177,7 +177,11 @@ public class BackupServiceImpl implements BackupService {
DateTimeUtils.format(LocalDateTime.now(), DateTimeUtils.HORIZONTAL_LINE_DATETIME_FORMATTER) +
IdUtil.simpleUUID().hashCode() + ".zip";
// Create halo zip file
Path haloZipPath = Files.createFile(Paths.get(haloProperties.getBackupDir(), haloZipFileName));
Path haloZipFilePath = Paths.get(haloProperties.getBackupDir(), haloZipFileName);
if (!Files.exists(haloZipFilePath.getParent())) {
Files.createDirectories(haloZipFilePath.getParent());
}
Path haloZipPath = Files.createFile(haloZipFilePath);
// Zip halo
run.halo.app.utils.FileUtils.zip(Paths.get(this.haloProperties.getWorkDir()), haloZipPath);
@ -297,7 +301,11 @@ public class BackupServiceImpl implements BackupService {
DateTimeUtils.format(LocalDateTime.now(), DateTimeUtils.HORIZONTAL_LINE_DATETIME_FORMATTER) +
IdUtil.simpleUUID().hashCode() + ".json";
Path haloDataPath = Files.createFile(Paths.get(haloProperties.getDataExportDir(), haloDataFileName));
Path haloDataFilePath = Paths.get(haloProperties.getDataExportDir(), haloDataFileName);
if (!Files.exists(haloDataFilePath.getParent())) {
Files.createDirectories(haloDataFilePath.getParent());
}
Path haloDataPath = Files.createFile(haloDataFilePath);
FileWriter fileWriter = new FileWriter(haloDataPath.toFile(), CharsetUtil.UTF_8);
fileWriter.write(JsonUtils.objectToJson(data));