Files
glastree/app/Console/Commands/BackupRunCommand.php
T
2026-06-01 16:11:29 +02:00

56 lines
1.6 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...');
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;
}
}