From a4e43d3f1717130c9555b45322794fed8cfdb91c Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Thu, 9 Sep 2021 14:25:19 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B04225=20-=20Remove=20Read-only=20mode=20f?= =?UTF-8?q?or=20backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup/backup.class.inc.php | 60 ++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/setup/backup.class.inc.php b/setup/backup.class.inc.php index 060847d1d..ac1328140 100644 --- a/setup/backup.class.inc.php +++ b/setup/backup.class.inc.php @@ -172,42 +172,32 @@ class DBBackup */ public function CreateCompressedBackup($sTargetFile, $sSourceConfigFile = null) { - $bReadonlyBefore = SetupUtils::EnterReadOnlyMode(MetaModel::GetConfig()); - try { - //safe zone for db backup => cron is stopped/ itop in readonly - $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'); - - $sTmpFolder = APPROOT.'data/tmp-backup-'.rand(10000, getrandmax()); - $aFiles = $this->PrepareFilesToBackup($sSourceConfigFile, $sTmpFolder); - - $sFilesList = var_export($aFiles, true); - $this->LogInfo("backup: adding to archive files '$sFilesList'"); - $bArchiveCreationResult = $oArchive->createModify($aFiles, '', $sTmpFolder); - if (!$bArchiveCreationResult) { - $sErrorMsg = 'Cannot backup : unable to create archive'; - $this->LogError($sErrorMsg); - throw new BackupException($sErrorMsg); - } - - $this->LogInfo("backup: removing tmp folder '$sTmpFolder'"); - SetupUtils::rrmdir($sTmpFolder); - } finally { - if (! $bReadonlyBefore) { - SetupUtils::ExitReadOnlyMode(); - } else { - //we are in the scope of main process that needs to handle/keep readonly mode (setup for example). - $this->LogInfo("Keep readonly mode after backup"); - } + //safe zone for db backup => cron is stopped/ itop in readonly + $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'); + + $sTmpFolder = APPROOT.'data/tmp-backup-'.rand(10000, getrandmax()); + $aFiles = $this->PrepareFilesToBackup($sSourceConfigFile, $sTmpFolder); + + $sFilesList = var_export($aFiles, true); + $this->LogInfo("backup: adding to archive files '$sFilesList'"); + $bArchiveCreationResult = $oArchive->createModify($aFiles, '', $sTmpFolder); + if (!$bArchiveCreationResult) { + $sErrorMsg = 'Cannot backup : unable to create archive'; + $this->LogError($sErrorMsg); + throw new BackupException($sErrorMsg); + } + + $this->LogInfo("backup: removing tmp folder '$sTmpFolder'"); + SetupUtils::rrmdir($sTmpFolder); } /**