✨ 添加清理输出文件夹功能
This commit is contained in:
parent
5f3f3fd43e
commit
d776829009
|
|
@ -185,6 +185,7 @@ public class BackupService(ILogger<BackupService> logger, IConfiguration config,
|
|||
Directory.Delete(dumpDir, recursive: true);
|
||||
_logger.LogInformation("Backup completed: {File}", finalDump);
|
||||
|
||||
await _outputService.CleanOutputDirFiles();
|
||||
await _outputService.AddFileToOutput(finalDump);
|
||||
//await _cosService.AddFileToCOS(finalDump);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,5 +48,38 @@ namespace SQLBackupToCOS
|
|||
throw;
|
||||
}
|
||||
}
|
||||
public async Task CleanOutputDirFiles()
|
||||
{
|
||||
try
|
||||
{
|
||||
string outputPath = _config.GetValue<string>("outputDir") ?? "/output";
|
||||
if (Directory.Exists(outputPath))
|
||||
{
|
||||
var files = Directory.GetFiles(outputPath);
|
||||
foreach (var file in files)
|
||||
{
|
||||
_logger.LogInformation($"Deleting file: {file}");
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Failed to delete file: {file}");
|
||||
}
|
||||
}
|
||||
_logger.LogInformation("All files in output directory have been deleted.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning($"Output directory does not exist: {outputPath}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to clean output directory");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue