fix: backups
This commit is contained in:
parent
ae12222687
commit
bb6c9cf49e
@ -289,7 +289,7 @@ public function handle(): void
|
||||
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 @@ public function handle(): void
|
||||
]);
|
||||
}
|
||||
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) {
|
||||
|
@ -57,7 +57,7 @@ public function handle(): void
|
||||
}
|
||||
}
|
||||
$payload = [
|
||||
'parse_mode' => 'markdown',
|
||||
// 'parse_mode' => 'markdown',
|
||||
'reply_markup' => json_encode([
|
||||
'inline_keyboard' => [
|
||||
[...$inlineButtons],
|
||||
|
@ -35,11 +35,6 @@ public function mount()
|
||||
$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');
|
||||
|
@ -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 @@ public function getListeners()
|
||||
$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();
|
||||
|
@ -207,7 +207,4 @@ public function scheduledBackups()
|
||||
{
|
||||
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
|
||||
}
|
||||
public function database_name() {
|
||||
return $this->clickhouse_db;
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +207,4 @@ public function scheduledBackups()
|
||||
{
|
||||
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
|
||||
}
|
||||
public function database_name() {
|
||||
return '0';
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,4 @@ public function scheduledBackups()
|
||||
{
|
||||
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
|
||||
}
|
||||
public function database_name() {
|
||||
return '0';
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,4 @@ public function scheduledBackups()
|
||||
{
|
||||
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
|
||||
}
|
||||
public function database_name() {
|
||||
return $this->mariadb_database;
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +223,4 @@ public function scheduledBackups()
|
||||
{
|
||||
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
|
||||
}
|
||||
public function database_name() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +209,4 @@ public function scheduledBackups()
|
||||
{
|
||||
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
|
||||
}
|
||||
public function database_name() {
|
||||
return $this->mysql_database;
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,4 @@ public function scheduledBackups()
|
||||
{
|
||||
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
|
||||
}
|
||||
public function database_name() {
|
||||
return $this->postgres_db;
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +204,4 @@ public function scheduledBackups()
|
||||
{
|
||||
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
|
||||
}
|
||||
public function database_name() {
|
||||
return '0';
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ public function toMail(): MailMessage
|
||||
|
||||
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,
|
||||
];
|
||||
|
@ -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 @@ public function toDiscord(): string
|
||||
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,
|
||||
];
|
||||
|
@ -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
|
||||
<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>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>
|
||||
@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');
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user