From 75340985969b371d73279622343a84adf856a92b Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Thu, 7 Nov 2024 15:06:16 -0500 Subject: [PATCH] fix(server): support non-default postgres port when taking a backup (#13992) --- server/src/services/backup.service.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/server/src/services/backup.service.ts b/server/src/services/backup.service.ts index 4be0e2787952c..d08e0d397bf1f 100644 --- a/server/src/services/backup.service.ts +++ b/server/src/services/backup.service.ts @@ -80,7 +80,22 @@ export class BackupService extends BaseService { } = this.configRepository.getEnv(); const isUrlConnection = config.connectionType === 'url'; - const databaseParams = isUrlConnection ? ['-d', config.url] : ['-U', config.username, '-h', config.host]; + + const databaseParams = isUrlConnection + ? ['--dbname', config.url] + : [ + '--username', + config.username, + '--host', + config.host, + '--port', + `${config.port}`, + '--database', + config.database, + ]; + + databaseParams.push('--clean', '--if-exists'); + const backupFilePath = path.join( StorageCore.getBaseFolder(StorageFolder.BACKUPS), `immich-db-backup-${Date.now()}.sql.gz.tmp`, @@ -88,8 +103,11 @@ export class BackupService extends BaseService { try { await new Promise((resolve, reject) => { - const pgdump = this.processRepository.spawn(`pg_dumpall`, [...databaseParams, '--clean', '--if-exists'], { - env: { PATH: process.env.PATH, PGPASSWORD: isUrlConnection ? undefined : config.password }, + const pgdump = this.processRepository.spawn(`pg_dumpall`, databaseParams, { + env: { + PATH: process.env.PATH, + PGPASSWORD: isUrlConnection ? undefined : config.password, + }, }); // NOTE: `--rsyncable` is only supported in GNU gzip