fix getBackupExportPath

This commit is contained in:
xiaomlove
2025-05-17 02:11:34 +07:00
parent 1381390c8c
commit 21bb095683
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -248,9 +248,9 @@ class Setting extends NexusModel
return self::get("permission.user_token_allowed"); return self::get("permission.user_token_allowed");
} }
public static function getBackupExportPath(): string public static function getBackupExportPath(): string|null
{ {
return self::get("backup.export_path", sys_get_temp_dir()); return self::get("backup.export_path");
} }
+3 -3
View File
@@ -32,7 +32,7 @@ class ToolRepository extends BaseRepository
$webRoot = base_path(); $webRoot = base_path();
$dirName = basename($webRoot); $dirName = basename($webRoot);
$excludes = self::BACKUP_EXCLUDES; $excludes = self::BACKUP_EXCLUDES;
$baseFilename = sprintf('%s/%s.web.%s', Setting::getBackupExportPath(), $dirName, date('Ymd.His')); $baseFilename = sprintf('%s/%s.web.%s', Setting::getBackupExportPath() ?: sys_get_temp_dir(), $dirName, date('Ymd.His'));
if (command_exists('tar') && ($method === 'tar' || $method === null)) { if (command_exists('tar') && ($method === 'tar' || $method === null)) {
$filename = $baseFilename . ".tar.gz"; $filename = $baseFilename . ".tar.gz";
$command = "tar"; $command = "tar";
@@ -89,7 +89,7 @@ class ToolRepository extends BaseRepository
{ {
$connectionName = config('database.default'); $connectionName = config('database.default');
$config = config("database.connections.$connectionName"); $config = config("database.connections.$connectionName");
$filename = sprintf('%s/%s.database.%s.sql', Setting::getBackupExportPath(), basename(base_path()), date('Ymd.His')); $filename = sprintf('%s/%s.database.%s.sql', Setting::getBackupExportPath() ?: sys_get_temp_dir(), basename(base_path()), date('Ymd.His'));
$command = sprintf( $command = sprintf(
'mysqldump --user=%s --password=%s --host=%s --port=%s --single-transaction --no-create-db %s >> %s 2>&1', 'mysqldump --user=%s --password=%s --host=%s --port=%s --single-transaction --no-create-db %s >> %s 2>&1',
$config['username'], $config['password'], $config['host'], $config['port'], $config['database'], $filename, $config['username'], $config['password'], $config['host'], $config['port'], $config['database'], $filename,
@@ -115,7 +115,7 @@ class ToolRepository extends BaseRepository
if ($backupDatabase['result_code'] != 0) { if ($backupDatabase['result_code'] != 0) {
throw new \RuntimeException("backup database fail: " . json_encode($backupDatabase)); throw new \RuntimeException("backup database fail: " . json_encode($backupDatabase));
} }
$baseFilename = sprintf('%s/%s.%s', Setting::getBackupExportPath(), basename(base_path()), date('Ymd.His')); $baseFilename = sprintf('%s/%s.%s', Setting::getBackupExportPath() ?: sys_get_temp_dir(), basename(base_path()), date('Ymd.His'));
if (command_exists('tar') && ($method === 'tar' || $method === null)) { if (command_exists('tar') && ($method === 'tar' || $method === null)) {
$filename = $baseFilename . ".tar.gz"; $filename = $baseFilename . ".tar.gz";
$command = sprintf( $command = sprintf(