New Features
continuous-integration/drone/push Build is passing Details

master
Muhep Atasoy 2019-12-14 17:51:09 +03:00
parent 77ed2426db
commit a3dcc671b8
4 changed files with 73 additions and 14 deletions

View File

@ -0,0 +1,64 @@
<?php
namespace App\Commands;
use App\Utils\BackupManager;
use App\Utils\Builders\ContainerBuilder;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\Facades\Artisan;
use LaravelZero\Framework\Commands\Command;
class BackupCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'backup {containers*} {--data} {--mysql} {--upload}';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Backup docker containers and all data.';
/**
* Execute the console command.
*
* @return mixed
* @throws \Throwable
*/
public function handle()
{
$containers = $this->argument('containers');
$this->line("<fg=red>### Backup is starting... ###</>");
$this->call("backup:container", [ 'containers' => $containers]);
if ($this->option('data')) {
$this->call("backup:data");
}
if ($this->option('mysql')) {
$this->call("backup:mysql", [
'--container' => env('MYSQL_CONTAINER_NAME'),
'--user' => env('MYSQL_USER'),
'--password' => env('MYSQL_PASSWORD'),
]);
}
$this->line("<fg=blue>|-> The backup and upload process is finished.</>");
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();
}
}

View File

@ -15,7 +15,7 @@ class ContainerBackupCommand extends Command
*
* @var string
*/
protected $signature = 'backup:container {containers*} {--backupFolder=}';
protected $signature = 'backup:container {containers*}';
/**
* The description of the command.
@ -32,13 +32,12 @@ class ContainerBackupCommand extends Command
*/
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);
$builder->setBackupFolder(env('BACKUP_FOLDER'))->setContainerName($container);
$bm->setBuilder($builder)->execute();
if ($bm->getShell()->getReturnValue() == 0) {
$this->line("<fg=green> |-> {$container} successfully backed up.</>");

View File

@ -15,7 +15,7 @@ class DataBackupCommand extends Command
*
* @var string
*/
protected $signature = 'backup:data {--dataFolder=} {--backupFolder=} {--clean}';
protected $signature = 'backup:data';
/**
* The description of the command.
@ -32,16 +32,12 @@ class DataBackupCommand extends Command
*/
public function handle()
{
$backupFolder = $this->option('backupFolder');
$dataFolder = $this->option('dataFolder');
$clean = $this->option('clean');
$this->line("<fg=blue>|-> Backing up data folder...</>");
$bm = new BackupManager();
$builder = new DataBuilder();
$builder->setDataFolder($dataFolder)
->setBackupFolder($backupFolder)
->setClean($clean);
$builder->setDataFolder(env('DATA_FOLDER'))
->setBackupFolder(env('BACKUP_FOLDER'));
$bm->setBuilder($builder)->execute();
if ($bm->getShell()->getReturnValue() == 0) {

View File

@ -15,7 +15,7 @@ class MysqlBackupCommand extends Command
*
* @var string
*/
protected $signature = 'backup:mysql {--container=} {--user=} {--password=} {--backupFolder=}';
protected $signature = 'backup:mysql {--container=} {--user=} {--password=}';
/**
* The description of the command.
@ -35,7 +35,6 @@ class MysqlBackupCommand extends Command
$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...</>");
@ -45,8 +44,9 @@ class MysqlBackupCommand extends Command
$builder = new DatabaseBuilder();
$builder->setCredential($credentials);
$builder->setBackupFolder($backupFolder)->setContainerName($container);
$output = $bm->setBuilder($builder)->execute();
$builder->setBackupFolder(env('BACKUP_FOLDER'))
->setContainerName($container);
$bm->setBuilder($builder)->execute();
if ($bm->getShell()->getReturnValue() == 0) {
$this->line("<fg=green> |-> Mysql databases successfully backed up.</>");
} else {