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}"; }
$oDBRS = new DBRestore($sDBHost, $sDBUser, $sDBPwd, $sDBName, $sDBSubName); $oDBRS->SetMySQLBinDir($sMySQLBinDir); $sBackupDir = APPROOT . 'data/backups/'; $sBackupFile = $sBackupDir . $sFile; $sRes = $oDBRS->RestoreFromZip($sBackupFile, $sEnvironment); IssueLog::Info('Backup Restore - Done, releasing the LOCK'); $oRestoreMutex->Unlock(); } catch (Exception $e) { $oRestoreMutex->Unlock(); $oPage->p('Error: ' . $e->getMessage()); } } $oPage->output(); break; case 'download': require_once APPROOT . '/application/startup.inc.php'; require_once APPROOT . '/application/loginwebpage.class.inc.php'; LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin) if (utils::GetConfig()->Get('demo_mode')) { throw new Exception('iTop is in demonstration mode: the feature is disabled'); } $sFile = utils::ReadParam('file', '', false, 'raw_data'); $oBackup = new DBBackupScheduled(); $sBackupDir = APPROOT . 'data/backups/'; $oBackup->DownloadBackup($sBackupDir . $sFile); break; } } catch (Exception $e) { IssueLog::Error($e->getMessage()); }
if (!is_dir($sBackupDir)) { $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);