{"record":{"id":"3db2af608a1746f3","repo":"coollabsio/coolify","slug":"server-not-found-3db2af","errorCode":null,"errorMessage":"Server not found?!","messagePattern":"Server not found\\?!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"app/Jobs/DatabaseBackupJob.php","lineNumber":115,"sourceCode":"            $databasesToBackup = null;\n\n            $this->team = Team::find($this->backup->team_id);\n            if (! $this->team) {\n                $this->backup->delete();\n\n                return;\n            }\n            if (data_get($this->backup, 'database_type') === ServiceDatabase::class) {\n                $this->database = data_get($this->backup, 'database');\n                $this->server = $this->database->service->server;\n                $this->s3 = $this->backup->s3;\n            } else {\n                $this->database = data_get($this->backup, 'database');\n                $this->server = $this->database->destination->server;\n                $this->s3 = $this->backup->s3;\n            }\n            if (is_null($this->server)) {\n                throw new \\Exception('Server not found?!');\n            }\n            if (is_null($this->database)) {\n                throw new \\Exception('Database not found?!');\n            }\n\n            $this->markStaleExecutionsAsFailed();\n\n            BackupCreated::dispatch($this->team->id);\n\n            $status = str(data_get($this->database, 'status'));\n            if (! $status->startsWith('running') && $this->database->id !== 0) {\n                Log::info('DatabaseBackupJob skipped: database not running', [\n                    'backup_id' => $this->backup->id,\n                    'database_id' => $this->database->id,\n                    'status' => (string) $status,\n                ]);\n\n                return;","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/coollabsio/coolify/blob/70b9acc42467278373e00de77abb40684e25b395/app/Jobs/DatabaseBackupJob.php#L97-L133","documentation":"DatabaseBackupJob resolves the target server through the database: for service databases via database->service->server, for standalone databases via database->destination->server. A null result means the relation chain broke — the destination or service's server was deleted while the ScheduledDatabaseBackup still exists and the job still runs. The job throws instead of silently skipping so the orphaned schedule is visible.","triggerScenarios":"A scheduled database backup fires (scheduler dispatches DatabaseBackupJob) after its standalone database's destination or its service's server record was deleted; the backup schedule outlived the resources it points at.","commonSituations":"Deleting a database/server without first deleting its scheduled backups; partial cleanups during project deletion; stale scheduled tasks re-enabled after server removal.","solutions":["Delete the ScheduledDatabaseBackup entries that reference the removed database/server.","Restore the missing relation (recreate the destination/server record) if the resources still exist.","If you manage schedules programmatically, delete schedules in the same transaction/unit as their database."],"exampleFix":"// before: schedule outlives its server, job throws 'Server not found?!'\n$schedule->delete(); // never called when the server was removed\n\n// after: remove dependent schedules when deleting the server/destination\nforeach ($database->scheduledBackups as $schedule) {\n    $schedule->delete();\n}\n$database->delete();","handlingStrategy":"validation","validationCode":"// Before dispatching or scheduling, verify the relation chain resolves\n$database = $backup->database;\n$server = $database?->database_type === \\App\\Models\\ServiceDatabase::class\n    ? $database?->service?->server\n    : $database?->destination?->server;\n\nif (is_null($server)) {\n    // orphaned schedule: delete it or alert, do not dispatch the job\n    $backup->delete();\n    return;\n}","typeGuard":"function backupTargetIsResolvable(\\App\\Models\\ScheduledDatabaseBackup $backup): bool\n{\n    $database = $backup->database;\n\n    return ! is_null($database) && ! is_null(\n        $database->database_type === \\App\\Models\\ServiceDatabase::class\n            ? $database->service?->server\n            : $database->destination?->server\n    );\n}","tryCatchPattern":null,"preventionTips":["Cascade-delete scheduled backups together with their database/server/destination.","Run a periodic audit: ScheduledDatabaseBackup rows whose database or server relation is null.","Fail the schedule visibly on first miss instead of letting it throw on every run."],"tags":["backup","database","orphaned-record","queue-job","scheduler"],"backgroundTag":"orphaned-relation","analyzedSha":"70b9acc42467278373e00de77abb40684e25b395","analyzedAt":"2026-08-17T01:41:01.313Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}