N°8379 - fix backup issue

This commit is contained in:
jf-cbd
2025-05-13 16:05:39 +02:00
parent 5232694c04
commit 544c4ae888
4 changed files with 25 additions and 37 deletions

View File

@@ -104,6 +104,8 @@ class DBBackup
/** @var string */
protected $sDBName;
/** @var string */
protected $sMySQLBinDir = '';
/** @var string */
protected $sDBSubName;
/**
@@ -131,7 +133,6 @@ class DBBackup
$this->sDBSubName = $oConfig->get('db_subname');
}
protected $sMySQLBinDir = '';
/**
* Create a normalized backup name, depending on the current date/time and Database
@@ -299,8 +300,9 @@ class DBBackup
}
$this->LogInfo("Starting backup of $this->sDBHost/$this->sDBName(suffix:'$this->sDBSubName')");
$sMySQLBinDir = utils::ReadParam('mysql_bindir', $this->sMySQLBinDir, true);
$sMySQLDump = $this->GetMysqldumpCommand();
$sMySQLDump = $this->MakeSafeMySQLCommand($sMySQLBinDir, 'mysqldump');
// Store the results in a temporary file
$sTmpFileName = self::EscapeShellArg($sBackupFileName);
@@ -557,20 +559,22 @@ EOF;
/**
* @return string the command to launch mysqldump (without its params)
* @throws \BackupException
*/
private function GetMysqldumpCommand()
public static function MakeSafeMySQLCommand(string $sMySQLBinDir, string $sCmd)
{
$sMySQLBinDir = utils::ReadParam('mysql_bindir', $this->sMySQLBinDir, true);
if (empty($sMySQLBinDir))
{
$sMysqldumpCommand = 'mysqldump';
if (empty($sMySQLBinDir)) {
$sMySQLCommand = $sCmd;
}
else
{
$sMysqldumpCommand = '"'.$sMySQLBinDir.'/mysqldump"';
else {
$sMySQLBinDir = escapeshellcmd($sMySQLBinDir);
$sMySQLCommand = '"'.$sMySQLBinDir.'/$sCmd"';
if (!file_exists($sMySQLCommand)) {
throw new BackupException("$sCmd not found in $sMySQLBinDir");
}
}
return $sMysqldumpCommand;
return $sMySQLCommand;
}
}