mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
backup add feature: upload to google drive
This commit is contained in:
@@ -12,14 +12,14 @@ class BackuAll extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'backup:all';
|
||||
protected $signature = 'backup:all {--upload-to-google-drive}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Backup all data, include web root and database';
|
||||
protected $description = 'Backup all data, include web root and database. options: --upload-to-google-drive';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
@@ -38,9 +38,13 @@ class BackuAll extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$uploadToGoogleDrive = $this->option('upload-to-google-drive');
|
||||
$rep = new ToolRepository();
|
||||
$result = $rep->backupAll();
|
||||
$log = sprintf('[%s], %s, result: %s', REQUEST_ID, __METHOD__, var_export($result, true));
|
||||
$result = $rep->backupAll($uploadToGoogleDrive);
|
||||
$log = sprintf(
|
||||
'[%s], %s, uploadToGoogleDrive: %s, result: %s',
|
||||
REQUEST_ID, __METHOD__, var_export($uploadToGoogleDrive, true), var_export($result, true)
|
||||
);
|
||||
$this->info($log);
|
||||
do_log($log);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class Test extends Command
|
||||
// $rep->assignCronjob();
|
||||
// $r = $rep->cronjobCheckout();
|
||||
$disk = Storage::disk('google_dirve');
|
||||
$r = $disk->files();
|
||||
$r = $disk->put('/', base_path('composer.json'));
|
||||
dd($r);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ class Invite extends NexusModel
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'inviter', 'invitee', 'hash', 'time_invited', 'valid', 'invitee_register_uid', 'invitee_register_email', 'invitee_register_username'
|
||||
'inviter', 'invitee', 'hash', 'time_invited', 'valid',
|
||||
'invitee_register_uid', 'invitee_register_email', 'invitee_register_username'
|
||||
];
|
||||
|
||||
public function getValidTextAttribute()
|
||||
|
||||
@@ -14,7 +14,7 @@ class GoogleDriveServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Storage::extend('google_dirve', function($app, $config) {
|
||||
Storage::extend('google_drive', function($app, $config) {
|
||||
$client = new \Google_Client();
|
||||
$client->setClientId($config['clientId']);
|
||||
$client->setClientSecret($config['clientSecret']);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ToolRepository extends BaseRepository
|
||||
{
|
||||
@@ -54,7 +55,7 @@ class ToolRepository extends BaseRepository
|
||||
return compact('result_code', 'filename');
|
||||
}
|
||||
|
||||
public function backupAll()
|
||||
public function backupAll($uploadToGoogleDrive = false)
|
||||
{
|
||||
$backupWeb = $this->backupWebRoot();
|
||||
if ($backupWeb['result_code'] != 0) {
|
||||
@@ -76,7 +77,12 @@ class ToolRepository extends BaseRepository
|
||||
"command: %s, output: %s, result_code: %s, result: %s, filename: %s",
|
||||
$command, json_encode($output), $result_code, $result, $filename
|
||||
));
|
||||
return compact('result_code', 'filename');
|
||||
$upload_result = '';
|
||||
if ($uploadToGoogleDrive) {
|
||||
$disk = Storage::disk('google_drive');
|
||||
$upload_result = $disk->put(basename($filename), fopen($filename, 'r'));
|
||||
}
|
||||
return compact('result_code', 'filename', 'upload_result');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user