coolify icon indicating copy to clipboard operation
coolify copied to clipboard

[Enhancement]: Enable backup restore/import for ServiceDatabase (Docker Compose databases)

Open Illyism opened this issue 4 months ago • 4 comments

Request Type

New Feature

Description

Description

Databases created via Docker Compose deployments (ServiceDatabase) can create backups but cannot restore/import them through the UI. The import functionality only supports Standalone database types.

Current Behavior

Database Type Backup Restore/Import
StandalonePostgresql
StandaloneMysql
StandaloneMariadb
StandaloneMongodb
ServiceDatabase (from Docker Compose)

Expected Behavior

ServiceDatabase should support restore/import functionality, similar to Standalone databases.

Technical Details

File: app/Livewire/Project/Database/Import.php

The buildRestoreCommand() method (line 576-614) only handles Standalone database classes:

switch ($this->resource->getMorphClass()) {
    case \App\Models\StandaloneMariadb::class:
        // ...
    case \App\Models\StandaloneMysql::class:
        // ...
    case \App\Models\StandalonePostgresql::class:
        // ...
    case \App\Models\StandaloneMongodb::class:
        // ...
    default:
        $restoreCommand = ''; // ServiceDatabase falls here
}

Proposed Solution

Add support for ServiceDatabase in Import.php:

  1. In buildRestoreCommand(), add a case for ServiceDatabase:
case \App\Models\ServiceDatabase::class:
    $dbType = $this->resource->databaseType(); // Returns 'standalone-postgresql', etc.
    // Build restore command based on $dbType
    break;
  1. The ServiceDatabase->databaseType() method already returns the database type (e.g., standalone-postgresql, standalone-mysql), which can be used to determine the correct restore command.

  2. Update getContainers() to properly handle ServiceDatabase container naming:

// ServiceDatabase container name format: {service-name}-{service-uuid}
$this->container = $this->resource->name . '-' . $this->resource->service->uuid;

Related Code

  • app/Livewire/Project/Database/Import.php - Import/restore component
  • app/Models/ServiceDatabase.php - Has databaseType() method
  • app/Jobs/DatabaseBackupJob.php - Already supports ServiceDatabase for backups

Use Case

Users deploying databases via Docker Compose (e.g., postgres:17-alpine in a compose file) need the ability to restore backups through the Coolify UI, just like Standalone database deployments.

Illyism avatar Dec 07 '25 22:12 Illyism

💎 $25 bounty • Ilias Ism

Steps to solve:

  1. Start working: Comment /attempt #7529 with your implementation plan
  2. Submit work: Create a pull request including /claim #7529 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

❗ Important guidelines:

  • To claim a bounty, you need to provide a short demo video of your changes in your pull request
  • If anything is unclear, ask for clarification before starting as this will help avoid potential rework
  • Low quality AI PRs will not receive review and will be closed
  • Do not ask to be assigned unless you've contributed before

Thank you for contributing to coollabsio/coolify!

algora-pbc[bot] avatar Dec 07 '25 22:12 algora-pbc[bot]

/attempt #7529

Implementation Plan

I will add ServiceDatabase support to the backup restore/import functionality by:

  1. Modify app/Livewire/Project/Database/Import.php:

    • Update getContainers() method to handle ServiceDatabase container naming (name-service.uuid)
    • Add ServiceDatabase case in buildRestoreCommand() method
  2. Support all database types:

    • PostgreSQL (including PostGIS variants)
    • MySQL
    • MariaDB
    • MongoDB
  3. Implementation approach:

    • Use existing ServiceDatabase::databaseType() method to detect database type
    • Build restore commands consistent with DatabaseBackupJob.php backup logic
    • Support both regular and "dump all" restore modes

Timeline: Implementation complete and ready for review

gyanu2507 avatar Dec 08 '25 13:12 gyanu2507

I believe one of the main reasons why this hasn't been implemented yet, is the problem that deployments that could trigger at the same time as a running backup / import. This can interrupt the backup / import, and worst case corrupt your database. So it requires some logic to put a redeployment on queue, whenever a import or backup is running.

Cinzya avatar Dec 08 '25 18:12 Cinzya

/attempt #7529

Implementation Plan

Adding ServiceDatabase support to the backup restore/import functionality:

  1. Modified getContainers(): Handle ServiceDatabase container naming (name-service.uuid format)
  2. Modified buildRestoreCommand(): Added ServiceDatabase case using databaseType() to detect PostgreSQL, MySQL, MariaDB, MongoDB
  3. Modified updatedDumpAll(): Support dump-all mode for ServiceDatabase

PR: #7540

murataslan1 avatar Dec 09 '25 07:12 murataslan1