Backup working, completed for now
This commit is contained in:
@@ -25,28 +25,14 @@ namespace AyaNova.Biz
|
||||
public static async Task DoWorkAsync(AyContext ct, bool OnDemand = false)
|
||||
{
|
||||
if (BackupIsRunning) return;
|
||||
//testing FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
|
||||
//get NOW in utc
|
||||
DateTime utcNow = DateTime.UtcNow;
|
||||
if (!OnDemand)
|
||||
{
|
||||
log.LogTrace("Checking if backup should run");
|
||||
|
||||
//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("Checking if backup should run");
|
||||
if (DateTime.UtcNow < ServerGlobalOpsSettingsCache.NextBackup)
|
||||
{
|
||||
log.LogTrace("Not past backup time yet"); return;//nope
|
||||
}
|
||||
// //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...
|
||||
log.LogTrace("Not past backup time yet");
|
||||
return;
|
||||
}
|
||||
}
|
||||
AyaNova.Api.ControllerHelpers.ApiServerState apiServerState = null;
|
||||
try
|
||||
@@ -55,14 +41,9 @@ namespace AyaNova.Biz
|
||||
//LOCK DOWN SERVER
|
||||
apiServerState = (AyaNova.Api.ControllerHelpers.ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(AyaNova.Api.ControllerHelpers.ApiServerState));
|
||||
apiServerState.SetClosed("BACKUP RUNNING");
|
||||
|
||||
await JobsBiz.LogJobAsync(Guid.Empty, $"Starting backup job {(OnDemand ? "manual / on demand" : "scheduled") } ", ct);
|
||||
|
||||
log.LogDebug("Backup starting");
|
||||
|
||||
|
||||
var DemandFileNamePrepend=OnDemand?"manual-":string.Empty;
|
||||
|
||||
//*************
|
||||
//DO DATA BACKUP
|
||||
//build command
|
||||
@@ -94,24 +75,19 @@ namespace AyaNova.Biz
|
||||
log.LogError($"BACKUP ERROR: {Result}");
|
||||
}
|
||||
|
||||
|
||||
//DO FILE BACKUP IF ATTACHMENTS BACKED UP
|
||||
if (ServerGlobalOpsSettingsCache.Backup.BackupAttachments)
|
||||
{
|
||||
await JobsBiz.LogJobAsync(Guid.Empty, $"Attachments backup starting", ct);
|
||||
FileUtil.BackupAttachments(DemandFileNamePrepend);
|
||||
|
||||
}
|
||||
|
||||
//PRUNE DATA BACKUP SETS NOT KEPT
|
||||
await JobsBiz.LogJobAsync(Guid.Empty, $"Pruning old backup sets", ct);
|
||||
FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
|
||||
|
||||
|
||||
//v.next - COPY TO ONLINE STORAGE
|
||||
|
||||
//***************
|
||||
|
||||
//***************
|
||||
log.LogDebug("Backup completed");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -11,11 +11,8 @@ namespace AyaNova.Util
|
||||
/// </summary>
|
||||
internal static class ServerGlobalOpsSettingsCache
|
||||
{
|
||||
|
||||
internal static GlobalOpsBackupSettings Backup { get; set; }
|
||||
internal static DateTime NextBackup { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Populate and / or create the settings
|
||||
/// </summary>
|
||||
@@ -31,7 +28,6 @@ namespace AyaNova.Util
|
||||
}
|
||||
NextBackup = FileUtil.MostRecentAutomatedBackupFileDate();
|
||||
SetNextBackup();
|
||||
|
||||
}
|
||||
|
||||
internal static void SetNextBackup()
|
||||
@@ -53,6 +49,5 @@ namespace AyaNova.Util
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
Reference in New Issue
Block a user