Backup working, completed for now

This commit is contained in:
2020-05-23 18:09:09 +00:00
parent 4068c27663
commit 65479bd903
2 changed files with 6 additions and 35 deletions

View File

@@ -25,28 +25,14 @@ namespace AyaNova.Biz
public static async Task DoWorkAsync(AyContext ct, bool OnDemand = false) public static async Task DoWorkAsync(AyContext ct, bool OnDemand = false)
{ {
if (BackupIsRunning) return; if (BackupIsRunning) return;
//testing FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
//get NOW in utc
DateTime utcNow = DateTime.UtcNow;
if (!OnDemand) if (!OnDemand)
{ {
log.LogTrace("Checking if backup should run"); log.LogTrace("Checking if backup should run");
if (DateTime.UtcNow < ServerGlobalOpsSettingsCache.NextBackup)
//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?
if (utcNow < ServerGlobalOpsSettingsCache.NextBackup)
{ {
log.LogTrace("Not past backup time yet"); return;//nope log.LogTrace("Not past backup time yet");
} return;
// //Yes, we've passed into the backup window time, but that's also true if we just ran the backup as well so }
// //need to check for that as well...
// //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, 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...
} }
AyaNova.Api.ControllerHelpers.ApiServerState apiServerState = null; AyaNova.Api.ControllerHelpers.ApiServerState apiServerState = null;
try try
@@ -55,14 +41,9 @@ namespace AyaNova.Biz
//LOCK DOWN SERVER //LOCK DOWN SERVER
apiServerState = (AyaNova.Api.ControllerHelpers.ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(AyaNova.Api.ControllerHelpers.ApiServerState)); apiServerState = (AyaNova.Api.ControllerHelpers.ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(AyaNova.Api.ControllerHelpers.ApiServerState));
apiServerState.SetClosed("BACKUP RUNNING"); apiServerState.SetClosed("BACKUP RUNNING");
await JobsBiz.LogJobAsync(Guid.Empty, $"Starting backup job {(OnDemand ? "manual / on demand" : "scheduled") } ", ct); await JobsBiz.LogJobAsync(Guid.Empty, $"Starting backup job {(OnDemand ? "manual / on demand" : "scheduled") } ", ct);
log.LogDebug("Backup starting"); log.LogDebug("Backup starting");
var DemandFileNamePrepend=OnDemand?"manual-":string.Empty; var DemandFileNamePrepend=OnDemand?"manual-":string.Empty;
//************* //*************
//DO DATA BACKUP //DO DATA BACKUP
//build command //build command
@@ -94,24 +75,19 @@ namespace AyaNova.Biz
log.LogError($"BACKUP ERROR: {Result}"); log.LogError($"BACKUP ERROR: {Result}");
} }
//DO FILE BACKUP IF ATTACHMENTS BACKED UP //DO FILE BACKUP IF ATTACHMENTS BACKED UP
if (ServerGlobalOpsSettingsCache.Backup.BackupAttachments) if (ServerGlobalOpsSettingsCache.Backup.BackupAttachments)
{ {
await JobsBiz.LogJobAsync(Guid.Empty, $"Attachments backup starting", ct); await JobsBiz.LogJobAsync(Guid.Empty, $"Attachments backup starting", ct);
FileUtil.BackupAttachments(DemandFileNamePrepend); FileUtil.BackupAttachments(DemandFileNamePrepend);
} }
//PRUNE DATA BACKUP SETS NOT KEPT //PRUNE DATA BACKUP SETS NOT KEPT
await JobsBiz.LogJobAsync(Guid.Empty, $"Pruning old backup sets", ct); await JobsBiz.LogJobAsync(Guid.Empty, $"Pruning old backup sets", ct);
FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep); FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
//v.next - COPY TO ONLINE STORAGE //v.next - COPY TO ONLINE STORAGE
//***************
//***************
log.LogDebug("Backup completed"); log.LogDebug("Backup completed");
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -11,11 +11,8 @@ namespace AyaNova.Util
/// </summary> /// </summary>
internal static class ServerGlobalOpsSettingsCache internal static class ServerGlobalOpsSettingsCache
{ {
internal static GlobalOpsBackupSettings Backup { get; set; } internal static GlobalOpsBackupSettings Backup { get; set; }
internal static DateTime NextBackup { get; set; } internal static DateTime NextBackup { get; set; }
/// <summary> /// <summary>
/// Populate and / or create the settings /// Populate and / or create the settings
/// </summary> /// </summary>
@@ -31,7 +28,6 @@ namespace AyaNova.Util
} }
NextBackup = FileUtil.MostRecentAutomatedBackupFileDate(); NextBackup = FileUtil.MostRecentAutomatedBackupFileDate();
SetNextBackup(); SetNextBackup();
} }
internal static void SetNextBackup() internal static void SetNextBackup()
@@ -53,6 +49,5 @@ namespace AyaNova.Util
} }
} }
}//eoc }//eoc
}//eons }//eons