feat: download local backups

This commit is contained in:
Andras Bacsai 2023-10-25 09:28:26 +02:00
parent 5e8ac1b48e
commit d5cc2a2eed
7 changed files with 93 additions and 8 deletions

View File

@ -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;

View File

@ -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",

62
composer.lock generated
View File

@ -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",

View File

@ -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'),

View File

@ -1,3 +1,3 @@
<?php
return '4.0.0-beta.101';
return '4.0.0-beta.102';

View File

@ -17,10 +17,10 @@
<div>Location: {{ data_get($execution, 'filename', 'N/A') }}</div>
<div class="flex gap-2">
<div class="flex-1"></div>
{{-- @if (data_get($execution, 'status') !== 'failed') --}}
{{-- <x-forms.button class="bg-coollabs-100 hover:bg-coollabs" wire:click="download">Download</x-forms.button> --}}
{{-- @endif --}}
@if (data_get($execution, 'status') === 'success')
<x-forms.button class=" hover:bg-coolgray-400"
wire:click="download({{ data_get($execution, 'id') }})">Download</x-forms.button>
@endif
<x-forms.button isError onclick="sure({{ data_get($execution, 'id') }})">Delete</x-forms.button>
</div>
</form>

View File

@ -4,7 +4,7 @@
"version": "3.12.36"
},
"v4": {
"version": "4.0.0-beta.101"
"version": "4.0.0-beta.102"
}
}
}