From 2fd4ca7e6a537a992623dbc8cefd10be9d076302 Mon Sep 17 00:00:00 2001 From: li_chx Date: Sun, 22 Mar 2026 13:12:58 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=B8=85=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SQLBackupToCOS/BackupService.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/SQLBackupToCOS/BackupService.cs b/SQLBackupToCOS/BackupService.cs index 6b8b79b..f9945aa 100644 --- a/SQLBackupToCOS/BackupService.cs +++ b/SQLBackupToCOS/BackupService.cs @@ -186,7 +186,6 @@ public class BackupService(ILogger 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 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)