This commit is contained in:
2021-12-15 18:21:58 +00:00
parent bd14e3676c
commit db24ea4aa5
4 changed files with 36 additions and 35 deletions

5
.vscode/launch.json vendored
View File

@@ -58,10 +58,11 @@
//"AYANOVA_TEMP_FILES_PATH": "c:\\temp\\RavenTestData\\tempfiles",
"AYANOVA_SERVER_TEST_MODE": "false",
//"AYANOVA_LOG_PATH": "c:\\temp\\RavenTestData\\logs",
// "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small",
// "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-8",
"AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_14\\bin\\"
//"AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_14\\bin\\"
"AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\Program Files\\ayanova\\local-postgres\\bin"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"

View File

@@ -54,7 +54,7 @@ namespace AyaNova.Biz
var jobstartmessage = $"LT:Backup LT:StartJob {(OnDemand ? "manual / on demand" : "scheduled") } ";
await JobsBiz.LogJobAsync(Guid.Empty, jobstartmessage);
DateTime dtStartBackup=DateTime.Now;
DateTime dtStartBackup = DateTime.Now;
log.LogDebug("Backup starting");
var DemandFileNamePrepend = OnDemand ? "manual-" : string.Empty;
//*************
@@ -63,7 +63,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");
// await JobsBiz.LogJobAsync(Guid.Empty, $"Data backup starting");
Npgsql.NpgsqlConnectionStringBuilder PostgresConnectionString = new Npgsql.NpgsqlConnectionStringBuilder(ServerBootConfig.AYANOVA_DB_CONNECTION);
var DBNameParameter = $"--dbname=postgresql://{PostgresConnectionString.Username}:{PostgresConnectionString.Password}@{PostgresConnectionString.Host}:{PostgresConnectionString.Port}/{PostgresConnectionString.Database}";
@@ -71,53 +71,51 @@ namespace AyaNova.Biz
DataBackupFile = FileUtil.GetFullPathForBackupFile(DataBackupFile);
var BackupUtilityCommand = "pg_dump";
if (!string.IsNullOrWhiteSpace(ServerBootConfig.AYANOVA_BACKUP_PG_DUMP_PATH))
BackupUtilityCommand = Path.Combine(ServerBootConfig.AYANOVA_BACKUP_PG_DUMP_PATH, BackupUtilityCommand);
var Arguments = $"{DBNameParameter} -Fc > {DataBackupFile}";
var Result = RunProgram.Run(BackupUtilityCommand, Arguments, log, MAXIMUM_MS_ALLOWED_FOR_PROCESSING);
if (string.IsNullOrWhiteSpace(Result))
{
var ms = "Backup of database completed OK";
log.LogDebug(ms);
}
else
if (!string.IsNullOrWhiteSpace(Result))
{
var msg = $"Error during data backup \"{Result}\"";
await JobsBiz.LogJobAsync(Guid.Empty, msg);
log.LogError($"BACKUP ERROR: {Result}");
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, msg,"Backup");
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, msg, "Backup");
}
//DO FILE BACKUP IF ATTACHMENTS BACKED UP
if (ServerGlobalOpsSettingsCache.Backup.BackupAttachments)
else
{
await JobsBiz.LogJobAsync(Guid.Empty, $"LT:Backup LT:Attachments");
FileUtil.BackupAttachments(DemandFileNamePrepend);
var ms = "Backup of file attachments completed OK";
log.LogDebug(ms);
log.LogDebug("Backup of database completed OK");
//DO FILE BACKUP IF ATTACHMENTS BACKED UP
if (ServerGlobalOpsSettingsCache.Backup.BackupAttachments)
{
await JobsBiz.LogJobAsync(Guid.Empty, $"LT:Backup LT:Attachments");
FileUtil.BackupAttachments(DemandFileNamePrepend);
log.LogDebug("Backup of file attachments completed OK");
}
//PRUNE DATA BACKUP SETS NOT KEPT
await JobsBiz.LogJobAsync(Guid.Empty, $"LT:BackupDeleteOld");
FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
//v.next - COPY TO ONLINE STORAGE
//***************
log.LogDebug("Backup completed");
var duration = DateTime.Now - dtStartBackup;
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, $"Backup ({(OnDemand ? "manual / on demand" : "scheduled")}) completed successfully, duration (h:m:s.ms): {duration.ToString()}, server re-opened", "Backup");
}
//PRUNE DATA BACKUP SETS NOT KEPT
await JobsBiz.LogJobAsync(Guid.Empty, $"LT:BackupDeleteOld");
FileUtil.DatabaseBackupCleanUp(ServerGlobalOpsSettingsCache.Backup.BackupSetsToKeep);
//v.next - COPY TO ONLINE STORAGE
//***************
log.LogDebug("Backup completed");
var duration=DateTime.Now - dtStartBackup;
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, $"Backup ({(OnDemand ? "manual / on demand" : "scheduled")}) completed successfully, duration (h:m:s.ms): {duration.ToString()}, server re-opened","Backup");
}
catch (Exception ex)
{
await JobsBiz.LogJobAsync(Guid.Empty, "LT:JobFailed");
await JobsBiz.LogJobAsync(Guid.Empty, ExceptionUtil.ExtractAllExceptionMessages(ex));
log.LogError(ex, "Backup failed");
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, "Backup failed","Backup", ex);
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, "Backup failed", "Backup", ex);
throw;
}
finally

View File

@@ -52,6 +52,8 @@ namespace AyaNova.Util
// var FullRunCommand=$"/C {BackupUtilityCommand} {Arguments}";
//for Windows need to pass to cmd.exe because often have command line piping etc
//todo: make this work when there are spaces with quotes etc
var args = $"/C {cmd} {arguments}";
using (var process = new Process())
{