mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
database backups
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\BackupFileStatus;
|
||||
use App\Jobs\Backup\RunBackup;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@ -10,7 +11,6 @@
|
||||
|
||||
/**
|
||||
* @property string $type
|
||||
* @property string $name
|
||||
* @property int $server_id
|
||||
* @property int $storage_id
|
||||
* @property int $database_id
|
||||
@ -28,7 +28,6 @@ class Backup extends AbstractModel
|
||||
|
||||
protected $fillable = [
|
||||
'type',
|
||||
'name',
|
||||
'server_id',
|
||||
'storage_id',
|
||||
'database_id',
|
||||
@ -77,8 +76,8 @@ public function run(): void
|
||||
{
|
||||
$file = new BackupFile([
|
||||
'backup_id' => $this->id,
|
||||
'name' => Str::of($this->name)->slug().'-'.now()->format('YmdHis'),
|
||||
'status' => 'creating',
|
||||
'name' => Str::of($this->database->name)->slug().'-'.now()->format('YmdHis'),
|
||||
'status' => BackupFileStatus::CREATING,
|
||||
]);
|
||||
$file->save();
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\BackupFileStatus;
|
||||
use App\Jobs\Backup\RestoreDatabase;
|
||||
use App\Jobs\StorageProvider\DeleteFile;
|
||||
use Carbon\Carbon;
|
||||
@ -75,12 +76,12 @@ public function getPathAttribute(): string
|
||||
|
||||
public function getStoragePathAttribute(): string
|
||||
{
|
||||
return '/'.$this->backup->name.'/'.$this->name.'.zip';
|
||||
return '/'.$this->backup->database->name.'/'.$this->name.'.zip';
|
||||
}
|
||||
|
||||
public function restore(Database $database): void
|
||||
{
|
||||
$this->status = 'restoring';
|
||||
$this->status = BackupFileStatus::RESTORING;
|
||||
$this->restored_to = $database->name;
|
||||
$this->save();
|
||||
dispatch(new RestoreDatabase($this, $database))->onConnection('ssh');
|
||||
|
@ -2,18 +2,14 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $user_id
|
||||
* @property string $profile
|
||||
* @property string $provider
|
||||
* @property string $label
|
||||
* @property string $token
|
||||
* @property string $refresh_token
|
||||
* @property bool $connected
|
||||
* @property Carbon $token_expires_at
|
||||
* @property array $credentials
|
||||
* @property User $user
|
||||
*/
|
||||
class StorageProvider extends AbstractModel
|
||||
@ -22,18 +18,14 @@ class StorageProvider extends AbstractModel
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'profile',
|
||||
'provider',
|
||||
'label',
|
||||
'token',
|
||||
'refresh_token',
|
||||
'connected',
|
||||
'token_expires_at',
|
||||
'credentials',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'integer',
|
||||
'connected' => 'boolean',
|
||||
'token_expires_at' => 'datetime',
|
||||
'credentials' => 'encrypted:array',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
|
Reference in New Issue
Block a user