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

69 lines
1.9 KiB
PHP

<?php
namespace App\Commands;
use App\Utils\BackupManager;
use App\Utils\Builders\DatabaseBuilder;
use App\Utils\Credential;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
class MysqlBackupCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'backup:mysql {--container=} {--user=} {--password=} {--backupFolder=}';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Backup mysql databases.';
/**
* Execute the console command.
*
* @return mixed
* @throws \Throwable
*/
public function handle()
{
$container = $this->option('container');
$user = $this->option('user');
$password = $this->option('password');
$backupFolder = $this->option('backupFolder');
$bm = new BackupManager();
$this->line("<fg=blue>|-> Backing up mysql databases...</>");
$credentials = new Credential();
$credentials->setUsername($user);
$credentials->setPassword($password);
$builder = new DatabaseBuilder();
$builder->setCredential($credentials);
$builder->setBackupFolder($backupFolder)->setContainerName($container);
$output = $bm->setBuilder($builder)->execute();
if ($bm->getShell()->getReturnValue() == 0) {
$this->line("<fg=green> |-> Mysql databases successfully backed up.</>");
} else {
$this->line("<fg=red> |-> Mysql databases 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();
}
}