This commit is contained in:
5
.vscode/launch.json
vendored
5
.vscode/launch.json
vendored
@@ -58,10 +58,11 @@
|
|||||||
//"AYANOVA_TEMP_FILES_PATH": "c:\\temp\\RavenTestData\\tempfiles",
|
//"AYANOVA_TEMP_FILES_PATH": "c:\\temp\\RavenTestData\\tempfiles",
|
||||||
"AYANOVA_SERVER_TEST_MODE": "false",
|
"AYANOVA_SERVER_TEST_MODE": "false",
|
||||||
//"AYANOVA_LOG_PATH": "c:\\temp\\RavenTestData\\logs",
|
//"AYANOVA_LOG_PATH": "c:\\temp\\RavenTestData\\logs",
|
||||||
|
|
||||||
// "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small",
|
// "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small",
|
||||||
// "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-8",
|
// "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": {
|
"sourceFileMap": {
|
||||||
"/Views": "${workspaceFolder}/Views"
|
"/Views": "${workspaceFolder}/Views"
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
AyaNova.Api.ControllerHelpers.ApiServerState apiServerState = null;
|
AyaNova.Api.ControllerHelpers.ApiServerState apiServerState = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BackupIsRunning = true;
|
BackupIsRunning = true;
|
||||||
@@ -53,8 +53,8 @@ namespace AyaNova.Biz
|
|||||||
apiServerState.SetClosed("BACKUP RUNNING");
|
apiServerState.SetClosed("BACKUP RUNNING");
|
||||||
var jobstartmessage = $"LT:Backup LT:StartJob {(OnDemand ? "manual / on demand" : "scheduled") } ";
|
var jobstartmessage = $"LT:Backup LT:StartJob {(OnDemand ? "manual / on demand" : "scheduled") } ";
|
||||||
await JobsBiz.LogJobAsync(Guid.Empty, jobstartmessage);
|
await JobsBiz.LogJobAsync(Guid.Empty, jobstartmessage);
|
||||||
|
|
||||||
DateTime dtStartBackup=DateTime.Now;
|
DateTime dtStartBackup = DateTime.Now;
|
||||||
log.LogDebug("Backup starting");
|
log.LogDebug("Backup starting");
|
||||||
var DemandFileNamePrepend = OnDemand ? "manual-" : string.Empty;
|
var DemandFileNamePrepend = OnDemand ? "manual-" : string.Empty;
|
||||||
//*************
|
//*************
|
||||||
@@ -63,7 +63,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");
|
// await JobsBiz.LogJobAsync(Guid.Empty, $"Data backup starting");
|
||||||
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}";
|
||||||
|
|
||||||
@@ -71,53 +71,51 @@ namespace AyaNova.Biz
|
|||||||
DataBackupFile = FileUtil.GetFullPathForBackupFile(DataBackupFile);
|
DataBackupFile = FileUtil.GetFullPathForBackupFile(DataBackupFile);
|
||||||
|
|
||||||
var BackupUtilityCommand = "pg_dump";
|
var BackupUtilityCommand = "pg_dump";
|
||||||
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(ServerBootConfig.AYANOVA_BACKUP_PG_DUMP_PATH))
|
if (!string.IsNullOrWhiteSpace(ServerBootConfig.AYANOVA_BACKUP_PG_DUMP_PATH))
|
||||||
BackupUtilityCommand = Path.Combine(ServerBootConfig.AYANOVA_BACKUP_PG_DUMP_PATH, BackupUtilityCommand);
|
BackupUtilityCommand = Path.Combine(ServerBootConfig.AYANOVA_BACKUP_PG_DUMP_PATH, BackupUtilityCommand);
|
||||||
|
|
||||||
var Arguments = $"{DBNameParameter} -Fc > {DataBackupFile}";
|
var Arguments = $"{DBNameParameter} -Fc > {DataBackupFile}";
|
||||||
|
|
||||||
var Result = RunProgram.Run(BackupUtilityCommand, Arguments, log, MAXIMUM_MS_ALLOWED_FOR_PROCESSING);
|
var Result = RunProgram.Run(BackupUtilityCommand, Arguments, log, MAXIMUM_MS_ALLOWED_FOR_PROCESSING);
|
||||||
if (string.IsNullOrWhiteSpace(Result))
|
if (!string.IsNullOrWhiteSpace(Result))
|
||||||
{
|
|
||||||
var ms = "Backup of database completed OK";
|
|
||||||
log.LogDebug(ms);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
var msg = $"Error during data backup \"{Result}\"";
|
var msg = $"Error during data backup \"{Result}\"";
|
||||||
await JobsBiz.LogJobAsync(Guid.Empty, msg);
|
await JobsBiz.LogJobAsync(Guid.Empty, msg);
|
||||||
log.LogError($"BACKUP ERROR: {Result}");
|
log.LogError($"BACKUP ERROR: {Result}");
|
||||||
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, msg,"Backup");
|
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, msg, "Backup");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log.LogDebug("Backup of database completed OK");
|
||||||
|
|
||||||
//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, $"LT:Backup LT:Attachments");
|
await JobsBiz.LogJobAsync(Guid.Empty, $"LT:Backup LT:Attachments");
|
||||||
FileUtil.BackupAttachments(DemandFileNamePrepend);
|
FileUtil.BackupAttachments(DemandFileNamePrepend);
|
||||||
var ms = "Backup of file attachments completed OK";
|
log.LogDebug("Backup of file attachments completed OK");
|
||||||
log.LogDebug(ms);
|
}
|
||||||
|
|
||||||
|
//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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await JobsBiz.LogJobAsync(Guid.Empty, "LT:JobFailed");
|
await JobsBiz.LogJobAsync(Guid.Empty, "LT:JobFailed");
|
||||||
await JobsBiz.LogJobAsync(Guid.Empty, ExceptionUtil.ExtractAllExceptionMessages(ex));
|
await JobsBiz.LogJobAsync(Guid.Empty, ExceptionUtil.ExtractAllExceptionMessages(ex));
|
||||||
log.LogError(ex, "Backup failed");
|
log.LogError(ex, "Backup failed");
|
||||||
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, "Backup failed","Backup", ex);
|
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, "Backup failed", "Backup", ex);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -128,7 +126,7 @@ namespace AyaNova.Biz
|
|||||||
apiServerState.ResumePriorState();
|
apiServerState.ResumePriorState();
|
||||||
BackupIsRunning = false;
|
BackupIsRunning = false;
|
||||||
await JobsBiz.LogJobAsync(Guid.Empty, "LT:JobCompleted");
|
await JobsBiz.LogJobAsync(Guid.Empty, "LT:JobCompleted");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -52,6 +52,8 @@ namespace AyaNova.Util
|
|||||||
// var FullRunCommand=$"/C {BackupUtilityCommand} {Arguments}";
|
// var FullRunCommand=$"/C {BackupUtilityCommand} {Arguments}";
|
||||||
|
|
||||||
//for Windows need to pass to cmd.exe because often have command line piping etc
|
//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}";
|
var args = $"/C {cmd} {arguments}";
|
||||||
using (var process = new Process())
|
using (var process = new Process())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user