mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02: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)
|
public function CreateCompressedBackup($sTargetFile, $sSourceConfigFile = null)
|
||||||
{
|
{
|
||||||
$bReadonlyBefore = SetupUtils::EnterReadOnlyMode(MetaModel::GetConfig());
|
//safe zone for db backup => cron is stopped/ itop in readonly
|
||||||
try {
|
$bIsCmdbSourceInitialized = CMDBSource::GetMysqli() instanceof mysqli;
|
||||||
//safe zone for db backup => cron is stopped/ itop in readonly
|
if (!$bIsCmdbSourceInitialized) {
|
||||||
$bIsCmdbSourceInitialized = CMDBSource::GetMysqli() instanceof mysqli;
|
$sErrorMsg = 'Cannot backup : CMDBSource not initialized !';
|
||||||
if (!$bIsCmdbSourceInitialized) {
|
$this->LogError($sErrorMsg);
|
||||||
$sErrorMsg = 'Cannot backup : CMDBSource not initialized !';
|
throw new CoreException($sErrorMsg);
|
||||||
$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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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