This commit is contained in:
2020-05-22 21:34:12 +00:00
parent 8c546b3779
commit 92b0892eb3
3 changed files with 21 additions and 5 deletions

2
.vscode/launch.json vendored
View File

@@ -50,7 +50,7 @@
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
"AYANOVA_METRICS_USE_INFLUXDB": "false",
"AYANOVA_SERVER_TEST_MODE":"true",
"AYANOVA_SERVER_TEST_MODE":"false",
"AYANOVA_SERVER_TEST_MODE_SEEDLEVEL":"small",
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET":"-7",
"AYANOVA_BACKUP_PG_DUMP_PATH":"C:\\data\\code\\PostgreSQLPortable_12.0\\App\\PgSQL\\bin\\"

View File

@@ -238,7 +238,7 @@ namespace AyaNova.Biz
/// Make a log entry for a job
/// (no context version)
/// </summary>
/// <param name="jobId"></param>
/// <param name="jobId">(NOTE: Guid.empty indicates internal job)</param>
/// <param name="statusText"></param>
internal static async Task<OpsJobLog> LogJobAsync(Guid jobId, string statusText)
{
@@ -248,7 +248,7 @@ namespace AyaNova.Biz
/// <summary>
/// Make a log entry for a job
/// </summary>
/// <param name="jobId"></param>
/// <param name="jobId">(NOTE: Guid.empty indicates internal job)</param>
/// <param name="statusText"></param>
/// <param name="ct"></param>
internal static async Task<OpsJobLog> LogJobAsync(Guid jobId, string statusText, AyContext ct)

View File

@@ -25,7 +25,7 @@ namespace AyaNova.Biz
public static async Task DoWorkAsync(AyContext ct, bool OnDemand = false)
{
if (BackupIsRunning) return;
//testing FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
//testing FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
//get NOW in utc
DateTime utcNow = DateTime.UtcNow;
if (!OnDemand)
@@ -56,6 +56,8 @@ namespace AyaNova.Biz
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");
//*************
@@ -64,7 +66,7 @@ namespace AyaNova.Biz
//this is valid on windows
//C:\data\code\PostgreSQLPortable_12.0\App\PgSQL\bin\pg_dump --dbname=postgresql://postgres:raven@127.0.0.1:5432/AyaNova -Fc > huge_new.backup
await JobsBiz.LogJobAsync(Guid.Empty, $"Data backup starting", ct);
Npgsql.NpgsqlConnectionStringBuilder PostgresConnectionString = new Npgsql.NpgsqlConnectionStringBuilder(ServerBootConfig.AYANOVA_DB_CONNECTION);
var DBNameParameter = $"--dbname=postgresql://{PostgresConnectionString.Username}:{PostgresConnectionString.Password}@{PostgresConnectionString.Host}:{PostgresConnectionString.Port}/{PostgresConnectionString.Database}";
@@ -79,16 +81,27 @@ namespace AyaNova.Biz
var Result = RunProgram.Run(BackupUtilityCommand, Arguments, log);
if (string.IsNullOrWhiteSpace(Result))
{
log.LogDebug("BACKUP SUCCESSFUL (NO ERROR)");
}
else
{
await JobsBiz.LogJobAsync(Guid.Empty, $"Error during data backup \"{Result}\"", ct);
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();
}
//PRUNE DATA BACKUP SETS NOT KEPT
await JobsBiz.LogJobAsync(Guid.Empty, $"Pruning old backup sets", ct);
FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
@@ -107,6 +120,8 @@ namespace AyaNova.Biz
}
catch (Exception ex)
{
await JobsBiz.LogJobAsync(Guid.Empty, "Backup failed with errors:", ct);
await JobsBiz.LogJobAsync(Guid.Empty, ExceptionUtil.ExtractAllExceptionMessages(ex), ct);
log.LogError(ex, "Backup failed");
throw ex;
}
@@ -114,6 +129,7 @@ namespace AyaNova.Biz
{
apiServerState.ResumePriorState();
BackupIsRunning = false;
await JobsBiz.LogJobAsync(Guid.Empty, $"Backup - fully complete, server re-opened", ct);
}
}