Пример #1
0
 public function restore($backup_id)
 {
     //clear stage cache
     $this->delStage(self::RESTORE_STAGE);
     chdir(sfConfig::get('sf_root_dir'));
     /*
      * TELL VA to reset stuff
      */
     $node_list = EtvaNodePeer::doSelect(new Criteria());
     $node_num = count($node_list);
     if ($node_num != 1) {
         /*
          * ERROR should be only one element (standard ETVA release only)
          */
         $msg = "Sould only be one Virtualization Agent! {$node_num} found!";
         $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'info' => $msg, 'error' => $msg);
         return $data;
     }
     $node = $node_list[0];
     /*
      * check node state ok to comm with agent
      */
     if (!$node->getState()) {
         $node_name = $node->getName();
         $msg = sfContext::getInstance()->getI18N()->__(EtvaNodePeer::_STATE_DOWN_, array('%name%' => $node_name));
         $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'action' => 'check_nodes', 'info' => $msg, 'error' => $msg);
         return $data;
     }
     $this->disable();
     /*
      *
      * FIRST THING....CLEANUP DESTINATION FOLDER AND GET RESTORE ARCHIVE
      *
      */
     IOFile::unlinkRecursive($this->archive_base_dir, false);
     $full_path = $this->archive_base_dir . '/' . self::ARCHIVE_FILE;
     $this->setStage(self::RESTORE_STAGE, self::GET_RESTORE);
     $response = $this->getApplianceBackup($backup_id, $full_path);
     /*
      *
      * DECOMPRESS BACKUP ARCHIVE
      *
      */
     $this->setStage(self::RESTORE_STAGE, self::ARCHIVE_RESTORE);
     $create_gz = new gzip_file($full_path);
     $base_dir = $this->archive_base_dir;
     $create_gz->set_options(array('basedir' => $base_dir, 'overwrite' => 1));
     $create_gz->extract_files();
     /*
      * get DB file and put in tmp_db_filename
      */
     $db_filename = $base_dir . '/' . self::DB_FILE;
     if (!file_exists($db_filename)) {
         return array('success' => false, 'error' => 'no file');
     }
     // move DB backup to correct folder...
     rename($db_filename, $this->tmp_db_filename);
     /*
      *
      * CLEAN DB ????
      *
      */
     /*
      * delete tables and build again....
      */
     $command = "symfony propel:insert-sql --no-confirmation";
     $path = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . "utils";
     ob_start();
     passthru('echo ' . $command . ' | sudo /usr/bin/php -f ' . $path . DIRECTORY_SEPARATOR . 'sudoexec.php', $return);
     $result = ob_get_contents();
     ob_end_clean();
     if ($result != 0 || $return != 0) {
         $msg = 'An error occurred while deleting DB. Aborted!' . $status;
         $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'action' => self::DB_RESTORE, 'info' => $msg, 'error' => $msg);
         return $data;
     }
     /*
      *
      * RESTORE CENTRAL MANAGEMENT BACKUP (DB)
      *
      *
      */
     $this->setStage(self::RESTORE_STAGE, self::DB_RESTORE);
     /*
      * load data to DB
      */
     //sfContext::getInstance()->getStorage()->regenerate(true);
     exec("symfony propel:data-load " . $this->tmp_db_filename, $output, $status);
     if ($status != 0) {
         // aconteceu erro
         $msg = 'An error occurred while generating DB dump. Aborted!' . $status;
         $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'action' => self::DB_RESTORE, 'info' => $msg, 'error' => $msg);
         return $data;
     }
     /*
      * 
      * generate session to stay logged in...
      *
      */
     sfContext::getInstance()->getStorage()->regenerate();
     $this->setStage(self::RESTORE_STAGE, self::VA_RESET);
     $node_va = new EtvaNode_VA($node);
     /*
      * get new uuid from DB
      */
     $backup_node = EtvaNodePeer::doSelectOne(new Criteria());
     $uuid = $backup_node->getUuid();
     $response = $node_va->send_change_uuid($uuid);
     if (!$response['success']) {
         return $response;
     }
     $response = array('success' => true);
     return $response;
 }
Пример #2
0
 public function executeLogDownload($request)
 {
     $filepath = sfConfig::get("app_remote_log_file");
     $response = $this->getResponse();
     $response->clearHttpHeaders();
     $response->setHttpHeader('Content-Length', sprintf("%u", filesize($filepath)));
     $response->setContentType('application/x-download');
     $response->setHttpHeader('Content-Disposition', 'attachment; filename="' . $filepath . '"');
     $response->sendHttpHeaders();
     ob_end_clean();
     $this->getResponse()->setContent(IOFile::readfile_chunked($filepath));
     return sfView::NONE;
 }
Пример #3
0
 public function executeIsoDownload(sfWebRequest $request)
 {
     $directory = sfConfig::get("config_isos_dir");
     $file = $request->getParameter('file');
     $filepath = $directory . "/" . $file;
     if (dirname($filepath) == $directory) {
         if ($directory && $file && is_file($filepath)) {
             $response = $this->getResponse();
             $response->clearHttpHeaders();
             $response->setHttpHeader('Pragma: public', true);
             $response->setHttpHeader('Content-Length', sprintf("%u", filesize($filepath)));
             $response->setContentType('application/x-download');
             $response->setHttpHeader('Content-Disposition', 'attachment; filename="' . $file . '"');
             $response->sendHttpHeaders();
             ob_end_clean();
             $this->getResponse()->setContent(IOFile::readfile_chunked($filepath));
         }
     }
     return sfView::NONE;
 }