Edit & Download (local) Backups (#436)

* Allow editing of backups

* pint updates

* setup of backup download

* allow download for local backup files

* delete uploaded files on delete of BackupFile

* pint updates

* S3 upload & download fixes

* Deletion of backup files

* support $ARCH selector for s3 installation

* delete files when deleting backup

* fixed ui issue

* adjustment

* Use system temp path for downloads

---------

Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
This commit is contained in:
Richard Anderson
2025-01-25 20:59:35 +00:00
committed by GitHub
parent 465951fd1e
commit a73476c1dd
31 changed files with 382 additions and 184 deletions

View File

@ -2,7 +2,7 @@
namespace App\Web\Pages\Servers\Databases;
use App\Actions\Database\CreateBackup;
use App\Actions\Database\ManageBackup;
use App\Models\Backup;
use App\Models\StorageProvider;
use App\Web\Contracts\HasSecondSubNav;
@ -38,12 +38,12 @@ protected function getHeaderActions(): array
Select::make('database')
->label('Database')
->options($this->server->databases()->pluck('name', 'id')->toArray())
->rules(fn (callable $get) => CreateBackup::rules($this->server, $get())['database'])
->rules(fn (callable $get) => ManageBackup::rules($this->server, $get())['database'])
->searchable(),
Select::make('storage')
->label('Storage')
->options(StorageProvider::getByProjectId($this->server->project_id)->pluck('profile', 'id')->toArray())
->rules(fn (callable $get) => CreateBackup::rules($this->server, $get())['storage'])
->rules(fn (callable $get) => ManageBackup::rules($this->server, $get())['storage'])
->suffixAction(
\Filament\Forms\Components\Actions\Action::make('connect')
->form(Create::form())
@ -59,21 +59,21 @@ protected function getHeaderActions(): array
->label('Interval')
->options(config('core.cronjob_intervals'))
->reactive()
->rules(fn (callable $get) => CreateBackup::rules($this->server, $get())['interval']),
->rules(fn (callable $get) => ManageBackup::rules($this->server, $get())['interval']),
TextInput::make('custom_interval')
->label('Custom Interval (Cron)')
->rules(fn (callable $get) => CreateBackup::rules($this->server, $get())['custom_interval'])
->rules(fn (callable $get) => ManageBackup::rules($this->server, $get())['custom_interval'])
->visible(fn (callable $get) => $get('interval') === 'custom')
->placeholder('0 * * * *'),
TextInput::make('keep')
->label('Backups to Keep')
->rules(fn (callable $get) => CreateBackup::rules($this->server, $get())['keep'])
->rules(fn (callable $get) => ManageBackup::rules($this->server, $get())['keep'])
->helperText('How many backups to keep before deleting the oldest one'),
])
->modalSubmitActionLabel('Create')
->action(function (array $data) {
run_action($this, function () use ($data) {
app(CreateBackup::class)->create($this->server, $data);
app(ManageBackup::class)->create($this->server, $data);
$this->dispatch('$refresh');

View File

@ -2,6 +2,7 @@
namespace App\Web\Pages\Servers\Databases\Widgets;
use App\Actions\Database\ManageBackupFile;
use App\Actions\Database\RestoreBackup;
use App\Models\Backup;
use App\Models\BackupFile;
@ -59,11 +60,21 @@ public function table(Table $table): Table
->query($this->getTableQuery())
->columns($this->getTableColumns())
->actions([
Action::make('download')
->hiddenLabel()
->icon('heroicon-o-arrow-down-tray')
->visible(fn (BackupFile $record) => $record->isAvailable() && $record->isLocal())
->tooltip('Download')
->action(function (BackupFile $record) {
return app(ManageBackupFile::class)->download($record);
})
->authorize(fn (BackupFile $record) => auth()->user()->can('view', $record)),
Action::make('restore')
->hiddenLabel()
->icon('heroicon-o-arrow-path')
->modalHeading('Restore Backup')
->tooltip('Restore Backup')
->disabled(fn (BackupFile $record) => ! $record->isAvailable())
->authorize(fn (BackupFile $record) => auth()->user()->can('update', $record->backup))
->form([
Select::make('database')
@ -95,16 +106,15 @@ public function table(Table $table): Table
Action::make('delete')
->hiddenLabel()
->icon('heroicon-o-trash')
->modalHeading('Delete Database')
->modalHeading('Delete Backup File')
->color('danger')
->disabled(fn (BackupFile $record) => ! $record->isAvailable())
->tooltip('Delete')
->authorize(fn (BackupFile $record) => auth()->user()->can('delete', $record))
->requiresConfirmation()
->action(function (BackupFile $record) {
run_action($this, function () use ($record) {
$record->delete();
$this->dispatch('$refresh');
});
app(ManageBackupFile::class)->delete($record);
$this->dispatch('$refresh');
}),
]);
}

View File

@ -2,10 +2,14 @@
namespace App\Web\Pages\Servers\Databases\Widgets;
use App\Actions\Database\ManageBackup;
use App\Actions\Database\RunBackup;
use App\Models\Backup;
use App\Models\BackupFile;
use App\Models\Server;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Support\Enums\MaxWidth;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
@ -57,12 +61,53 @@ public function table(Table $table): Table
->query($this->getTableQuery())
->columns($this->getTableColumns())
->actions([
Action::make('edit')
->hiddenLabel()
->icon('heroicon-o-pencil')
->tooltip('Edit Configuration')
->disabled(fn (Backup $record) => ! in_array($record->status, ['running', 'failed']))
->authorize(fn (Backup $record) => auth()->user()->can('update', $record))
->modelLabel('Edit Backup')
->modalWidth(MaxWidth::Large)
->modalSubmitActionLabel('Update')
->form([
Select::make('interval')
->label('Interval')
->options(config('core.cronjob_intervals'))
->reactive()
->default(fn (Backup $record) => $record->isCustomInterval() ? 'custom' : $record->interval)
->rules(fn (callable $get) => ManageBackup::rules($this->server, $get())['interval']),
TextInput::make('custom_interval')
->label('Custom Interval (Cron)')
->rules(fn (callable $get) => ManageBackup::rules($this->server, $get())['custom_interval'])
->visible(fn (callable $get) => $get('interval') === 'custom')
->default(fn (Backup $record) => $record->isCustomInterval() ? $record->interval : '')
->placeholder('0 * * * *'),
TextInput::make('keep')
->label('Backups to Keep')
->default(fn (Backup $record) => $record->keep_backups)
->rules(fn (callable $get) => ManageBackup::rules($this->server, $get())['keep'])
->helperText('How many backups to keep before deleting the oldest one'),
])
->action(function (Backup $backup, array $data) {
run_action($this, function () use ($data, $backup) {
app(ManageBackup::class)->update($backup, $data);
$this->dispatch('$refresh');
Notification::make()
->success()
->title('Backup updated!')
->send();
});
}),
Action::make('files')
->hiddenLabel()
->icon('heroicon-o-rectangle-stack')
->modalHeading('Backup Files')
->color('gray')
->tooltip('Show backup files')
->disabled(fn (Backup $record) => ! in_array($record->status, ['running', 'failed']))
->authorize(fn (Backup $record) => auth()->user()->can('viewAny', [BackupFile::class, $record]))
->modalContent(fn (Backup $record) => view('components.dynamic-widget', [
'widget' => BackupFilesList::class,
@ -88,16 +133,16 @@ public function table(Table $table): Table
Action::make('delete')
->hiddenLabel()
->icon('heroicon-o-trash')
->modalHeading('Delete Database')
->modalHeading('Delete Backup & Files')
->disabled(fn (Backup $record) => ! in_array($record->status, ['running', 'failed']))
->color('danger')
->tooltip('Delete')
->authorize(fn (Backup $record) => auth()->user()->can('delete', $record))
->requiresConfirmation()
->action(function (Backup $record) {
run_action($this, function () use ($record) {
$record->delete();
$this->dispatch('$refresh');
});
app(ManageBackup::class)->delete($record);
$this->dispatch('$refresh');
}),
]);
}