mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
fix(backups): let service databases choose the databases to back up
Closes #12432 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
33a6682791
commit
dbd211486b
@@ -169,6 +169,7 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
|
||||
// The container name is validated above, so it is a safe folder name. Keep the folder of earlier releases.
|
||||
$this->directory_name = $serviceName.'-'.$this->container_name;
|
||||
$escapedContainerName = escapeshellarg($this->container_name);
|
||||
$configuredDatabases = $this->configuredDatabasesToBackup();
|
||||
if (str($databaseType)->contains('postgres')) {
|
||||
$commands[] = "docker exec {$escapedContainerName} env | grep -E '^(POSTGRES|PGUSER=)'";
|
||||
$envs = instant_remote_process($commands, $this->server, true, false, null, disableMultiplexing: true);
|
||||
@@ -180,7 +181,9 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
|
||||
return str($env)->startsWith('POSTGRES_DB=');
|
||||
})->first();
|
||||
|
||||
if ($db) {
|
||||
if (filled($configuredDatabases)) {
|
||||
$databasesToBackup = $configuredDatabases;
|
||||
} elseif ($db) {
|
||||
$databasesToBackup = str($db)->after('POSTGRES_DB=')->value();
|
||||
} else {
|
||||
$databasesToBackup = $this->database->postgres_user;
|
||||
@@ -207,15 +210,14 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
|
||||
return str($env)->startsWith('MYSQL_DATABASE=');
|
||||
})->first();
|
||||
|
||||
if ($db) {
|
||||
if (filled($configuredDatabases)) {
|
||||
$databasesToBackup = $configuredDatabases;
|
||||
} elseif ($db) {
|
||||
$databasesToBackup = str($db)->after('MYSQL_DATABASE=')->value();
|
||||
} else {
|
||||
$databasesToBackup = $this->configuredDatabasesToBackup();
|
||||
if (blank($databasesToBackup)) {
|
||||
$this->recordUndeterminedDatabases('MYSQL_DATABASE');
|
||||
$this->recordUndeterminedDatabases('MYSQL_DATABASE');
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
} elseif (str($databaseType)->contains('mariadb')) {
|
||||
$commands[] = "docker exec {$escapedContainerName} env";
|
||||
@@ -235,27 +237,17 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
|
||||
}
|
||||
}
|
||||
|
||||
$db = $envs->filter(function ($env) {
|
||||
return str($env)->startsWith('MARIADB_DATABASE=');
|
||||
})->first();
|
||||
$db = $envs->first(fn ($env) => str($env)->startsWith('MARIADB_DATABASE='))
|
||||
?? $envs->first(fn ($env) => str($env)->startsWith('MYSQL_DATABASE='));
|
||||
|
||||
if ($db) {
|
||||
$databasesToBackup = str($db)->after('MARIADB_DATABASE=')->value();
|
||||
if (filled($configuredDatabases)) {
|
||||
$databasesToBackup = $configuredDatabases;
|
||||
} elseif ($db) {
|
||||
$databasesToBackup = str($db)->after('=')->value();
|
||||
} else {
|
||||
$db = $envs->filter(function ($env) {
|
||||
return str($env)->startsWith('MYSQL_DATABASE=');
|
||||
})->first();
|
||||
$this->recordUndeterminedDatabases('MARIADB_DATABASE or MYSQL_DATABASE');
|
||||
|
||||
if ($db) {
|
||||
$databasesToBackup = str($db)->after('MYSQL_DATABASE=')->value();
|
||||
} else {
|
||||
$databasesToBackup = $this->configuredDatabasesToBackup();
|
||||
if (blank($databasesToBackup)) {
|
||||
$this->recordUndeterminedDatabases('MARIADB_DATABASE or MYSQL_DATABASE');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
} elseif (str($databaseType)->contains('mongo')) {
|
||||
$databasesToBackup = ['*'];
|
||||
@@ -1104,7 +1096,8 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
|
||||
}
|
||||
|
||||
/**
|
||||
* Databases picked on the backup, for service databases whose container does not name one.
|
||||
* Databases picked in the backup settings of a service database. They take priority over the
|
||||
* database that the container env names, as for standalone databases.
|
||||
*
|
||||
* @return string|array<int, string>|null
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user