mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°6889 backup mysqldump call : restore possibility to connect using socket protocol (#591)
With previous fix (N°6123) we forced to use the tcp protocol each time. This was blocking for users wanting to connect using the socket protocol on localhost. Now for localhost we will : - send both port and protocol arguments if the `db_host` config parameter does contain a port - don't send any of the port or protocol arguments if `db_host` doesn't contain a port
This commit is contained in:
@@ -305,9 +305,8 @@ class DBBackup
|
||||
// Store the results in a temporary file
|
||||
$sTmpFileName = self::EscapeShellArg($sBackupFileName);
|
||||
|
||||
$sPortOption = self::GetMysqliCliSingleOption('port', $this->iDBPort);
|
||||
$sPortAndTransportOptions = self::GetMysqlCliPortAndTransportOptions($this->sDBHost, $this->iDBPort);
|
||||
$sTlsOptions = self::GetMysqlCliTlsOptions($this->oConfig);
|
||||
$sProtocolOption = self::GetMysqlCliTransportOption($this->sDBHost);
|
||||
|
||||
$sMysqlVersion = CMDBSource::GetDBVersion();
|
||||
$bIsMysqlSupportUtf8mb4 = (version_compare($sMysqlVersion, self::MYSQL_VERSION_WITH_UTF8MB4_IN_PROGRAMS) === -1);
|
||||
@@ -326,10 +325,10 @@ EOF;
|
||||
chmod($sMySQLDumpCnfFile, 0600);
|
||||
file_put_contents($sMySQLDumpCnfFile, $sMySQLDumpCnf, LOCK_EX);
|
||||
|
||||
// Note: opt implicitely sets lock-tables... which cancels the benefit of single-transaction!
|
||||
// Note: opt implicitly sets lock-tables... which cancels the benefit of single-transaction!
|
||||
// skip-lock-tables compensates and allows for writes during a backup
|
||||
$sCommand = "$sMySQLDump --defaults-extra-file=\"$sMySQLDumpCnfFile\" --opt --skip-lock-tables --default-character-set=".$sMysqldumpCharset." --add-drop-database --single-transaction --host=$sHost $sPortOption $sProtocolOption --user=$sUser $sTlsOptions --result-file=$sTmpFileName $sDBName $sTables 2>&1";
|
||||
$sCommandDisplay = "$sMySQLDump --defaults-extra-file=\"$sMySQLDumpCnfFile\" --opt --skip-lock-tables --default-character-set=".$sMysqldumpCharset." --add-drop-database --single-transaction --host=$sHost $sPortOption $sProtocolOption --user=xxxxx $sTlsOptions --result-file=$sTmpFileName $sDBName $sTables";
|
||||
$sCommand = "$sMySQLDump --defaults-extra-file=\"$sMySQLDumpCnfFile\" --opt --skip-lock-tables --default-character-set=" . $sMysqldumpCharset . " --add-drop-database --single-transaction --host=$sHost $sPortAndTransportOptions --user=$sUser $sTlsOptions --result-file=$sTmpFileName $sDBName $sTables 2>&1";
|
||||
$sCommandDisplay = "$sMySQLDump --defaults-extra-file=\"$sMySQLDumpCnfFile\" --opt --skip-lock-tables --default-character-set=" . $sMysqldumpCharset . " --add-drop-database --single-transaction --host=$sHost $sPortAndTransportOptions --user=xxxxx $sTlsOptions --result-file=$sTmpFileName $sDBName $sTables";
|
||||
|
||||
// Now run the command for real
|
||||
$this->LogInfo("backup: generate data file with command: $sCommandDisplay");
|
||||
@@ -523,25 +522,37 @@ EOF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define if we should force a transport option
|
||||
*
|
||||
* @param string $sHost
|
||||
* @return string CLI options for port and protocol
|
||||
*
|
||||
* @return string .
|
||||
|
||||
* @since 2.7.9 3.0.4 3.1.1 N°6123
|
||||
* @since 2.7.9 3.0.4 3.1.1 N°6123 method creation
|
||||
* @since 2.7.10 3.0.4 3.1.2 3.2.0 N°6889 rename method to return both port and transport options. Keep default socket connexion if we are on localhost with no port
|
||||
*
|
||||
* @link https://bugs.mysql.com/bug.php?id=55796 MySQL CLI tools will ignore `--port` option on localhost
|
||||
* @link https://jira.mariadb.org/browse/MDEV-14974 Since 10.6.1 the MariaDB CLI tools will use the `--port` option on host=localhost
|
||||
*/
|
||||
public static function GetMysqlCliTransportOption(string $sHost)
|
||||
private static function GetMysqlCliPortAndTransportOptions(string $sHost, ?int $iPort): string
|
||||
{
|
||||
$sTransportOptions = '';
|
||||
|
||||
/** N°6123 As we're using a --port option, if we use localhost as host,
|
||||
* MariaDB > 10.6 will implicitly change its protocol from socket to tcp and throw a warning **/
|
||||
if($sHost === 'localhost'){
|
||||
$sTransportOptions = '--protocol=tcp';
|
||||
if (strtolower($sHost) === 'localhost') {
|
||||
/**
|
||||
* Since MariaDB 10.6.1 if we have host=localhost, and only the --port option we will get a warning
|
||||
* To avoid this warning if we want to set --port option we must set --protocol=tcp
|
||||
**/
|
||||
if (is_null($iPort)) {
|
||||
// no port specified => no option to return, this will mean using socket protocol (unix socket)
|
||||
return '';
|
||||
}
|
||||
|
||||
$sPortOption = self::GetMysqliCliSingleOption('port', $iPort);
|
||||
$sTransportOptions = ' --protocol=tcp';
|
||||
return $sPortOption . $sTransportOptions;
|
||||
}
|
||||
|
||||
return $sTransportOptions;
|
||||
if (is_null($iPort)) {
|
||||
$iPort = CMDBSource::MYSQL_DEFAULT_PORT;
|
||||
}
|
||||
$sPortOption = self::GetMysqliCliSingleOption('port', $iPort);
|
||||
|
||||
return $sPortOption;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user