public function Process($iUnixTimeLimit) { $oMutex = new iTopMutex('backup.' . utils::GetCurrentEnvironment()); $oMutex->Lock(); try { // Make sure the target directory exists SetupUtils::builddir($this->sBackupDir); $oBackup = new DBBackupScheduled(); // Eliminate files exceeding the retention setting // if ($this->iRetentionCount > 0) { $aFiles = $oBackup->ListFiles($this->sBackupDir); while (count($aFiles) >= $this->iRetentionCount) { $sFileToDelete = array_shift($aFiles); unlink($sFileToDelete); if (file_exists($sFileToDelete)) { // Ok, do not loop indefinitely on this break; } } } // Do execute the backup // $oBackup->SetMySQLBinDir(MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', '')); $sBackupFile = MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'file_name_format', '__DB__-%Y-%m-%d_%H_%M'); $sName = $oBackup->MakeName($sBackupFile); if ($sName == '') { $sName = $oBackup->MakeName(BACKUP_DEFAULT_FORMAT); } $sZipFile = $this->sBackupDir . $sName . '.zip'; $sSourceConfigFile = APPCONF . utils::GetCurrentEnvironment() . '/' . ITOP_CONFIG_FILE; $oBackup->CreateZip($sZipFile, $sSourceConfigFile); } catch (Exception $e) { $oMutex->Unlock(); throw $e; } $oMutex->Unlock(); return "Created the backup: {$sZipFile}"; }
$oP->p($sImgError . Dict::Format('bkp-missing-dir', $sBackupDir)); } else { $oP->p(Dict::Format('bkp-free-disk-space', SetupUtils::HumanReadableSize(SetupUtils::CheckDiskSpace($sBackupDir)), $sBackupDir)); if (!is_writable($sBackupDir)) { $oP->p($sImgError . Dict::Format('bkp-dir-not-writeable', $sBackupDir)); } } $sBackupDirAuto = $sBackupDir . 'auto/'; SetupUtils::builddir($sBackupDirAuto); $sBackupDirManual = $sBackupDir . 'manual/'; SetupUtils::builddir($sBackupDirManual); // Wrong format // $sBackupFile = MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'file_name_format', BACKUP_DEFAULT_FORMAT); $oBackup = new DBBackupScheduled(); $sZipName = $oBackup->MakeName($sBackupFile); if ($sZipName == '') { $oP->p($sImgError . Dict::Format('bkp-wrong-format-spec', $sBackupFile, BACKUP_DEFAULT_FORMAT)); } else { $oP->p(Dict::Format('bkp-name-sample', $sZipName)); } // Week Days // $aWeekDayToString = array(1 => Dict::S('DayOfWeek-Monday'), 2 => Dict::S('DayOfWeek-Tuesday'), 3 => Dict::S('DayOfWeek-Wednesday'), 4 => Dict::S('DayOfWeek-Thursday'), 5 => Dict::S('DayOfWeek-Friday'), 6 => Dict::S('DayOfWeek-Saturday'), 7 => Dict::S('DayOfWeek-Sunday')); $aDayLabels = array(); $oBackupExec = new BackupExec(); foreach ($oBackupExec->InterpretWeekDays() as $iDay) { $aDayLabels[] = $aWeekDayToString[$iDay]; } $sDays = implode(', ', $aDayLabels); $sBackupTime = MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'time', '23:30');