61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use App\Utils\BackupManager;
|
|
use App\Utils\Builders\DataBuilder;
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use LaravelZero\Framework\Commands\Command;
|
|
use Throwable;
|
|
|
|
class DataBackupCommand extends Command
|
|
{
|
|
/**
|
|
* The signature of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'backup:data {--dataFolder=} {--backupFolder=}';
|
|
|
|
/**
|
|
* The description of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Backup containers data folder.';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
* @throws Throwable
|
|
*/
|
|
public function handle()
|
|
{
|
|
$backupFolder = $this->option('backupFolder');
|
|
$dataFolder = $this->option('dataFolder');
|
|
$bm = new BackupManager();
|
|
$this->line("<fg=blue>|-> Backing up data folder...</>");
|
|
$builder = new DataBuilder();
|
|
$builder->setDataFolder($dataFolder)->setBackupFolder($backupFolder);
|
|
$bm->setBuilder($builder)->execute();
|
|
if ($bm->getShell()->getReturnValue() == 0) {
|
|
$this->line("<fg=green> |-> Data folder successfully backed up.</>");
|
|
} else {
|
|
$this->line("<fg=red> |-> Data folder could not be backed up.</>");
|
|
}
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* Define the command's schedule.
|
|
*
|
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
|
* @return void
|
|
*/
|
|
public function schedule(Schedule $schedule): void
|
|
{
|
|
// $schedule->command(static::class)->everyMinute();
|
|
}
|
|
}
|