Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: backup of password protected postgresql database

Andras Bacsaieaefb3a6fb37
diff --git a/app/Jobs/DatabaseBackupJob.php b/app/Jobs/DatabaseBackupJob.php
index c8adf75ca7..10ed79622e 100644
--- a/app/Jobs/DatabaseBackupJob.php
+++ b/app/Jobs/DatabaseBackupJob.php
@@ -56,6 +56,8 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
public ?string $backup_output = null;
+ public ?string $postgres_password = null;
+
public ?S3Storage $s3 = null;
public function __construct($backup)
@@ -134,6 +136,13 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
} else {
$databasesToBackup = $this->database->postgres_user;
}
+ $this->postgres_password = $envs->filter(function ($env) {
+ return str($env)->startsWith('POSTGRES_PASSWORD=');
+ })->first();
+ if ($this->postgres_password) {
+ $this->postgres_password = str($this->postgres_password)->after('POSTGRES_PASSWORD=')->value();
+ }
+
} elseif (str($databaseType)->contains('mysql')) {
$this->container_name = "{$this->database->name}-$serviceUuid";
$this->directory_name = $serviceName.'-'.$this->container_name;
@@ -381,7 +390,13 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
{
try {
$commands[] = 'mkdir -p '.$this->backup_dir;
- $commands[] = "docker exec $this->container_name pg_dump --format=custom --no-acl --no-owner --username {$this->database->postgres_user} $database > $this->backup_location";
+ $backupCommand = "docker exec";
+ if ($this->postgres_password) {
+ $backupCommand .= " -e PGPASSWORD=$this->postgres_password";
+ }
+ $backupCommand .= " $this->container_name pg_dump --format=custom --no-acl --no-owner --username {$this->database->postgres_user} $database > $this->backup_location";
+
+ $commands[] = $backupCommand;
$this->backup_output = instant_remote_process($commands, $this->server);
$this->backup_output = trim($this->backup_output);
if ($this->backup_output === '') {