This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -50,7 +50,7 @@
|
|||||||
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",
|
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",
|
||||||
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
|
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
|
||||||
"AYANOVA_METRICS_USE_INFLUXDB": "false",
|
"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_SEEDLEVEL":"small",
|
||||||
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET":"-7",
|
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET":"-7",
|
||||||
"AYANOVA_BACKUP_PG_DUMP_PATH":"C:\\data\\code\\PostgreSQLPortable_12.0\\App\\PgSQL\\bin\\"
|
"AYANOVA_BACKUP_PG_DUMP_PATH":"C:\\data\\code\\PostgreSQLPortable_12.0\\App\\PgSQL\\bin\\"
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ namespace AyaNova.Biz
|
|||||||
/// Make a log entry for a job
|
/// Make a log entry for a job
|
||||||
/// (no context version)
|
/// (no context version)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jobId"></param>
|
/// <param name="jobId">(NOTE: Guid.empty indicates internal job)</param>
|
||||||
/// <param name="statusText"></param>
|
/// <param name="statusText"></param>
|
||||||
internal static async Task<OpsJobLog> LogJobAsync(Guid jobId, string statusText)
|
internal static async Task<OpsJobLog> LogJobAsync(Guid jobId, string statusText)
|
||||||
{
|
{
|
||||||
@@ -248,7 +248,7 @@ namespace AyaNova.Biz
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Make a log entry for a job
|
/// Make a log entry for a job
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jobId"></param>
|
/// <param name="jobId">(NOTE: Guid.empty indicates internal job)</param>
|
||||||
/// <param name="statusText"></param>
|
/// <param name="statusText"></param>
|
||||||
/// <param name="ct"></param>
|
/// <param name="ct"></param>
|
||||||
internal static async Task<OpsJobLog> LogJobAsync(Guid jobId, string statusText, AyContext ct)
|
internal static async Task<OpsJobLog> LogJobAsync(Guid jobId, string statusText, AyContext ct)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace AyaNova.Biz
|
|||||||
public static async Task DoWorkAsync(AyContext ct, bool OnDemand = false)
|
public static async Task DoWorkAsync(AyContext ct, bool OnDemand = false)
|
||||||
{
|
{
|
||||||
if (BackupIsRunning) return;
|
if (BackupIsRunning) return;
|
||||||
//testing FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
|
//testing FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
|
||||||
//get NOW in utc
|
//get NOW in utc
|
||||||
DateTime utcNow = DateTime.UtcNow;
|
DateTime utcNow = DateTime.UtcNow;
|
||||||
if (!OnDemand)
|
if (!OnDemand)
|
||||||
@@ -56,6 +56,8 @@ namespace AyaNova.Biz
|
|||||||
apiServerState = (AyaNova.Api.ControllerHelpers.ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(AyaNova.Api.ControllerHelpers.ApiServerState));
|
apiServerState = (AyaNova.Api.ControllerHelpers.ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(AyaNova.Api.ControllerHelpers.ApiServerState));
|
||||||
apiServerState.SetClosed("BACKUP RUNNING");
|
apiServerState.SetClosed("BACKUP RUNNING");
|
||||||
|
|
||||||
|
await JobsBiz.LogJobAsync(Guid.Empty, $"Starting backup job {(OnDemand ? "manual / on demand" : "scheduled") } ", ct);
|
||||||
|
|
||||||
log.LogDebug("Backup starting");
|
log.LogDebug("Backup starting");
|
||||||
|
|
||||||
//*************
|
//*************
|
||||||
@@ -64,7 +66,7 @@ namespace AyaNova.Biz
|
|||||||
//this is valid on windows
|
//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
|
//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);
|
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 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);
|
var Result = RunProgram.Run(BackupUtilityCommand, Arguments, log);
|
||||||
if (string.IsNullOrWhiteSpace(Result))
|
if (string.IsNullOrWhiteSpace(Result))
|
||||||
|
{
|
||||||
|
|
||||||
log.LogDebug("BACKUP SUCCESSFUL (NO ERROR)");
|
log.LogDebug("BACKUP SUCCESSFUL (NO ERROR)");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
await JobsBiz.LogJobAsync(Guid.Empty, $"Error during data backup \"{Result}\"", ct);
|
||||||
log.LogError($"BACKUP ERROR: {Result}");
|
log.LogError($"BACKUP ERROR: {Result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//DO FILE BACKUP IF ATTACHMENTS BACKED UP
|
//DO FILE BACKUP IF ATTACHMENTS BACKED UP
|
||||||
if (ServerGlobalOpsSettingsCache.Backup.BackupAttachments)
|
if (ServerGlobalOpsSettingsCache.Backup.BackupAttachments)
|
||||||
|
{
|
||||||
|
await JobsBiz.LogJobAsync(Guid.Empty, $"Attachments backup starting", ct);
|
||||||
FileUtil.BackupAttachments();
|
FileUtil.BackupAttachments();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//PRUNE DATA BACKUP SETS NOT KEPT
|
//PRUNE DATA BACKUP SETS NOT KEPT
|
||||||
|
await JobsBiz.LogJobAsync(Guid.Empty, $"Pruning old backup sets", ct);
|
||||||
FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
|
FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
|
||||||
|
|
||||||
|
|
||||||
@@ -107,6 +120,8 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
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");
|
log.LogError(ex, "Backup failed");
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
@@ -114,6 +129,7 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
apiServerState.ResumePriorState();
|
apiServerState.ResumePriorState();
|
||||||
BackupIsRunning = false;
|
BackupIsRunning = false;
|
||||||
|
await JobsBiz.LogJobAsync(Guid.Empty, $"Backup - fully complete, server re-opened", ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user