fix(backups): back up the instance database on localhost and show why the pre-update backup failed

The pre-update backup now skips a disabled schedule.
This commit is contained in:
Andras Bacsai
2026-11-04 06:34:44 +01:00
parent d09480973e
commit 860e786481
3 changed files with 8 additions and 4 deletions
+3 -2
View File
@@ -135,7 +135,7 @@ class UpdateCoolify
private function backupDatabase(): void
{
$backup = StandalonePostgresql::find(0)?->scheduledBackups()->first();
if (! $backup || ! instanceSettings()->is_backup_before_update_enabled) {
if (! $backup?->enabled || ! instanceSettings()->is_backup_before_update_enabled) {
return;
}
@@ -144,7 +144,8 @@ class UpdateCoolify
$job = new DatabaseBackupJob($backup);
$job->handle();
if ($job->backup_log?->status !== 'success') {
throw new \Exception('The database backup failed, so the update was not started.');
$reason = $job->backup_log?->message;
throw new \Exception('The database backup failed, so the update was not started.'.($reason ? " Error: {$reason}" : '').' You can turn off "Backup before update" in Settings > Backup to update without a backup.');
}
}
+4 -1
View File
@@ -140,7 +140,10 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
$this->server = $this->database->service->server;
} else {
$this->database = data_get($this->backup, 'database');
$this->server = $this->database->destination->server;
// The coolify-db container always runs on the Coolify host, whatever its destination row says.
$this->server = $this->database instanceof StandalonePostgresql && $this->database->isInstanceDatabase()
? Server::find(0)
: $this->database->destination->server;
}
if (is_null($this->server)) {
throw new \Exception('Server not found?!');