This commit is contained in:
2020-07-21 19:32:50 +00:00
parent f94a4f4223
commit 336046b1d7
8 changed files with 39 additions and 32 deletions

View File

@@ -43,13 +43,17 @@ namespace AyaNova.Biz
}
}
AyaNova.Api.ControllerHelpers.ApiServerState apiServerState = null;
string BackupStatusNotification = string.Empty;
try
{
BackupIsRunning = true;
//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") } ");
var jobstartmessage = $"Starting backup job {(OnDemand ? "manual / on demand" : "scheduled") } ";
await JobsBiz.LogJobAsync(Guid.Empty, jobstartmessage);
BackupStatusNotification = jobstartmessage + "\n";
log.LogDebug("Backup starting");
var DemandFileNamePrepend = OnDemand ? "manual-" : string.Empty;
//*************
@@ -74,13 +78,16 @@ namespace AyaNova.Biz
var Result = RunProgram.Run(BackupUtilityCommand, Arguments, log, MAXIMUM_MS_ALLOWED_FOR_PROCESSING);
if (string.IsNullOrWhiteSpace(Result))
{
log.LogDebug("BACKUP SUCCESSFUL (NO ERROR)");
var ms = "Backup of database completed OK";
log.LogDebug(ms);
BackupStatusNotification += (ms + "\n");
}
else
{
await JobsBiz.LogJobAsync(Guid.Empty, $"Error during data backup \"{Result}\"");
var msg = $"Error during data backup \"{Result}\"";
await JobsBiz.LogJobAsync(Guid.Empty, msg);
log.LogError($"BACKUP ERROR: {Result}");
//TODO: notify OPSNOTIFY
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, msg);
}
//DO FILE BACKUP IF ATTACHMENTS BACKED UP
@@ -88,6 +95,10 @@ namespace AyaNova.Biz
{
await JobsBiz.LogJobAsync(Guid.Empty, $"Attachments backup starting");
FileUtil.BackupAttachments(DemandFileNamePrepend);
var ms = "Backup of file attachments completed OK";
log.LogDebug(ms);
BackupStatusNotification += (ms + "\n");
}
//PRUNE DATA BACKUP SETS NOT KEPT
@@ -95,7 +106,8 @@ namespace AyaNova.Biz
FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
//v.next - COPY TO ONLINE STORAGE
//***************
//***************
log.LogDebug("Backup completed");
}
catch (Exception ex)
@@ -103,7 +115,7 @@ namespace AyaNova.Biz
await JobsBiz.LogJobAsync(Guid.Empty, "Backup failed with errors:");
await JobsBiz.LogJobAsync(Guid.Empty, ExceptionUtil.ExtractAllExceptionMessages(ex));
log.LogError(ex, "Backup failed");
//TODO: notify OPSNOTIFY
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, "Backup failed", ex);
throw ex;
}
finally
@@ -114,6 +126,7 @@ namespace AyaNova.Biz
apiServerState.ResumePriorState();
BackupIsRunning = false;
await JobsBiz.LogJobAsync(Guid.Empty, $"Backup - fully complete, server re-opened");
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, $"Backup completed server re-opened\nStatus:{BackupStatusNotification}");
}
}

View File

@@ -3,16 +3,6 @@ using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using AyaNova.Models;
using System;
using System.Linq;
using System.Globalization;
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using AyaNova.Util;
using AyaNova.Models;
namespace AyaNova.Biz
{