mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
N°8379 - fix backup issue
This commit is contained in:
@@ -53,14 +53,7 @@ class DBRestore extends DBBackup
|
|||||||
$sUser = self::EscapeShellArg($this->sDBUser);
|
$sUser = self::EscapeShellArg($this->sDBUser);
|
||||||
$sPwd = self::EscapeShellArg($this->sDBPwd);
|
$sPwd = self::EscapeShellArg($this->sDBPwd);
|
||||||
$sDBName = self::EscapeShellArg($this->sDBName);
|
$sDBName = self::EscapeShellArg($this->sDBName);
|
||||||
if (empty($this->sMySQLBinDir))
|
$sMySQLExe = DBBackup::MakeSafeMySQLCommand($this->sMySQLBinDir, 'mysql');
|
||||||
{
|
|
||||||
$sMySQLExe = 'mysql';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$sMySQLExe = '"'.$this->sMySQLBinDir.'/mysql"';
|
|
||||||
}
|
|
||||||
if (is_null($this->iDBPort))
|
if (is_null($this->iDBPort))
|
||||||
{
|
{
|
||||||
$sPortOption = '';
|
$sPortOption = '';
|
||||||
|
|||||||
@@ -56,15 +56,7 @@ try
|
|||||||
//
|
//
|
||||||
$sMySQLBinDir = MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', '');
|
$sMySQLBinDir = MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', '');
|
||||||
$sMySQLBinDir = utils::ReadParam('mysql_bindir', $sMySQLBinDir, true);
|
$sMySQLBinDir = utils::ReadParam('mysql_bindir', $sMySQLBinDir, true);
|
||||||
if (empty($sMySQLBinDir))
|
$sMySQLDump = DBBackup::MakeSafeMySQLCommand($sMySQLBinDir, 'mysqldump');
|
||||||
{
|
|
||||||
$sMySQLDump = 'mysqldump';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//echo 'Info - Found mysql_bindir: '.$sMySQLBinDir;
|
|
||||||
$sMySQLDump = '"'.$sMySQLBinDir.'/mysqldump"';
|
|
||||||
}
|
|
||||||
$sCommand = "$sMySQLDump -V 2>&1";
|
$sCommand = "$sMySQLDump -V 2>&1";
|
||||||
|
|
||||||
$aOutput = array();
|
$aOutput = array();
|
||||||
|
|||||||
@@ -104,6 +104,8 @@ class DBBackup
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
protected $sDBName;
|
protected $sDBName;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
|
protected $sMySQLBinDir = '';
|
||||||
|
/** @var string */
|
||||||
protected $sDBSubName;
|
protected $sDBSubName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,7 +133,6 @@ class DBBackup
|
|||||||
$this->sDBSubName = $oConfig->get('db_subname');
|
$this->sDBSubName = $oConfig->get('db_subname');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected $sMySQLBinDir = '';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a normalized backup name, depending on the current date/time and Database
|
* 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')");
|
$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
|
// Store the results in a temporary file
|
||||||
$sTmpFileName = self::EscapeShellArg($sBackupFileName);
|
$sTmpFileName = self::EscapeShellArg($sBackupFileName);
|
||||||
@@ -557,20 +559,22 @@ EOF;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string the command to launch mysqldump (without its params)
|
* @return string the command to launch mysqldump (without its params)
|
||||||
|
* @throws \BackupException
|
||||||
*/
|
*/
|
||||||
private function GetMysqldumpCommand()
|
public static function MakeSafeMySQLCommand($sMySQLBinDir, string $sCmd)
|
||||||
{
|
{
|
||||||
$sMySQLBinDir = utils::ReadParam('mysql_bindir', $this->sMySQLBinDir, true);
|
if (empty($sMySQLBinDir)) {
|
||||||
if (empty($sMySQLBinDir))
|
$sMySQLCommand = $sCmd;
|
||||||
{
|
|
||||||
$sMysqldumpCommand = 'mysqldump';
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
$sMySQLBinDir = escapeshellcmd($sMySQLBinDir);
|
||||||
$sMysqldumpCommand = '"'.$sMySQLBinDir.'/mysqldump"';
|
$sMySQLCommand = '"'.$sMySQLBinDir.'/$sCmd"';
|
||||||
|
if (!file_exists($sMySQLCommand)) {
|
||||||
|
throw new BackupException("$sCmd not found in $sMySQLBinDir");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sMysqldumpCommand;
|
return $sMySQLCommand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -484,16 +484,15 @@ class SetupUtils
|
|||||||
{
|
{
|
||||||
$sMySQLBinDir = MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', '');
|
$sMySQLBinDir = MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', '');
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
if (empty($sMySQLBinDir))
|
$sMySQLDump = DBBackup::MakeSafeMySQLCommand($sMySQLBinDir, 'mysqldump');
|
||||||
{
|
} catch (Exception $e) {
|
||||||
$sMySQLDump = 'mysqldump';
|
$aResult[] = new CheckResult(CheckResult::ERROR, $e->getMessage());
|
||||||
}
|
return $aResult;
|
||||||
else
|
|
||||||
{
|
|
||||||
SetupPage::log('Info - Found mysql_bindir: '.$sMySQLBinDir);
|
|
||||||
$sMySQLDump = '"'.$sMySQLBinDir.'/mysqldump"';
|
|
||||||
}
|
}
|
||||||
|
if (!empty($sMySQLBinDir)) {
|
||||||
|
SetupPage::log('Info - Found mysql_bindir: '.$sMySQLBinDir);
|
||||||
|
}
|
||||||
$sCommand = "$sMySQLDump -V 2>&1";
|
$sCommand = "$sMySQLDump -V 2>&1";
|
||||||
|
|
||||||
$aOutput = array();
|
$aOutput = array();
|
||||||
|
|||||||
Reference in New Issue
Block a user