mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
backup add transfer option
This commit is contained in:
@@ -12,7 +12,7 @@ class BackupDatabase extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'backup:database';
|
protected $signature = 'backup:database {--transfer=}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@@ -39,7 +39,9 @@ class BackupDatabase extends Command
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$rep = new ToolRepository();
|
$rep = new ToolRepository();
|
||||||
$result = $rep->backupDatabase();
|
$transfer = $this->option('transfer');
|
||||||
|
$this->info("transfer: $transfer");
|
||||||
|
$result = $rep->backupDatabase($transfer);
|
||||||
$log = sprintf('[%s], %s, result: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true));
|
$log = sprintf('[%s], %s, result: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true));
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class BackupWeb extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'backup:web {--method=}';
|
protected $signature = 'backup:web {--method=} {--transfer=}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@@ -39,9 +39,10 @@ class BackupWeb extends Command
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$method = $this->option('method');
|
$method = $this->option('method');
|
||||||
$this->info("method: $method");
|
$transfer = $this->option('transfer');
|
||||||
|
$this->info("method: $method, transfer: $transfer");
|
||||||
$rep = new ToolRepository();
|
$rep = new ToolRepository();
|
||||||
$result = $rep->backupWeb($method);
|
$result = $rep->backupWeb($method, $transfer);
|
||||||
$log = sprintf('[%s], %s, result: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true));
|
$log = sprintf('[%s], %s, result: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true));
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
|
|||||||
@@ -88,9 +88,8 @@ class Test extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$rep = new PluginRepository();
|
$rep = new ToolRepository();
|
||||||
// $rep->installCronjob();
|
$r = $rep->transfer('C:\Users\CHENYU~1\AppData\Local\Temp/nexusphp.v1.5.beta5.20120707.web.20220918.053953.zip', 0);
|
||||||
$r = $rep->getInstalledVersion('xiaomlove/nexusphp-post-like');
|
|
||||||
dd($r);
|
dd($r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class ToolRepository extends BaseRepository
|
|||||||
{
|
{
|
||||||
const BACKUP_EXCLUDES = ['vendor', 'node_modules', '.git', '.idea', '.settings', '.DS_Store', '.github'];
|
const BACKUP_EXCLUDES = ['vendor', 'node_modules', '.git', '.idea', '.settings', '.DS_Store', '.github'];
|
||||||
|
|
||||||
public function backupWeb($method = null): array
|
public function backupWeb($method = null, $transfer = false): array
|
||||||
{
|
{
|
||||||
$webRoot = base_path();
|
$webRoot = base_path();
|
||||||
$dirName = basename($webRoot);
|
$dirName = basename($webRoot);
|
||||||
@@ -76,10 +76,13 @@ class ToolRepository extends BaseRepository
|
|||||||
$result_code = 0;
|
$result_code = 0;
|
||||||
do_log("No tar command, use zip.");
|
do_log("No tar command, use zip.");
|
||||||
}
|
}
|
||||||
return compact('result_code', 'filename');
|
if (!$transfer) {
|
||||||
|
return compact('result_code', 'filename');
|
||||||
|
}
|
||||||
|
return $this->transfer($filename, $result_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function backupDatabase(): array
|
public function backupDatabase($transfer = false): array
|
||||||
{
|
{
|
||||||
$connectionName = config('database.default');
|
$connectionName = config('database.default');
|
||||||
$config = config("database.connections.$connectionName");
|
$config = config("database.connections.$connectionName");
|
||||||
@@ -93,10 +96,13 @@ class ToolRepository extends BaseRepository
|
|||||||
"command: %s, output: %s, result_code: %s, result: %s, filename: %s",
|
"command: %s, output: %s, result_code: %s, result: %s, filename: %s",
|
||||||
$command, json_encode($output), $result_code, $result, $filename
|
$command, json_encode($output), $result_code, $result, $filename
|
||||||
));
|
));
|
||||||
return compact('result_code', 'filename');
|
if (!$transfer) {
|
||||||
|
return compact('result_code', 'filename');
|
||||||
|
}
|
||||||
|
return $this->transfer($filename, $result_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function backupAll($method = null): array
|
public function backupAll($method = null, $transfer = false): array
|
||||||
{
|
{
|
||||||
$backupWeb = $this->backupWeb($method);
|
$backupWeb = $this->backupWeb($method);
|
||||||
if ($backupWeb['result_code'] != 0) {
|
if ($backupWeb['result_code'] != 0) {
|
||||||
@@ -134,8 +140,10 @@ class ToolRepository extends BaseRepository
|
|||||||
$result_code = 0;
|
$result_code = 0;
|
||||||
do_log("No tar command, use zip.");
|
do_log("No tar command, use zip.");
|
||||||
}
|
}
|
||||||
return compact('result_code', 'filename');
|
if (!$transfer) {
|
||||||
|
return compact('result_code', 'filename');
|
||||||
|
}
|
||||||
|
return $this->transfer($filename, $result_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,27 +186,33 @@ class ToolRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
$backupResult = $this->backupAll();
|
$backupResult = $this->backupAll();
|
||||||
do_log("Backup all result: " . json_encode($backupResult));
|
do_log("Backup all result: " . json_encode($backupResult));
|
||||||
if ($backupResult['result_code'] != 0) {
|
$transferResult = $this->transfer($backupResult['filename'], $backupResult['result_code'], $setting);
|
||||||
throw new \RuntimeException("Backup all fail.");
|
$backupResult['transfer_result'] = $transferResult;
|
||||||
}
|
do_log("[BACKUP_ALL_DONE]: " . json_encode($backupResult));
|
||||||
$filename = $backupResult['filename'];
|
return $backupResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transfer($filename, $result_code, $setting = null): array
|
||||||
|
{
|
||||||
|
if ($result_code != 0) {
|
||||||
|
throw new \RuntimeException("file: $filename backup fail!");
|
||||||
|
}
|
||||||
|
$result = compact('filename', 'result_code');
|
||||||
|
if (empty($setting)) {
|
||||||
|
$setting = Setting::get('backup');
|
||||||
|
}
|
||||||
$saveResult = $this->saveToGoogleDrive($setting, $filename);
|
$saveResult = $this->saveToGoogleDrive($setting, $filename);
|
||||||
do_log("[BACKUP_GOOGLE_DRIVE]: $saveResult");
|
do_log("[BACKUP_GOOGLE_DRIVE]: $saveResult");
|
||||||
$backupResult['google_drive'] = $saveResult;
|
$result['google_drive'] = $saveResult;
|
||||||
|
|
||||||
$saveResult = $this->saveToFtp($setting, $filename);
|
$saveResult = $this->saveToFtp($setting, $filename);
|
||||||
do_log("[BACKUP_FTP]: $saveResult");
|
do_log("[BACKUP_FTP]: $saveResult");
|
||||||
$backupResult['ftp'] = $saveResult;
|
$result['ftp'] = $saveResult;
|
||||||
|
|
||||||
$saveResult = $this->saveToSftp($setting, $filename);
|
$saveResult = $this->saveToSftp($setting, $filename);
|
||||||
do_log("[BACKUP_SFTP]: $saveResult");
|
do_log("[BACKUP_SFTP]: $saveResult");
|
||||||
$backupResult['sftp'] = $saveResult;
|
$result['sftp'] = $saveResult;
|
||||||
|
return $result;
|
||||||
do_log("[BACKUP_ALL_DONE]: " . json_encode($backupResult));
|
|
||||||
|
|
||||||
return $backupResult;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function saveToGoogleDrive(array $setting, $filename): bool|string
|
private function saveToGoogleDrive(array $setting, $filename): bool|string
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.7.27');
|
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.7.27');
|
||||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-09-17');
|
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-09-18');
|
||||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||||
|
|||||||
Reference in New Issue
Block a user