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}";
 }
Beispiel #2
0
 //
 $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');
 $oP->p(Dict::Format('bkp-week-days', $sDays, $sBackupTime));
 $iRetention = MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'retention_count', 5);
 $oP->p(Dict::Format('bkp-retention', $iRetention));
 $oP->add("</fieldset>");
 // List of backups
 //
 $aFiles = $oBackup->ListFiles($sBackupDirAuto);
 $aFilesToDelete = array();
 while (count($aFiles) > $iRetention - 1) {
     $aFilesToDelete[] = array_shift($aFiles);
 }
 $oRestoreMutex = new iTopMutex('restore.' . utils::GetCurrentEnvironment());
 if ($oRestoreMutex->TryLock()) {
     $oRestoreMutex->Unlock();
     $sDisableRestore = '';
 } else {
     $sDisableRestore = 'disabled="disabled"';
 }
 // 1st table: list the backups made in the background
 //
 $aDetails = array();
 foreach ($oBackup->ListFiles($sBackupDirAuto) as $sBackupFile) {