This commit is contained in:
@@ -33,19 +33,19 @@ namespace AyaNova.Biz
|
||||
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
|
||||
// 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 < todayBackupTime)
|
||||
if (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
|
||||
}
|
||||
// //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;
|
||||
@@ -60,6 +60,9 @@ namespace AyaNova.Biz
|
||||
|
||||
log.LogDebug("Backup starting");
|
||||
|
||||
|
||||
var DemandFileNamePrepend=OnDemand?"manual-":string.Empty;
|
||||
|
||||
//*************
|
||||
//DO DATA BACKUP
|
||||
//build command
|
||||
@@ -70,7 +73,7 @@ namespace AyaNova.Biz
|
||||
Npgsql.NpgsqlConnectionStringBuilder PostgresConnectionString = new Npgsql.NpgsqlConnectionStringBuilder(ServerBootConfig.AYANOVA_DB_CONNECTION);
|
||||
var DBNameParameter = $"--dbname=postgresql://{PostgresConnectionString.Username}:{PostgresConnectionString.Password}@{PostgresConnectionString.Host}:{PostgresConnectionString.Port}/{PostgresConnectionString.Database}";
|
||||
|
||||
var DataBackupFile = $"db-{FileUtil.GetSafeDateFileName()}.backup";//presentation issue so don't use UTC for this one
|
||||
var DataBackupFile = $"{DemandFileNamePrepend}db-{FileUtil.GetSafeDateFileName()}.backup";//presentation issue so don't use UTC for this one
|
||||
DataBackupFile = FileUtil.GetFullPathForUtilityFile(DataBackupFile);
|
||||
|
||||
var BackupUtilityCommand = "pg_dump";
|
||||
@@ -96,7 +99,7 @@ namespace AyaNova.Biz
|
||||
if (ServerGlobalOpsSettingsCache.Backup.BackupAttachments)
|
||||
{
|
||||
await JobsBiz.LogJobAsync(Guid.Empty, $"Attachments backup starting", ct);
|
||||
FileUtil.BackupAttachments();
|
||||
FileUtil.BackupAttachments(DemandFileNamePrepend);
|
||||
|
||||
}
|
||||
|
||||
@@ -127,6 +130,9 @@ namespace AyaNova.Biz
|
||||
}
|
||||
finally
|
||||
{
|
||||
//bump the backup date if automatic backup
|
||||
if(!OnDemand)
|
||||
ServerGlobalOpsSettingsCache.SetNextBackup();
|
||||
apiServerState.ResumePriorState();
|
||||
BackupIsRunning = false;
|
||||
await JobsBiz.LogJobAsync(Guid.Empty, $"Backup - fully complete, server re-opened", ct);
|
||||
|
||||
Reference in New Issue
Block a user