final stage
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\BackupService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class BackupRunCommand extends Command
|
||||
{
|
||||
protected $signature = 'backup:run
|
||||
{--filename= : Custom filename prefix for the backup file}
|
||||
{--no-files : Exclude uploaded files from backup}
|
||||
{--no-env : Exclude .env from backup}';
|
||||
|
||||
protected $description = 'Esegue un backup completo del database, file e configurazione';
|
||||
|
||||
private BackupService $backupService;
|
||||
|
||||
public function __construct(BackupService $backupService)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->backupService = $backupService;
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$this->info('Avvio backup...');
|
||||
|
||||
if ($this->option('no-files')) {
|
||||
$this->backupService->saveConfig(['backup_include_files' => false]);
|
||||
$this->warn('Files esclusi dal backup.');
|
||||
}
|
||||
if ($this->option('no-env')) {
|
||||
$this->backupService->saveConfig(['backup_include_env' => false]);
|
||||
$this->warn('.env escluso dal backup.');
|
||||
}
|
||||
|
||||
$result = $this->backupService->run();
|
||||
|
||||
if ($result['success']) {
|
||||
$this->info(' Backup completato con successo!');
|
||||
$this->line('File: ' . $result['filename']);
|
||||
$this->line('Dimensione: ' . $result['size_formatted']);
|
||||
$this->line('Percorso: ' . storage_path('app/backups/' . $result['filename']));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$this->error(' Backup fallito: ' . ($result['message'] ?? 'Errore sconosciuto'));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user