Esempio n. 1
0
 protected function execute($arguments = array(), $options = array())
 {
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', $options['env'], true));
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     $apli = new Appliance();
     $serial = $apli->get_serial_number();
     $this->log('[INFO] Appliance backup...' . "\n");
     if ($serial) {
         $result = $apli->backup(true);
         if (!$result['success']) {
             if ($result['action'] == Appliance::LOGIN_BACKUP) {
                 $result['txt'] = 'Could not login!';
             }
             if ($result['action'] == Appliance::DB_BACKUP) {
                 $result['txt'] = 'DB backup error...';
             }
             if ($result['action'] == Appliance::MA_BACKUP) {
                 $result['txt'] = 'MA backup error...';
             }
             $reason = $result['info'];
             if ($result['txt']) {
                 $reason = $result['txt'];
             }
             $message = 'The backup failed, reason: ' . $reason;
             $context->getEventDispatcher()->notify(new sfEvent($this->name, 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
             $this->log('[ERR] ' . $message . "\n");
         } else {
             $message = 'The backup process run with success.';
             $context->getEventDispatcher()->notify(new sfEvent($this->name, 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::INFO)));
             $this->log('[INFO] ' . $message . "\n");
         }
     } else {
         $this->log('[INFO] Could not be possible to do the backup because the appliance is not registered!' . "\n");
     }
 }
Esempio n. 2
0
 public function executeJsonBackup(sfWebRequest $request)
 {
     $apli = new Appliance();
     $serial = $apli->get_serial_number();
     if (!$serial) {
         $msg = 'Need to register first!';
         $result = array('success' => false, 'agent' => 'MASTERSITE', 'action' => 'need_register', 'info' => $msg, 'error' => $msg);
         $error = $this->setJsonError($result);
         return $this->renderText($error);
     }
     $method = $request->getParameter('method');
     switch ($method) {
         case 'get_backup_progress':
             $action = $apli->getStage(Appliance::BACKUP_STAGE);
             switch ($action) {
                 case Appliance::MA_BACKUP:
                     $m_agent = $apli->getStage($action);
                     $cache = new apc_CACHE($serial);
                     $partial_download = $cache->get(cURL::PROGRESS_DOWNLOAD_NOW);
                     $result = array('success' => true, 'action' => $action, 'ma' => $m_agent, 'down' => $partial_download);
                     break;
                 case Appliance::UPLOAD_BACKUP:
                     $cache = new apc_CACHE($serial);
                     $total_upload = $cache->get(cURL::PROGRESS_UPLOAD_TOTAL);
                     $partial_upload = $cache->get(cURL::PROGRESS_UPLOAD_NOW);
                     $percent = $partial_upload / $total_upload;
                     $result = array('success' => true, 'action' => $action, 'total_up' => $total_upload, 'partial_up' => $partial_upload, 'percent' => $percent);
                     break;
                 case Appliance::DB_BACKUP:
                     $txt = 'Perfoming DB backup...';
                     $result = array('success' => true, 'txt' => $txt, 'action' => $action);
                     break;
                 case Appliance::ARCHIVE_BACKUP:
                     $txt = 'Creating compressed archive...';
                     $result = array('success' => true, 'txt' => $txt, 'action' => $action);
                     break;
                 default:
                     $result = array('success' => true, 'txt' => $action, 'action' => $action);
             }
             break;
         case 'backup':
             $force = $request->getParameter('force');
             $result = $apli->backup($force);
             if (!$result['success']) {
                 if ($result['action'] == Appliance::LOGIN_BACKUP) {
                     $result['txt'] = 'Could not login!';
                 }
                 if ($result['action'] == Appliance::DB_BACKUP) {
                     $result['txt'] = 'DB backup error...';
                 }
                 if ($result['action'] == Appliance::MA_BACKUP) {
                     $result['txt'] = 'MA backup error...';
                 }
             }
             break;
         default:
             $result = array('success' => true, 'data' => array());
             break;
     }
     if (!$result['success']) {
         $error = $this->setJsonError($result);
         return $this->renderText($error);
     }
     $json_encoded = json_encode($result);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($json_encoded);
 }
Esempio n. 3
0
 public static function getAgentFiles($method)
 {
     $apli = new Appliance();
     switch ($method) {
         case 'get_diagnostic_progress':
             $action = $apli->getStage(Appliance::BACKUP_STAGE);
             error_log("[ACTION] {$action}");
             switch ($action) {
                 case Appliance::DB_BACKUP:
                     $txt = 'Perfoming DB backup...';
                     $result = array('success' => true, 'txt' => $txt, 'action' => $action);
                     break;
                 case Appliance::ARCHIVE_BACKUP:
                     $txt = 'Creating compressed archive...';
                     $result = array('success' => true, 'txt' => $txt, 'action' => $action);
                     break;
                 default:
                     $result = array('success' => true, 'txt' => $action, 'action' => $action);
             }
             break;
         case 'diagnostic':
             #                $force = $request->getParameter('force');
             $result = $apli->backup(true, true);
             // generate tarball with logs
             $filepath = sfConfig::get("app_remote_log_file");
             $scriptfile = sfConfig::get("app_remote_log_script");
             #                putenv("ETVADIAGNOSTIC=symfony");
             $command = "/bin/bash {$scriptfile} {$filepath}";
             $node_list = EtvaNodePeer::doSelect(new Criteria());
             foreach ($node_list as $node) {
                 $name = $node->getName();
                 $ip = $node->getIp();
                 $port = $node->getPort();
                 $command .= " {$name} {$ip} {$port}";
             }
             $command .= ' 2>&1';
             error_log('[COMMAND]' . $command);
             $path = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . "utils";
             error_log("[INFO] PATH TO SUDOEXEC" . $path . DIRECTORY_SEPARATOR);
             ob_start();
             passthru('echo ' . $command . ' | sudo /usr/bin/php -f ' . $path . DIRECTORY_SEPARATOR . 'sudoexec.php', $return);
             #$content_grabbed=ob_get_contents();
             ob_end_clean();
             #$output = shell_exec($command);
             error_log("[INFO] Script diagnostic_ball has exited.");
             error_log("[INFO] " . $return);
             if ($return != 0) {
                 $result['success'] = false;
             } else {
                 $mail_success = diagnostic::sendDiagnosticEmail();
                 if (!$mail_success) {
                     //$str = implode("\n", $mail_success);
                     $result['mail_errors'] = 'email errors';
                 }
             }
             if (!$result['success']) {
                 if ($result['action'] == Appliance::LOGIN_BACKUP) {
                     $result['txt'] = 'Could not login!';
                 }
                 if ($result['action'] == Appliance::DB_BACKUP) {
                     $result['txt'] = 'DB backup error...';
                 }
                 if ($result['action'] == Appliance::MA_BACKUP) {
                     $result['txt'] = 'MA backup error...';
                 }
             }
             break;
         default:
             $result = array('success' => true, 'data' => array());
             break;
     }
     return $result;
 }