🐛 修复文件清理逻辑
This commit is contained in:
parent
f41bd03f03
commit
2fd4ca7e6a
|
|
@ -186,7 +186,6 @@ public class BackupService(ILogger<BackupService> logger, IConfiguration config,
|
|||
|
||||
await CompressDirectoryAsync([dumpDir, extraDir], finalDump, ct);
|
||||
|
||||
Directory.Delete(dumpDir, recursive: true);
|
||||
_logger.LogInformation("Backup completed: {File}", finalDump);
|
||||
|
||||
_outputService.CleanOutputDirFiles();
|
||||
|
|
@ -198,6 +197,27 @@ public class BackupService(ILogger<BackupService> logger, IConfiguration config,
|
|||
_logger.LogError(ex, "Error during backup process.");
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(dumpDir))
|
||||
{
|
||||
Directory.Delete(dumpDir, recursive: true);
|
||||
_logger.LogInformation("Cleaned temporary dump directory: {Dir}", dumpDir);
|
||||
}
|
||||
|
||||
if (File.Exists(finalDump))
|
||||
{
|
||||
File.Delete(finalDump);
|
||||
_logger.LogInformation("Cleaned temporary archive file: {File}", finalDump);
|
||||
}
|
||||
}
|
||||
catch (Exception cleanupEx)
|
||||
{
|
||||
_logger.LogWarning(cleanupEx, "Failed to clean temporary files in /data/dumps.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CompressDirectoryAsync(string[] sourceDirs, string targetFile, CancellationToken ct)
|
||||
|
|
|
|||
Loading…
Reference in New Issue