dgd-backupper-php/app/Commands/ContainerBackupCommand.php

63 lines
1.7 KiB
PHP

<?php
namespace App\Commands;
use App\Constants\BuilderMode;
use App\Utils\BackupManager;
use App\Utils\Builders\ContainerBuilder;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
class ContainerBackupCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'backup:container {containers*} {--backupFolder=}';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Backup Docker Container';
/**
* Execute the console command.
*
* @return mixed
* @throws \Throwable
*/
public function handle()
{
$backupFolder = $this->option('backupFolder');
$containers = $this->argument('containers');
$bm = new BackupManager();
foreach ($containers as $container) {
$this->line("<fg=blue>|-> Backing up {$container}...</>");
$builder = new ContainerBuilder();
$builder->setBackupFolder($backupFolder)->setContainerName($container);
$bm->setBuilder($builder)->execute();
if ($bm->getShell()->getReturnValue() == 0) {
$this->line("<fg=green> |-> {$container} successfully backed up.</>");
} else {
$this->line("<fg=red> |-> {$container} 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();
}
}