1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00

New: Add version and timestamp to backup archive

This commit is contained in:
Bogdan 2023-04-14 05:53:32 +03:00 committed by GitHub
parent 39350ed0de
commit ed3d880974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,7 +69,8 @@ public void Backup(BackupType backupType)
_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 @@ public void Backup(BackupType backupType)
BackupConfigFile();
BackupDatabase();
CreateVersionInfo();
CreateVersionInfo(dateNow);
_logger.ProgressDebug("Creating backup zip");
@ -203,11 +204,15 @@ private void BackupConfigFile()
_diskTransferService.TransferFile(configFile, tempConfigFile, TransferMode.Copy);
}
private void CreateVersionInfo()
private void CreateVersionInfo(DateTime dateNow)
{
var builder = new StringBuilder();
var tempFile = Path.Combine(_backupTempFolder, "INFO");
builder.AppendLine(BuildInfo.Version.ToString());
var builder = new StringBuilder();
builder.AppendLine($"v{BuildInfo.Version}");
builder.AppendLine($"{dateNow:yyyy-MM-dd HH:mm:ss}");
_diskProvider.WriteAllText(tempFile, builder.ToString());
}
private void CleanupOldBackups(BackupType backupType)