This commit is contained in:
2021-12-15 18:45:21 +00:00
parent db24ea4aa5
commit a23d575f31
2 changed files with 18 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ using Microsoft.Extensions.Logging;
using AyaNova.Models; using AyaNova.Models;
using AyaNova.Util; using AyaNova.Util;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
namespace AyaNova.Biz namespace AyaNova.Biz
{ {
@@ -71,11 +71,25 @@ 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);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
//put quotes around paths if spaces in them
if (BackupUtilityCommand.Contains(' '))
{
BackupUtilityCommand = $"\"{BackupUtilityCommand}\"";
}
if (DataBackupFile.Contains(' '))
{
DataBackupFile = $"\"{DataBackupFile}\"";
}
}
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);
@@ -87,14 +101,14 @@ namespace AyaNova.Biz
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, msg, "Backup"); await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, msg, "Backup");
} }
else else
{ {
log.LogDebug("Backup of database completed OK"); 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);
log.LogDebug("Backup of file attachments completed OK"); log.LogDebug("Backup of file attachments completed OK");
} }

View File

@@ -52,8 +52,6 @@ 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())
{ {