N°4225 - Remove Read-only mode for backup

This commit is contained in:
Eric Espie
2021-09-09 14:25:19 +02:00
parent ed6969be2c
commit a4e43d3f17

View File

@@ -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);
}
/**