70 lines
2.0 KiB
PHP
70 lines
2.0 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* : Name or ID of the containers to be backed up.}
|
|
{--folder= : Export folder for backed up containers.}';
|
|
|
|
/**
|
|
* The description of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Backup Docker Container';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
* @throws \Throwable
|
|
*/
|
|
public function handle()
|
|
{
|
|
$containers = $this->argument('containers');
|
|
$backupFolder = $this->option('folder');
|
|
if (!$backupFolder) {
|
|
$backupFolder = env('BACKUP_FOLDER');
|
|
}
|
|
|
|
$backupManager = new BackupManager();
|
|
foreach ($containers as $container) {
|
|
$this->line("<fg=blue>|-> Backing up {$container}...</>");
|
|
$builder = new ContainerBuilder();
|
|
$builder->setContainerName($container)
|
|
->setBackupFolder($backupFolder);
|
|
$backupManager->setBuilder($builder)->execute();
|
|
if ($backupManager->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();
|
|
}
|
|
}
|