This commit is contained in:
2020-05-23 13:51:58 +00:00
parent 6f7f162de4
commit ff3946b2b0
4 changed files with 46 additions and 21 deletions

View File

@@ -171,16 +171,16 @@ namespace AyaNova.Util
/// <summary>
/// Get date of newest backup file or minvalue if not found
/// Get date of newest automatic backup file or minvalue if not found
///
/// </summary>
/// <returns></returns>
internal static DateTime MostRecentBackupFileDate()
internal static DateTime MostRecentAutomatedBackupFileDate()
{
DateTime LastBackup = DateTime.MinValue;
var BackupPath = UtilityFilesFolder;
foreach (string file in Directory.EnumerateFiles(UtilityFilesFolder, "*.backup"))
{
foreach (string file in Directory.EnumerateFiles(UtilityFilesFolder, "db-*.backup"))
{
var ThisFileTime = File.GetCreationTimeUtc(file);
if (ThisFileTime > LastBackup)
{
@@ -505,11 +505,11 @@ namespace AyaNova.Util
}
internal static void BackupAttachments(ILogger log = null)
internal static void BackupAttachments(string demandFileNamePrepend,ILogger log = null)
{
try
{
var AttachmentsBackupFile = $"at-{FileUtil.GetSafeDateFileName()}.zip";//presentation issue so don't use UTC for this one
var AttachmentsBackupFile = $"{demandFileNamePrepend}at-{FileUtil.GetSafeDateFileName()}.zip";//presentation issue so don't use UTC for this one
AttachmentsBackupFile = GetFullPathForUtilityFile(AttachmentsBackupFile);
System.IO.Compression.ZipFile.CreateFromDirectory(UserFilesFolder, AttachmentsBackupFile);

View File

@@ -13,7 +13,7 @@ namespace AyaNova.Util
{
internal static GlobalOpsBackupSettings Backup { get; set; }
// internal static DateTime LastBackup { get; set; }
internal static DateTime NextBackup { get; set; }
/// <summary>
@@ -28,8 +28,27 @@ namespace AyaNova.Util
Backup = new GlobalOpsBackupSettings();
ct.GlobalOpsBackupSettings.Add(Backup);
ct.SaveChanges();
}
Backup.LastBackup=FileUtil.MostRecentBackupFileDate();
}
Backup.LastBackup=FileUtil.MostRecentAutomatedBackupFileDate();
SetNextBackup();
}
internal static void SetNextBackup()
{
//If backup at 6pm and come here need to check if should add day
DateTime utcNow = DateTime.UtcNow;
//Has last backup run more than 24 hours ago?
if (NextBackup < utcNow.AddHours(-24))
{
//set it to today then
NextBackup = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, Backup.BackupTime.Hour, Backup.BackupTime.Minute, 0, DateTimeKind.Utc);
}
else
{
//less than 24 hours, set it to tomorrow
NextBackup = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day+1, Backup.BackupTime.Hour, Backup.BackupTime.Minute, 0, DateTimeKind.Utc);
}
}