mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°4225 - Remove Read-only mode for backup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user