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: backups

Andras Bacsaibb6c9cf49e32
diff --git a/app/Jobs/DatabaseBackupJob.php b/app/Jobs/DatabaseBackupJob.php
index befeffed06..a09ebeadae 100644
--- a/app/Jobs/DatabaseBackupJob.php
+++ b/app/Jobs/DatabaseBackupJob.php
@@ -289,7 +289,7 @@ class DatabaseBackupJob implements ShouldQueue, ShouldBeEncrypted
if ($this->backup->save_s3) {
$this->upload_to_s3();
}
- $this->team?->notify(new BackupSuccess($this->backup, $this->database));
+ $this->team?->notify(new BackupSuccess($this->backup, $this->database, $database));
$this->backup_log->update([
'status' => 'success',
'message' => $this->backup_output,
@@ -305,8 +305,7 @@ class DatabaseBackupJob implements ShouldQueue, ShouldBeEncrypted
]);
}
send_internal_notification('DatabaseBackupJob failed with: ' . $e->getMessage());
- $this->team?->notify(new BackupFailed($this->backup, $this->database, $this->backup_output));
- throw $e;
+ $this->team?->notify(new BackupFailed($this->backup, $this->database, $this->backup_output, $database));
}
}
} catch (\Throwable $e) {
diff --git a/app/Jobs/SendMessageToTelegramJob.php b/app/Jobs/SendMessageToTelegramJob.php
index 4785da669a..4191b02feb 100644
--- a/app/Jobs/SendMessageToTelegramJob.php
+++ b/app/Jobs/SendMessageToTelegramJob.php
@@ -57,7 +57,7 @@ class SendMessageToTelegramJob implements ShouldQueue, ShouldBeEncrypted
}
}
$payload = [
- 'parse_mode' => 'markdown',
+ // 'parse_mode' => 'markdown',
'reply_markup' => json_encode([
'inline_keyboard' => [
[...$inlineButtons],
diff --git a/app/Livewire/Project/Database/Backup/Execution.php b/app/Livewire/Project/Database/Backup/Execution.php
index 1f790d6438..000b6fb2be 100644
--- a/app/Livewire/Project/Database/Backup/Execution.php
+++ b/app/Livewire/Project/Database/Backup/Execution.php
@@ -35,11 +35,6 @@ class Execution extends Component
$this->executions = $executions;
$this->s3s = currentTeam()->s3s;
}
- public function cleanupFailed()
- {
- $this->backup->executions()->where('status', 'failed')->delete();
- $this->dispatch('refreshBackupExecutions');
- }
public function render()
{
return view('livewire.project.database.backup.execution');
diff --git a/app/Livewire/Project/Database/BackupExecutions.php b/app/Livewire/Project/Database/BackupExecutions.php
index b127a685cf..a34d849f29 100644
--- a/app/Livewire/Project/Database/BackupExecutions.php
+++ b/app/Livewire/Project/Database/BackupExecutions.php
@@ -2,9 +2,7 @@
namespace App\Livewire\Project\Database;
-use Illuminate\Support\Facades\Storage;
use Livewire\Component;
-use Symfony\Component\HttpFoundation\StreamedResponse;
class BackupExecutions extends Component
{
@@ -16,11 +14,15 @@ class BackupExecutions extends Component
$userId = auth()->user()->id;
return [
"echo-private:team.{$userId},BackupCreated" => 'refreshBackupExecutions',
- "refreshBackupExecutions",
"deleteBackup"
];
}
+ public function cleanupFailed()
+ {
+ $this->backup->executions()->where('status', 'failed')->delete();
+ $this->refreshBackupExecutions();
+ }
public function deleteBackup($exeuctionId)
{
$execution = $this->backup->executions()->where('id', $exeuctionId)->first();
diff --git a/app/Models/StandaloneClickhouse.php b/app/Models/StandaloneClickhouse.php
index 3746a32f5c..2197d51df6 100644
--- a/app/Models/StandaloneClickhouse.php
+++ b/app/Models/StandaloneClickhouse.php
@@ -207,7 +207,4 @@ class StandaloneClickhouse extends BaseModel
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
- public function database_name() {
- return $this->clickhouse_db;
- }
}
diff --git a/app/Models/StandaloneDragonfly.php b/app/Models/StandaloneDragonfly.php
index adc1ea6ccf..7b18666b8c 100644
--- a/app/Models/StandaloneDragonfly.php
+++ b/app/Models/StandaloneDragonfly.php
@@ -207,7 +207,4 @@ class StandaloneDragonfly extends BaseModel
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
- public function database_name() {
- return '0';
- }
}
diff --git a/app/Models/StandaloneKeydb.php b/app/Models/StandaloneKeydb.php
index ff91322a0e..c2c1b98daa 100644
--- a/app/Models/StandaloneKeydb.php
+++ b/app/Models/StandaloneKeydb.php
@@ -208,7 +208,4 @@ class StandaloneKeydb extends BaseModel
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
- public function database_name() {
- return '0';
- }
}
diff --git a/app/Models/StandaloneMariadb.php b/app/Models/StandaloneMariadb.php
index 37d39f882e..5e18bbfde4 100644
--- a/app/Models/StandaloneMariadb.php
+++ b/app/Models/StandaloneMariadb.php
@@ -208,7 +208,4 @@ class StandaloneMariadb extends BaseModel
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
- public function database_name() {
- return $this->mariadb_database;
- }
}
diff --git a/app/Models/StandaloneMongodb.php b/app/Models/StandaloneMongodb.php
index 30414e26b8..8e4d327a38 100644
--- a/app/Models/StandaloneMongodb.php
+++ b/app/Models/StandaloneMongodb.php
@@ -223,7 +223,4 @@ class StandaloneMongodb extends BaseModel
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
- public function database_name() {
- return null;
- }
}
diff --git a/app/Models/StandaloneMysql.php b/app/Models/StandaloneMysql.php
index 53e9b6f226..eede451d77 100644
--- a/app/Models/StandaloneMysql.php
+++ b/app/Models/StandaloneMysql.php
@@ -209,7 +209,4 @@ class StandaloneMysql extends BaseModel
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
- public function database_name() {
- return $this->mysql_database;
- }
}
diff --git a/app/Models/StandalonePostgresql.php b/app/Models/StandalonePostgresql.php
index 6435c49de1..cf449a8155 100644
--- a/app/Models/StandalonePostgresql.php
+++ b/app/Models/StandalonePostgresql.php
@@ -208,7 +208,4 @@ class StandalonePostgresql extends BaseModel
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
- public function database_name() {
- return $this->postgres_db;
- }
}
diff --git a/app/Models/StandaloneRedis.php b/app/Models/StandaloneRedis.php
index de18c8c07d..da4701df90 100644
--- a/app/Models/StandaloneRedis.php
+++ b/app/Models/StandaloneRedis.php
@@ -204,7 +204,4 @@ class StandaloneRedis extends BaseModel
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
- public function database_name() {
- return '0';
- }
}
diff --git a/app/Notifications/Database/BackupFailed.php b/app/Notifications/Database/BackupFailed.php
index 67fd275894..7cad486b3f 100644
--- a/app/Notifications/Database/BackupFailed.php
+++ b/app/Notifications/Database/BackupFailed.php
@@ -15,21 +15,20 @@ class BackupFailed extends Notification implements ShouldQueue
{
use Queueable;
- public $tries = 1;
+ public $backoff = 10;
+ public $tries = 2;
public string $name;
- public ?string $database_name = null;
public string $frequency;
- public function __construct(ScheduledDatabaseBackup $backup, public $database, public $output)
+ public function __construct(ScheduledDatabaseBackup $backup, public $database, public $output, public $database_name)
{
$this->name = $database->name;
- $this->database_name = $database->database_name();
$this->frequency = $backup->frequency;
}
public function via(object $notifiable): array
{
- return [DiscordChannel::class, TelegramChannel::class, MailChannel::class];
+ return setNotificationChannels($notifiable, 'database_backups');
}
public function toMail(): MailMessage
@@ -47,11 +46,11 @@ class BackupFailed extends Notification implements ShouldQueue
public function toDiscord(): string
{
- return "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was FAILED.\n\nReason: {$this->output}";
+ return "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was FAILED.\n\nReason:\n{$this->output}";
}
public function toTelegram(): array
{
- $message = "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was FAILED.\n\nReason: {$this->output}";
+ $message = "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was FAILED.\n\nReason:\n{$this->output}";
return [
"message" => $message,
];
diff --git a/app/Notifications/Database/BackupSuccess.php b/app/Notifications/Database/BackupSuccess.php
index d69a31f462..c43a12276f 100644
--- a/app/Notifications/Database/BackupSuccess.php
+++ b/app/Notifications/Database/BackupSuccess.php
@@ -12,15 +12,14 @@ class BackupSuccess extends Notification implements ShouldQueue
{
use Queueable;
- public $tries = 1;
+ public $backoff = 10;
+ public $tries = 3;
public string $name;
- public ?string $database_name = null;
public string $frequency;
- public function __construct(ScheduledDatabaseBackup $backup, public $database)
+ public function __construct(ScheduledDatabaseBackup $backup, public $database, public $database_name)
{
$this->name = $database->name;
- $this->database_name = $database->database_name();
$this->frequency = $backup->frequency;
}
@@ -48,6 +47,7 @@ class BackupSuccess extends Notification implements ShouldQueue
public function toTelegram(): array
{
$message = "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was successful.";
+ ray($message);
return [
"message" => $message,
];
diff --git a/resources/views/livewire/project/database/backup-executions.blade.php b/resources/views/livewire/project/database/backup-executions.blade.php
index ae9428923f..34e2b965d9 100644
--- a/resources/views/livewire/project/database/backup-executions.blade.php
+++ b/resources/views/livewire/project/database/backup-executions.blade.php
@@ -1,43 +1,51 @@
-<div class="flex flex-col-reverse gap-2">
- @forelse($executions as $execution)
- <form wire:key="{{ data_get($execution, 'id') }}"
- class="relative flex flex-col p-4 bg-white box-without-bg dark:bg-coolgray-100" @class([
- 'border-green-500' => data_get($execution, 'status') === 'success',
- 'border-red-500' => data_get($execution, 'status') === 'failed',
- ])>
- @if (data_get($execution, 'status') === 'running')
- <div class="absolute top-2 right-2">
- <x-loading />
- </div>
- @endif
- <div>Database: {{ data_get($execution, 'database_name', 'N/A') }}</div>
- <div>Status: {{ data_get($execution, 'status') }}</div>
- <div>Started At: {{ data_get($execution, 'created_at') }}</div>
- @if (data_get($execution, 'message'))
- <div>Message: {{ data_get($execution, 'message') }}</div>
- @endif
- <div>Size: {{ data_get($execution, 'size') }} B / {{ round((int) data_get($execution, 'size') / 1024, 2) }}
- kB / {{ round((int) data_get($execution, 'size') / 1024 / 1024, 3) }} MB
- </div>
- <div>Location: {{ data_get($execution, 'filename', 'N/A') }}</div>
- <div class="flex gap-2">
- <div class="flex-1"></div>
- @if (data_get($execution, 'status') === 'success')
- <x-forms.button class=" dark:hover:bg-coolgray-400"
- x-on:click="download_file('{{ data_get($execution, 'id') }}')">Download</x-forms.button>
+<div>
+ <div class="flex items-center gap-2">
+ <h3 class="py-4">Executions</h3>
+ <x-forms.button wire:click='cleanupFailed'>Cleanup Failed Backups</x-forms.button>
+ </div>
+ <div class="flex flex-col-reverse gap-2">
+ @forelse($executions as $execution)
+ <form wire:key="{{ data_get($execution, 'id') }}"
+ class="relative flex flex-col p-4 bg-white box-without-bg dark:bg-coolgray-100"
+ @class([
+ 'border-green-500' => data_get($execution, 'status') === 'success',
+ 'border-red-500' => data_get($execution, 'status') === 'failed',
+ ])>
+ @if (data_get($execution, 'status') === 'running')
+ <div class="absolute top-2 right-2">
+ <x-loading />
+ </div>
+ @endif
+ <div>Database: {{ data_get($execution, 'database_name', 'N/A') }}</div>
+ <div>Status: {{ data_get($execution, 'status') }}</div>
+ <div>Started At: {{ data_get($execution, 'created_at') }}</div>
+ @if (data_get($execution, 'message'))
+ <div>Message: {{ data_get($execution, 'message') }}</div>
@endif
- <x-modal-confirmation isErrorButton action="deleteBackup({{ data_get($execution, 'id') }})">
- <x-slot:button-title>
- Delete
- </x-slot:button-title>
- This will delete this backup. It is not reversible.<br>Please think again.
- </x-modal-confirmation>
- </div>
- </form>
+ <div>Size: {{ data_get($execution, 'size') }} B /
+ {{ round((int) data_get($execution, 'size') / 1024, 2) }}
+ kB / {{ round((int) data_get($execution, 'size') / 1024 / 1024, 3) }} MB
+ </div>
+ <div>Location: {{ data_get($execution, 'filename', 'N/A') }}</div>
+ <div class="flex gap-2">
+ <div class="flex-1"></div>
+ @if (data_get($execution, 'status') === 'success')
+ <x-forms.button class=" dark:hover:bg-coolgray-400"
+ x-on:click="download_file('{{ data_get($execution, 'id') }}')">Download</x-forms.button>
+ @endif
+ <x-modal-confirmation isErrorButton action="deleteBackup({{ data_get($execution, 'id') }})">
+ <x-slot:button-title>
+ Delete
+ </x-slot:button-title>
+ This will delete this backup. It is not reversible.<br>Please think again.
+ </x-modal-confirmation>
+ </div>
+ </form>
- @empty
- <div>No executions found.</div>
- @endforelse
+ @empty
+ <div>No executions found.</div>
+ @endforelse
+ </div>
<script>
function download_file(executionId) {
window.open('/download/backup/' + executionId, '_blank');
diff --git a/resources/views/livewire/project/database/backup/execution.blade.php b/resources/views/livewire/project/database/backup/execution.blade.php
index 16a0ac4936..9056296fe9 100644
--- a/resources/views/livewire/project/database/backup/execution.blade.php
+++ b/resources/views/livewire/project/database/backup/execution.blade.php
@@ -4,10 +4,6 @@
<livewire:project.database.heading :database="$database" />
<div class="pt-6">
<livewire:project.database.backup-edit :backup="$backup" :s3s="$s3s" :status="data_get($database, 'status')" />
- <div class="flex items-center gap-2">
- <h3 class="py-4">Executions</h3>
- <x-forms.button wire:click='cleanupFailed'>Cleanup Failed Backups</x-forms.button>
- </div>
<livewire:project.database.backup-executions :backup="$backup" :executions="$executions" />
</div>
</div>
diff --git a/resources/views/livewire/project/database/scheduled-backups.blade.php b/resources/views/livewire/project/database/scheduled-backups.blade.php
index 8bdcae767b..0dce5fb9a9 100644
--- a/resources/views/livewire/project/database/scheduled-backups.blade.php
+++ b/resources/views/livewire/project/database/scheduled-backups.blade.php
@@ -2,21 +2,21 @@
<div class="flex flex-wrap gap-2">
@forelse($database->scheduledBackups as $backup)
@if ($type == 'database')
- <div class="box">
- <a class="flex flex-col"
- href="{{ route('project.database.backup.execution', [...$parameters, 'backup_uuid' => $backup->uuid]) }}">
+ <a class="box"
+ href="{{ route('project.database.backup.execution', [...$parameters, 'backup_uuid' => $backup->uuid]) }}">
+ <div class="flex flex-col">
<div>Frequency: {{ $backup->frequency }}</div>
<div>Last backup: {{ data_get($backup->latest_log, 'status', 'No backup yet') }}</div>
<div>Number of backups to keep (locally): {{ $backup->number_of_backups_locally }}</div>
- </a>
- </div>
+ </div>
+ </a>
@else
- <div class="box">
+ <div class="box" wire:click="setSelectedBackup('{{ data_get($backup, 'id') }}')">
<div @class([
'border-coollabs' =>
data_get($backup, 'id') === data_get($selectedBackup, 'id'),
'flex flex-col border-l-2 border-transparent',
- ]) wire:click="setSelectedBackup('{{ data_get($backup, 'id') }}')">
+ ])>
<div>Frequency: {{ $backup->frequency }}</div>
<div>Last backup: {{ data_get($backup->latest_log, 'status', 'No backup yet') }}</div>
<div>Number of backups to keep (locally): {{ $backup->number_of_backups_locally }}</div>