64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?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...');
|
|
|
|
$options = [];
|
|
if ($this->option('no-files')) {
|
|
$options['include_files'] = false;
|
|
$this->warn('Files esclusi dal backup.');
|
|
}
|
|
if ($this->option('no-env')) {
|
|
$options['include_env'] = false;
|
|
$this->warn('.env escluso dal backup.');
|
|
}
|
|
|
|
$result = $this->backupService->run($options);
|
|
|
|
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']));
|
|
|
|
if (!empty($result['steps'])) {
|
|
$this->line('Contenuto:');
|
|
foreach ($result['steps'] as $step) {
|
|
$this->line(' - ' . $step);
|
|
}
|
|
}
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
$this->error(' Backup fallito: ' . ($result['message'] ?? 'Errore sconosciuto'));
|
|
|
|
return Command::FAILURE;
|
|
}
|
|
}
|