From 073b1cd30323d5aaec293ad9e05168f11b9e1914 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Tue, 16 Jul 2019 15:26:36 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02018=20Backup=20:=20fix=20version=20chec?= =?UTF-8?q?k=20for=20MySQL8=20Now=20uses=20\CMDBSource::GetDBVersion=20ins?= =?UTF-8?q?tead=20of=20mysqldump=20-V?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup/applicationinstaller.class.inc.php | 2 ++ setup/backup.class.inc.php | 43 +++++++----------------- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/setup/applicationinstaller.class.inc.php b/setup/applicationinstaller.class.inc.php index 254ebfc4c..5eca6eb8b 100644 --- a/setup/applicationinstaller.class.inc.php +++ b/setup/applicationinstaller.class.inc.php @@ -447,6 +447,8 @@ class ApplicationInstaller { $oBackup->SetMySQLBinDir($sMySQLBinDir); } + + CMDBSource::InitFromConfig($oConfig); $oBackup->CreateCompressedBackup($sTargetFile, $sSourceConfigFile); } diff --git a/setup/backup.class.inc.php b/setup/backup.class.inc.php index 457829e12..de4ddd952 100644 --- a/setup/backup.class.inc.php +++ b/setup/backup.class.inc.php @@ -302,11 +302,20 @@ if (class_exists('ZipArchive')) // The setup must be able to start even if the " * @param string $sTargetFile Path and name, without the extension * @param string|null $sSourceConfigFile Configuration file to embed into the backup, if not the current one * + * @throws \CoreException if CMDBSource not initialized * @throws \BackupException if archive cannot be created * @throws \Exception */ public function CreateCompressedBackup($sTargetFile, $sSourceConfigFile = null) { + $bIsCmdbSourceInitialized = CMDBSource::GetMysqli() instanceof mysqli; + if (!$bIsCmdbSourceInitialized) + { + $sErrorMsg = 'Cannot backup : CMDBSource not initialized !'; + $this->LogError($sErrorMsg); + throw new CoreException($sErrorMsg); + } + $this->LogInfo("Creating backup: '$sTargetFile.tar.gz'"); $oArchive = new ITopArchiveTar($sTargetFile.'.tar.gz'); @@ -435,10 +444,9 @@ if (class_exists('ZipArchive')) // The setup must be able to start even if the " $sPortOption = self::GetMysqliCliSingleOption('port', $this->iDBPort); $sTlsOptions = self::GetMysqlCliTlsOptions($this->oConfig); - $sMysqldumpVersion = self::GetMysqldumpVersion($sMySQLDump); - $bIsMysqldumpSupportUtf8mb4 = (version_compare($sMysqldumpVersion, - self::MYSQL_VERSION_WITH_UTF8MB4_IN_PROGRAMS) == -1); - $sMysqldumpCharset = $bIsMysqldumpSupportUtf8mb4 ? 'utf8' : DEFAULT_CHARACTER_SET; + $sMysqlVersion = CMDBSource::GetDBVersion(); + $bIsMysqlSupportUtf8mb4 = (version_compare($sMysqlVersion, self::MYSQL_VERSION_WITH_UTF8MB4_IN_PROGRAMS) === -1); + $sMysqldumpCharset = $bIsMysqlSupportUtf8mb4 ? 'utf8' : DEFAULT_CHARACTER_SET; // Delete the file created by tempnam() so that the spawned process can write into it (Windows/IIS) @unlink($sBackupFileName); @@ -714,33 +722,6 @@ EOF; return $sMysqldumpCommand; } - - /** - * @param string $sMysqldumpCommand - * - * @return string version of the mysqldump program, as parsed from program return - * - * @uses mysqldump -V Sample return value : mysqldump Ver 10.13 Distrib 5.7.19, for Win64 (x86_64) - * @since 2.5 needed to check compatibility with utf8mb4 (N°1001) - * @throws \BackupException - */ - private static function GetMysqldumpVersion($sMysqldumpCommand) - { - $sCommand = $sMysqldumpCommand.' -V'; - $aOutput = array(); - exec($sCommand, $aOutput, $iRetCode); - - if ($iRetCode != 0) - { - throw new BackupException("mysqldump could not be executed (retcode=$iRetCode): Please make sure it is installed and located at : $sMysqldumpCommand"); - } - - $sMysqldumpOutput = $aOutput[0]; - $aDumpVersionMatchResults = array(); - preg_match('/Distrib (\d+\.\d+\.\d+)/', $sMysqldumpOutput, $aDumpVersionMatchResults); - - return $aDumpVersionMatchResults[1]; - } } }