Backup
This commit is contained in:
@@ -141,7 +141,7 @@ namespace AyaNova.Biz
|
|||||||
/// <param name="ct"></param>
|
/// <param name="ct"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
internal static async Task<OpsJob> AddJobAsync(OpsJob newJob, AyContext ct)
|
internal static async Task<OpsJob> AddJobAsync(OpsJob newJob, AyContext ct)
|
||||||
{
|
{
|
||||||
await ct.OpsJob.AddAsync(newJob);
|
await ct.OpsJob.AddAsync(newJob);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
return newJob;
|
return newJob;
|
||||||
@@ -372,6 +372,9 @@ namespace AyaNova.Biz
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//backup
|
||||||
|
await CoreJobBackup.DoWorkAsync(ct);
|
||||||
|
|
||||||
|
|
||||||
//Notifications
|
//Notifications
|
||||||
}
|
}
|
||||||
@@ -396,7 +399,7 @@ namespace AyaNova.Biz
|
|||||||
internal static async Task ProcessJobAsync(OpsJob job, AyContext ct)
|
internal static async Task ProcessJobAsync(OpsJob job, AyContext ct)
|
||||||
{
|
{
|
||||||
var JobDescription = $"{job.Name} {job.JobType.ToString()}";
|
var JobDescription = $"{job.Name} {job.JobType.ToString()}";
|
||||||
if (job.SubType!=JobSubType.NotSet)
|
if (job.SubType != JobSubType.NotSet)
|
||||||
JobDescription += $":{job.SubType}";
|
JobDescription += $":{job.SubType}";
|
||||||
|
|
||||||
log.LogDebug($"ProcessJobAsync -> Processing job {JobDescription}");
|
log.LogDebug($"ProcessJobAsync -> Processing job {JobDescription}");
|
||||||
|
|||||||
@@ -24,37 +24,50 @@ namespace AyaNova.Biz
|
|||||||
//
|
//
|
||||||
public static async Task DoWorkAsync(AyContext ct)
|
public static async Task DoWorkAsync(AyContext ct)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (BackupIsRunning) return;
|
if (BackupIsRunning) return;
|
||||||
|
|
||||||
//get NOW in utc
|
//get NOW in utc
|
||||||
DateTime utcNow = DateTime.UtcNow;
|
DateTime utcNow = DateTime.UtcNow;
|
||||||
|
|
||||||
//what time should we backup today?
|
//what time should we backup today?
|
||||||
DateTime todayBackupTime = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, ServerGlobalOpsSettings.BackupTime.Hour, ServerGlobalOpsSettings.BackupTime.Minute, 0, DateTimeKind.Utc);//first start with NOW
|
DateTime todayBackupTime = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, ServerGlobalOpsSettings.BackupTime.Hour, ServerGlobalOpsSettings.BackupTime.Minute, 0, DateTimeKind.Utc);//first start with NOW
|
||||||
|
|
||||||
//Are we there yet?
|
//Are we there yet?
|
||||||
if (utcNow < todayBackupTime) return;//nope
|
if (utcNow < todayBackupTime) 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
|
//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...
|
//need to check for that as well...
|
||||||
|
|
||||||
//Has last backup run more than 24 hours ago?
|
//Has last backup run more than 24 hours ago?
|
||||||
if (ServerGlobalOpsSettings.LastBackup > utcNow.AddHours(-24))
|
if (ServerGlobalOpsSettings.LastBackup > utcNow.AddHours(-24))
|
||||||
return;//nope, so we have already run today's backup
|
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...
|
//Ok, we're into backup time and it's been more than 24 hours since it last ran so let's do this...
|
||||||
BackupIsRunning = true;
|
try
|
||||||
log.LogTrace("Backup starting");
|
{
|
||||||
|
BackupIsRunning = true;
|
||||||
|
log.LogTrace("Backup starting");
|
||||||
|
|
||||||
//*************
|
//*************
|
||||||
|
|
||||||
|
log.LogInformation("SIMULATED BACKUP RUNNING NOW - TORA TORA TORA!");
|
||||||
|
|
||||||
|
//***************
|
||||||
|
|
||||||
//BACKUP TORA TORA TORA!
|
//Update last backup
|
||||||
//***************
|
var biz = GlobalOpsSettingsBiz.GetBiz(ct);
|
||||||
|
var OpSet = await biz.GetAsync(false);
|
||||||
|
OpSet.LastBackup = utcNow;
|
||||||
|
await biz.ReplaceAsync(OpSet);
|
||||||
|
|
||||||
//Update last backup
|
log.LogTrace("Backup completed");
|
||||||
BackupIsRunning = false;
|
}
|
||||||
log.LogTrace("Backup completed");
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
log.LogError(ex, "BACKUP FAILED!");
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
BackupIsRunning = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ namespace AyaNova.Models
|
|||||||
public GlobalOpsSettings()
|
public GlobalOpsSettings()
|
||||||
{
|
{
|
||||||
Id = 1;//always 1
|
Id = 1;//always 1
|
||||||
BackupTime = new DateTime(2020, 5, 19, 23, 59, 0, DateTimeKind.Utc);//date doesn't matter it only uses hour
|
// BackupTime = new DateTime(2020, 5, 19, 23, 59, 0, DateTimeKind.Utc);//date doesn't matter it only uses hour
|
||||||
|
//testing only, above is the correct one
|
||||||
|
BackupTime = DateTime.UtcNow.AddMinutes(1);
|
||||||
LastBackup = DateTime.MinValue;
|
LastBackup = DateTime.MinValue;
|
||||||
BackupSetsToKeep = 3;
|
BackupSetsToKeep = 3;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user