This commit is contained in:
2020-05-22 13:56:08 +00:00
parent ef99cc404e
commit 0e1f3e0826
5 changed files with 29 additions and 7 deletions

View File

@@ -67,7 +67,7 @@ namespace AyaNova.Biz
//If backup time has changed then reset last backup as well as it might block from taking effect
if (putObject.BackupTime.Hour != dbObject.BackupTime.Hour && putObject.BackupTime.Minute != dbObject.BackupTime.Minute)
{
putObject.LastBackup = DateTime.MinValue;
ServerGlobalOpsSettingsCache.LastBackup = DateTime.MinValue;
}
CopyObject.Copy(putObject, dbObject, "Id");
ct.Entry(dbObject).OriginalValues["Concurrency"] = putObject.Concurrency;

View File

@@ -33,7 +33,7 @@ namespace AyaNova.Biz
//what time should we backup today?
DateTime todayBackupTime = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, ServerGlobalOpsSettingsCache.Backup.BackupTime.Hour, ServerGlobalOpsSettingsCache.Backup.BackupTime.Minute, 0, DateTimeKind.Utc);//first start with NOW
//Are we there yet?
//Are we there yet?
if (utcNow < todayBackupTime)
{
log.LogTrace("Not past backup time yet"); return;//nope
@@ -43,7 +43,7 @@ namespace AyaNova.Biz
//Has last backup run more than 24 hours ago?
if (ServerGlobalOpsSettingsCache.Backup.LastBackup > utcNow.AddHours(-24))
{
log.LogTrace("Hasn't been 24 hours since last backup yet"); return;//nope//nope, so we have already run today's backup
log.LogTrace("Hasn't been 24 hours since last backup yet"); return;//nope, so we have already run today's backup
}
//Ok, we're into backup time and it's been more than 24 hours since it last ran so let's do this...
}

View File

@@ -8,7 +8,7 @@ namespace AyaNova.Models
public uint Concurrency { get; set; }
public DateTime BackupTime { get; set; }
public DateTime LastBackup { get; set; }
public int BackupSetsToKeep { get; set; }
public bool BackupAttachments { get; set; }
@@ -16,7 +16,7 @@ namespace AyaNova.Models
{
Id = 1;//always 1
BackupTime = new DateTime(2020, 5, 19, 23, 59, 0, DateTimeKind.Local).ToUniversalTime();//date doesn't matter it only uses hour
LastBackup = DateTime.MinValue;
BackupSetsToKeep = 3;
}

View File

@@ -119,6 +119,27 @@ namespace AyaNova.Util
}
/// <summary>
/// Get date of newest backup file or minvalue if not found
///
/// </summary>
/// <returns></returns>
internal static DateTime MostRecentBackupFileDate()
{
DateTime LastBackup = DateTime.MinValue;
var BackupPath = UtilityFilesFolder;
foreach (string file in Directory.EnumerateFiles(UtilityFilesFolder, "*.backup"))
{
var ThisFileTime = File.GetCreationTimeUtc(Path.Combine(BackupPath, file));
if (ThisFileTime > LastBackup)
{
LastBackup = ThisFileTime;
}
}
return LastBackup;
}
/// <summary>
/// Confirm if a file exists in the utility folder
/// </summary>

View File

@@ -13,6 +13,7 @@ namespace AyaNova.Util
{
internal static GlobalOpsBackupSettings Backup { get; set; }
internal static DateTime LastBackup { get; set; }
/// <summary>
@@ -27,10 +28,10 @@ namespace AyaNova.Util
Backup = new GlobalOpsBackupSettings();
ct.GlobalOpsBackupSettings.Add(Backup);
ct.SaveChanges();
}
}
LastBackup=FileUtil.MostRecentBackupFileDate();
}
}//eoc
}//eons