From d5cc2a2eedc644746049a04626ed886dbb4fcb5f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 25 Oct 2023 09:28:26 +0200 Subject: [PATCH] feat: download local backups --- .../Project/Database/BackupExecutions.php | 24 +++++++ composer.json | 1 + composer.lock | 62 ++++++++++++++++++- config/sentry.php | 2 +- config/version.php | 2 +- .../database/backup-executions.blade.php | 8 +-- versions.json | 2 +- 7 files changed, 93 insertions(+), 8 deletions(-) diff --git a/app/Http/Livewire/Project/Database/BackupExecutions.php b/app/Http/Livewire/Project/Database/BackupExecutions.php index 2f808d992..f8ec4efbe 100644 --- a/app/Http/Livewire/Project/Database/BackupExecutions.php +++ b/app/Http/Livewire/Project/Database/BackupExecutions.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire\Project\Database; +use Illuminate\Support\Facades\Storage; use Livewire\Component; class BackupExecutions extends Component @@ -23,6 +24,29 @@ public function deleteBackup($exeuctionId) $this->emit('success', 'Backup deleted successfully.'); $this->emit('refreshBackupExecutions'); } + public function download($exeuctionId) + { + try { + $execution = $this->backup->executions()->where('id', $exeuctionId)->first(); + if (is_null($execution)) { + $this->emit('error', 'Backup execution not found.'); + return; + } + $filename = data_get($execution, 'filename'); + $server = $execution->scheduledDatabaseBackup->database->destination->server; + $privateKeyLocation = savePrivateKeyToFs($server); + $disk = Storage::build([ + 'driver' => 'sftp', + 'host' => $server->ip, + 'port' => $server->port, + 'username' => $server->user, + 'privateKey' => $privateKeyLocation, + ]); + return $disk->download($filename); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } public function refreshBackupExecutions(): void { $this->executions = $this->backup->executions; diff --git a/composer.json b/composer.json index 217560b57..9937ee5b9 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "laravel/ui": "^4.2", "lcobucci/jwt": "^5.0.0", "league/flysystem-aws-s3-v3": "^3.0", + "league/flysystem-sftp-v3": "^3.0", "livewire/livewire": "^v2.12.3", "lorisleiva/laravel-actions": "^2.7", "masmerise/livewire-toaster": "^1.2", diff --git a/composer.lock b/composer.lock index 9f9e8d658..62d4f27ff 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "de2c45be3f03d43430549d963778dc4a", + "content-hash": "21ed976753483557403be75318585442", "packages": [ { "name": "aws/aws-crt-php", @@ -2938,6 +2938,66 @@ ], "time": "2023-08-30T10:23:59+00:00" }, + { + "name": "league/flysystem-sftp-v3", + "version": "3.16.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem-sftp-v3.git", + "reference": "1ba682def8e87fd7fa00883629553c0200d2e974" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem-sftp-v3/zipball/1ba682def8e87fd7fa00883629553c0200d2e974", + "reference": "1ba682def8e87fd7fa00883629553c0200d2e974", + "shasum": "" + }, + "require": { + "league/flysystem": "^3.0.14", + "league/mime-type-detection": "^1.0.0", + "php": "^8.0.2", + "phpseclib/phpseclib": "^3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\Flysystem\\PhpseclibV3\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frankdejonge.nl" + } + ], + "description": "SFTP filesystem adapter for Flysystem.", + "keywords": [ + "Flysystem", + "file", + "files", + "filesystem", + "sftp" + ], + "support": { + "issues": "https://github.com/thephpleague/flysystem-sftp-v3/issues", + "source": "https://github.com/thephpleague/flysystem-sftp-v3/tree/3.16.0" + }, + "funding": [ + { + "url": "https://ecologi.com/frankdejonge", + "type": "custom" + }, + { + "url": "https://github.com/frankdejonge", + "type": "github" + } + ], + "time": "2023-08-30T10:25:05+00:00" + }, { "name": "league/mime-type-detection", "version": "1.13.0", diff --git a/config/sentry.php b/config/sentry.php index 32e27e081..16f184229 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.101', + 'release' => '4.0.0-beta.102', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index d54064579..004c77c3b 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Location: {{ data_get($execution, 'filename', 'N/A') }}
- - {{-- @if (data_get($execution, 'status') !== 'failed') --}} - {{-- Download --}} - {{-- @endif --}} + @if (data_get($execution, 'status') === 'success') + Download + @endif Delete
diff --git a/versions.json b/versions.json index 4c8e06b9d..cd5da1110 100644 --- a/versions.json +++ b/versions.json @@ -4,7 +4,7 @@ "version": "3.12.36" }, "v4": { - "version": "4.0.0-beta.101" + "version": "4.0.0-beta.102" } } }