New Features
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
77ed2426db
commit
a3dcc671b8
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,7 @@ class ContainerBackupCommand extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'backup:container {containers*} {--backupFolder=}';
|
protected $signature = 'backup:container {containers*}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The description of the command.
|
* The description of the command.
|
||||||
|
|
@ -32,13 +32,12 @@ class ContainerBackupCommand extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$backupFolder = $this->option('backupFolder');
|
|
||||||
$containers = $this->argument('containers');
|
$containers = $this->argument('containers');
|
||||||
$bm = new BackupManager();
|
$bm = new BackupManager();
|
||||||
foreach ($containers as $container) {
|
foreach ($containers as $container) {
|
||||||
$this->line("<fg=blue>|-> Backing up {$container}...</>");
|
$this->line("<fg=blue>|-> Backing up {$container}...</>");
|
||||||
$builder = new ContainerBuilder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->setBackupFolder($backupFolder)->setContainerName($container);
|
$builder->setBackupFolder(env('BACKUP_FOLDER'))->setContainerName($container);
|
||||||
$bm->setBuilder($builder)->execute();
|
$bm->setBuilder($builder)->execute();
|
||||||
if ($bm->getShell()->getReturnValue() == 0) {
|
if ($bm->getShell()->getReturnValue() == 0) {
|
||||||
$this->line("<fg=green> |-> {$container} successfully backed up.</>");
|
$this->line("<fg=green> |-> {$container} successfully backed up.</>");
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class DataBackupCommand extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'backup:data {--dataFolder=} {--backupFolder=} {--clean}';
|
protected $signature = 'backup:data';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The description of the command.
|
* The description of the command.
|
||||||
|
|
@ -32,16 +32,12 @@ class DataBackupCommand extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$backupFolder = $this->option('backupFolder');
|
|
||||||
$dataFolder = $this->option('dataFolder');
|
|
||||||
$clean = $this->option('clean');
|
|
||||||
$this->line("<fg=blue>|-> Backing up data folder...</>");
|
$this->line("<fg=blue>|-> Backing up data folder...</>");
|
||||||
|
|
||||||
$bm = new BackupManager();
|
$bm = new BackupManager();
|
||||||
$builder = new DataBuilder();
|
$builder = new DataBuilder();
|
||||||
$builder->setDataFolder($dataFolder)
|
$builder->setDataFolder(env('DATA_FOLDER'))
|
||||||
->setBackupFolder($backupFolder)
|
->setBackupFolder(env('BACKUP_FOLDER'));
|
||||||
->setClean($clean);
|
|
||||||
$bm->setBuilder($builder)->execute();
|
$bm->setBuilder($builder)->execute();
|
||||||
|
|
||||||
if ($bm->getShell()->getReturnValue() == 0) {
|
if ($bm->getShell()->getReturnValue() == 0) {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class MysqlBackupCommand extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'backup:mysql {--container=} {--user=} {--password=} {--backupFolder=}';
|
protected $signature = 'backup:mysql {--container=} {--user=} {--password=}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The description of the command.
|
* The description of the command.
|
||||||
|
|
@ -35,7 +35,6 @@ class MysqlBackupCommand extends Command
|
||||||
$container = $this->option('container');
|
$container = $this->option('container');
|
||||||
$user = $this->option('user');
|
$user = $this->option('user');
|
||||||
$password = $this->option('password');
|
$password = $this->option('password');
|
||||||
$backupFolder = $this->option('backupFolder');
|
|
||||||
$bm = new BackupManager();
|
$bm = new BackupManager();
|
||||||
$this->line("<fg=blue>|-> Backing up mysql databases...</>");
|
$this->line("<fg=blue>|-> Backing up mysql databases...</>");
|
||||||
|
|
||||||
|
|
@ -45,8 +44,9 @@ class MysqlBackupCommand extends Command
|
||||||
|
|
||||||
$builder = new DatabaseBuilder();
|
$builder = new DatabaseBuilder();
|
||||||
$builder->setCredential($credentials);
|
$builder->setCredential($credentials);
|
||||||
$builder->setBackupFolder($backupFolder)->setContainerName($container);
|
$builder->setBackupFolder(env('BACKUP_FOLDER'))
|
||||||
$output = $bm->setBuilder($builder)->execute();
|
->setContainerName($container);
|
||||||
|
$bm->setBuilder($builder)->execute();
|
||||||
if ($bm->getShell()->getReturnValue() == 0) {
|
if ($bm->getShell()->getReturnValue() == 0) {
|
||||||
$this->line("<fg=green> |-> Mysql databases successfully backed up.</>");
|
$this->line("<fg=green> |-> Mysql databases successfully backed up.</>");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue