From ed3d880974ae6a1430866eebaf72533f35258f6f Mon Sep 17 00:00:00 2001 From: Bogdan Date: Fri, 14 Apr 2023 05:53:32 +0300 Subject: [PATCH] New: Add version and timestamp to backup archive --- src/NzbDrone.Core/Backup/BackupService.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Core/Backup/BackupService.cs b/src/NzbDrone.Core/Backup/BackupService.cs index b9033c1e5..385a5690b 100644 --- a/src/NzbDrone.Core/Backup/BackupService.cs +++ b/src/NzbDrone.Core/Backup/BackupService.cs @@ -69,7 +69,8 @@ namespace NzbDrone.Core.Backup _diskProvider.EnsureFolder(_backupTempFolder); _diskProvider.EnsureFolder(GetBackupFolder(backupType)); - var backupFilename = string.Format("sonarr_backup_v{0}_{1:yyyy.MM.dd_HH.mm.ss}.zip", BuildInfo.Version, DateTime.Now); + var dateNow = DateTime.Now; + var backupFilename = $"sonarr_backup_v{BuildInfo.Version}_{dateNow:yyyy.MM.dd_HH.mm.ss}.zip"; var backupPath = Path.Combine(GetBackupFolder(backupType), backupFilename); Cleanup(); @@ -81,7 +82,7 @@ namespace NzbDrone.Core.Backup BackupConfigFile(); BackupDatabase(); - CreateVersionInfo(); + CreateVersionInfo(dateNow); _logger.ProgressDebug("Creating backup zip"); @@ -203,11 +204,15 @@ namespace NzbDrone.Core.Backup _diskTransferService.TransferFile(configFile, tempConfigFile, TransferMode.Copy); } - private void CreateVersionInfo() + private void CreateVersionInfo(DateTime dateNow) { + var tempFile = Path.Combine(_backupTempFolder, "INFO"); + var builder = new StringBuilder(); + builder.AppendLine($"v{BuildInfo.Version}"); + builder.AppendLine($"{dateNow:yyyy-MM-dd HH:mm:ss}"); - builder.AppendLine(BuildInfo.Version.ToString()); + _diskProvider.WriteAllText(tempFile, builder.ToString()); } private void CleanupOldBackups(BackupType backupType)