New Feature
continuous-integration/drone/push Build is failing Details

.env file or argument in command can be used both same time.
master
Muhep Atasoy 2019-12-17 20:38:09 +03:00
parent be09ad70d9
commit 2467ac62e2
6 changed files with 45 additions and 16 deletions

View File

@ -5,21 +5,21 @@ namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command; use LaravelZero\Framework\Commands\Command;
class InspiringCommand extends Command class AboutCommand extends Command
{ {
/** /**
* The signature of the command. * The signature of the command.
* *
* @var string * @var string
*/ */
protected $signature = 'inspiring {name=Artisan}'; protected $signature = 'about';
/** /**
* The description of the command. * The description of the command.
* *
* @var string * @var string
*/ */
protected $description = 'Display an inspiring quote'; protected $description = 'Display about message';
/** /**
* Execute the console command. * Execute the console command.
@ -28,7 +28,12 @@ class InspiringCommand extends Command
*/ */
public function handle() public function handle()
{ {
$this->info('Simplicity is the ultimate sophistication.'); $this->line("<fg=green>Backup manager for backing up Docker Containers to Mega.nz.</>");
$this->line("<fg=blue>Developer: </><fg=red>Muhep Atasoy</>");
$this->line("<fg=magenta>Github: </>https://github.com/muhep06");
$this->line("<fg=red>Gitea: </>https://git.muhepatasoy.xyz/muhep");
$this->line("<fg=yellow>Drone: </>https://drone.muhepatasoy.xyz/muhep/dgd-backupper-php");
return;
} }
/** /**
@ -37,7 +42,7 @@ class InspiringCommand extends Command
* @param \Illuminate\Console\Scheduling\Schedule $schedule * @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void * @return void
*/ */
public function schedule(Schedule $schedule) public function schedule(Schedule $schedule): void
{ {
// $schedule->command(static::class)->everyMinute(); // $schedule->command(static::class)->everyMinute();
} }

View File

@ -2,10 +2,7 @@
namespace App\Commands; namespace App\Commands;
use App\Utils\BackupManager;
use App\Utils\Builders\ContainerBuilder;
use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\Facades\Artisan;
use LaravelZero\Framework\Commands\Command; use LaravelZero\Framework\Commands\Command;
class BackupCommand extends Command class BackupCommand extends Command

View File

@ -15,7 +15,9 @@ class ContainerBackupCommand extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'backup:container {containers*}'; 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. * The description of the command.
@ -33,8 +35,13 @@ class ContainerBackupCommand extends Command
public function handle() public function handle()
{ {
$containers = $this->argument('containers'); $containers = $this->argument('containers');
$backupFolder = $this->option('folder');
if (!$backupFolder) {
$backupFolder = env('BACKUP_FOLDER');
}
$backupManager = new BackupManager(); $backupManager = new BackupManager();
$backupManager->setBackupFolder(env('BACKUP_FOLDER')); $backupManager->setBackupFolder($backupFolder);
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();

View File

@ -15,7 +15,9 @@ class DataBackupCommand extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'backup:data'; protected $signature = 'backup:data
{--data= : You can use it to back up the data folder of all containers or any folder. }
{--folder= : Export folder for backed up folder. }';
/** /**
* The description of the command. * The description of the command.
@ -34,10 +36,19 @@ class DataBackupCommand extends Command
{ {
$this->line("<fg=blue>|-> Backing up data folder...</>"); $this->line("<fg=blue>|-> Backing up data folder...</>");
$backupFolder = $this->option('folder');
$dataFolder = $this->option('data');
if (!$backupFolder) {
$backupFolder = env('BACKUP_FOLDER');
}
if (!$dataFolder) {
$dataFolder = env('DATA_FOLDER');
}
$bm = new BackupManager(); $bm = new BackupManager();
$builder = new DataBuilder(); $builder = new DataBuilder();
$builder->setDataFolder(env('DATA_FOLDER')); $builder->setDataFolder($dataFolder);
$bm->setBackupFolder(env('BACKUP_FOLDER')) $bm->setBackupFolder($backupFolder)
->setBuilder($builder)->execute(); ->setBuilder($builder)->execute();
if ($bm->getShell()->getReturnValue() == 0) { if ($bm->getShell()->getReturnValue() == 0) {

View File

@ -15,7 +15,11 @@ class MysqlBackupCommand extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'backup:mysql {--container=} {--user=} {--password=}'; protected $signature = 'backup:mysql
{--container= : Mysql container name or id}
{--user= : Mysql username}
{--password= : Mysql password}
{--folder= : Export folder for backup}';
/** /**
* The description of the command. * The description of the command.
@ -46,7 +50,12 @@ class MysqlBackupCommand extends Command
$builder->setCredential($credentials); $builder->setCredential($credentials);
$builder->setContainerName($container); $builder->setContainerName($container);
$bm->setBackupFolder(env('BACKUP_FOLDER')) $backupFolder = $this->option('folder');
if (!$backupFolder) {
$backupFolder = env('BACKUP_FOLDER');
}
$bm->setBackupFolder($backupFolder)
->setBuilder($builder)->execute(); ->setBuilder($builder)->execute();
if ($bm->getShell()->getReturnValue() == 0) { if ($bm->getShell()->getReturnValue() == 0) {

View File

@ -13,7 +13,7 @@ class InspiringCommandTest extends TestCase
*/ */
public function testInspiringCommand() public function testInspiringCommand()
{ {
$this->artisan('inspiring') $this->artisan('about')
->expectsOutput('Simplicity is the ultimate sophistication.') ->expectsOutput('Simplicity is the ultimate sophistication.')
->assertExitCode(0); ->assertExitCode(0);
} }