Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pseux committed Apr 23, 2020
1 parent 665b912 commit 0e78de4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/Commands/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
namespace Pseux\Backup\Commands;

use Illuminate\Http\File;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;

class Backup extends Command
class Backup extends BaseBackup
{
protected $signature = 'backup {type}';
protected $description = 'Creating backups of files';
Expand All @@ -21,6 +20,9 @@ public function __construct()

public function handle()
{
if (env('AWS_ACCESS_KEY_ID') === null)
return $this->error('No AWS credentials found.');

$type = $this->argument('type');

switch ($type)
Expand Down Expand Up @@ -54,6 +56,8 @@ private function runBackupEnv()
$this->error('Error creating backup: ' . $e->getMessage());
exit;
}

$this->info('Backup successful at: ' . $remote_dir);
}

private function runBackupDB()
Expand Down Expand Up @@ -97,7 +101,7 @@ private function runBackupDB()
exit;
}

$this->info('Backup successful as: ' . $remote_dir);
$this->info('Backup successful at: ' . $remote_dir);
}

private function getStorageDir()
Expand Down
9 changes: 5 additions & 4 deletions src/Commands/BackupImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
namespace Pseux\Backup\Commands;

use Illuminate\Http\File;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;

class BackupImport extends Command
class BackupImport extends BaseBackup
{
protected $signature = 'backup:import {type} {source?}';
protected $description = 'Import previous backups';
Expand All @@ -21,9 +20,11 @@ public function __construct()

public function handle()
{
if (env('AWS_ACCESS_KEY_ID') === null)
return $this->error('No AWS credentials found.');

$type = $this->argument('type');
$source = $this->argument('source');
if ($source === null) $source = config('app.env');
$source = $this->argument('source') ?: config('app.env');

switch ($type)
{
Expand Down
28 changes: 28 additions & 0 deletions src/Commands/BaseBackup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Pseux\Backup\Commands;

use Illuminate\Console\Command;
use App;
use \Dotenv\Dotenv;

class BaseBackup extends Command
{
public function __construct()
{
parent::__construct();

if (config('app.env') === 'local' && env('AWS_ACCESS_KEY_ID') === null)
{
if (!is_file(env('HOME') . '/.backupconfig')) return;

$dotenv = Dotenv::createMutable(env('HOME'), '.backupconfig');
$dotenv->load();

config(['filesystems.disks.s3.key' => env('AWS_ACCESS_KEY_ID')]);
config(['filesystems.disks.s3.secret' => env('AWS_SECRET_ACCESS_KEY')]);
config(['filesystems.disks.s3.region' => env('AWS_DEFAULT_REGION')]);
config(['filesystems.disks.s3.bucket' => env('AWS_BUCKET')]);
}
}
}

0 comments on commit 0e78de4

Please sign in to comment.