docker php image use php:8.2-fpm + volume backup export path

This commit is contained in:
xiaomlove
2025-05-17 13:20:42 +07:00
parent 21bb095683
commit 0b35fe662d
6 changed files with 89 additions and 55 deletions

View File

@@ -10,6 +10,7 @@ use App\Models\SearchBox;
use App\Models\Setting;
use App\Models\User;
use App\Repositories\TokenRepository;
use App\Repositories\ToolRepository;
use Filament\Facades\Filament;
use Filament\Resources\Pages\Page;
use Filament\Forms;
@@ -122,7 +123,7 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
// Forms\Components\TextInput::make('backup.google_drive_client_secret')->label(__('label.setting.backup.google_drive_client_secret')),
// Forms\Components\TextInput::make('backup.google_drive_refresh_token')->label(__('label.setting.backup.google_drive_refresh_token')),
// Forms\Components\TextInput::make('backup.google_drive_folder_id')->label(__('label.setting.backup.google_drive_folder_id')),
Forms\Components\TextInput::make('backup.export_path')->label(__('label.setting.backup.export_path'))->helperText(new HtmlString(__('label.setting.backup.export_path_help', ['default_path' => sys_get_temp_dir()]))),
Forms\Components\TextInput::make('backup.export_path')->label(__('label.setting.backup.export_path'))->helperText(new HtmlString(__('label.setting.backup.export_path_help', ['default_path' => ToolRepository::getBackupExportPathDefault()]))),
Forms\Components\Radio::make('backup.via_ftp')->options(self::$yesOrNo)->inline(true)->label(__('label.setting.backup.via_ftp'))->helperText(new HtmlString(__('label.setting.backup.via_ftp_help'))),
Forms\Components\Radio::make('backup.via_sftp')->options(self::$yesOrNo)->inline(true)->label(__('label.setting.backup.via_sftp'))->helperText(new HtmlString(__('label.setting.backup.via_sftp_help'))),
])->columns(2);

View File

@@ -32,7 +32,7 @@ class ToolRepository extends BaseRepository
$webRoot = base_path();
$dirName = basename($webRoot);
$excludes = self::BACKUP_EXCLUDES;
$baseFilename = sprintf('%s/%s.web.%s', Setting::getBackupExportPath() ?: sys_get_temp_dir(), $dirName, date('Ymd.His'));
$baseFilename = sprintf('%s/%s.web.%s', $this->getBackupExportPath(), $dirName, date('Ymd.His'));
if (command_exists('tar') && ($method === 'tar' || $method === null)) {
$filename = $baseFilename . ".tar.gz";
$command = "tar";
@@ -89,9 +89,9 @@ class ToolRepository extends BaseRepository
{
$connectionName = config('database.default');
$config = config("database.connections.$connectionName");
$filename = sprintf('%s/%s.database.%s.sql', Setting::getBackupExportPath() ?: sys_get_temp_dir(), basename(base_path()), date('Ymd.His'));
$filename = sprintf('%s/%s.database.%s.sql', $this->getBackupExportPath(), basename(base_path()), date('Ymd.His'));
$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 --no-tablespaces %s >> %s 2>&1',
$config['username'], $config['password'], $config['host'], $config['port'], $config['database'], $filename,
);
$result = exec($command, $output, $result_code);
@@ -115,7 +115,7 @@ class ToolRepository extends BaseRepository
if ($backupDatabase['result_code'] != 0) {
throw new \RuntimeException("backup database fail: " . json_encode($backupDatabase));
}
$baseFilename = sprintf('%s/%s.%s', Setting::getBackupExportPath() ?: sys_get_temp_dir(), basename(base_path()), date('Ymd.His'));
$baseFilename = sprintf('%s/%s.%s', $this->getBackupExportPath(), basename(base_path()), date('Ymd.His'));
if (command_exists('tar') && ($method === 'tar' || $method === null)) {
$filename = $baseFilename . ".tar.gz";
$command = sprintf(
@@ -149,6 +149,20 @@ class ToolRepository extends BaseRepository
return $this->transfer($filename, $result_code);
}
private function getBackupExportPath(): string
{
$path = Setting::getBackupExportPath();
if (empty($path)) {
$path = self::getBackupExportPathDefault();
}
return $path;
}
public static function getBackupExportPathDefault(): string
{
return sys_get_temp_dir() . "/nexusphp_backup";
}
/**
* do backup cronjob
*