Skip to content

Commit

Permalink
fix(server): support non-default postgres port when taking a backup
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 committed Nov 7, 2024
1 parent e84ad08 commit 0c6eb95
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions server/src/services/backup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,34 @@ 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`,
);

try {
await new Promise<void>((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
Expand Down

0 comments on commit 0c6eb95

Please sign in to comment.