Files
glastree/app/Console/Commands/BackupRunCommand.php
T

64 lines
1.8 KiB
PHP
Raw Normal View History

2026-06-01 16:11:29 +02:00
<?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...');
2026-06-23 08:05:51 +02:00
$options = [];
2026-06-01 16:11:29 +02:00
if ($this->option('no-files')) {
2026-06-23 08:05:51 +02:00
$options['include_files'] = false;
2026-06-01 16:11:29 +02:00
$this->warn('Files esclusi dal backup.');
}
if ($this->option('no-env')) {
2026-06-23 08:05:51 +02:00
$options['include_env'] = false;
2026-06-01 16:11:29 +02:00
$this->warn('.env escluso dal backup.');
}
2026-06-23 08:05:51 +02:00
$result = $this->backupService->run($options);
2026-06-01 16:11:29 +02:00
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']));
2026-06-23 08:05:51 +02:00
if (!empty($result['steps'])) {
$this->line('Contenuto:');
foreach ($result['steps'] as $step) {
$this->line(' - ' . $step);
}
}
2026-06-01 16:11:29 +02:00
return Command::SUCCESS;
}
$this->error(' Backup fallito: ' . ($result['message'] ?? 'Errore sconosciuto'));
return Command::FAILURE;
}
}