protected function execute($arguments = array(), $options = array()) { $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', $options['env'], true)); parent::execute($arguments, $options); // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); // add your code here $options_task_server_backup = array('location' => $arguments['location'], 'filepath' => $arguments['filepath']); if ($arguments['snapshot']) { $options_task_server_backup['snapshot'] = $arguments['snapshot']; } if ($arguments['newsnapshot']) { $options_task_server_backup['newsnapshot'] = $arguments['newsnapshot']; } if ($arguments['delete']) { $options_task_server_backup['deletesnapshot'] = $arguments['delete']; } if ($arguments['location']) { if ($arguments['do_not_generate_tar'] && $arguments['do_not_generate_tar'] != 'false') { $options_task_server_backup['do_not_generate_tar'] = true; } } $task_server_backup = new serverBackupTask($this->dispatcher, new sfFormatter()); return $task_server_backup->run(array('serverid' => $arguments['serverid']), $options_task_server_backup); }
protected function execute($arguments = array(), $options = array()) { // number of workers $n_childs = $options['processes'] - 1; // Start n child $this->startChildren($n_childs); $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', $options['env'], true)); $this->redefineStdOut(); // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); // add your code here // queue of response $this->queueResourceResponse = msg_get_queue(ftok(__FILE__, 'X')); $backup_location = $arguments['location']; if ($this->iAmParent()) { $this->log('[INFO] Get all nodes with VirtAgent activated...' . "\n"); $query = EtvaServerQuery::create(); // filter servers if ($options['filter']) { $fil_arr = explode(',', $options['filter']); foreach ($fil_arr as $sname) { $query->addOr(EtvaServerPeer::NAME, $sname, Criteria::EQUAL); } } // exclude servers if ($options['exclude']) { $exc_arr = explode(',', $options['exclude']); foreach ($exc_arr as $sname) { $query->addAnd(EtvaServerPeer::NAME, $sname, Criteria::NOT_EQUAL); } } $all_servers = $query->find(); foreach ($all_servers as $server) { // add server to queue to process backup $this->addToQueue($server); } // Wait until queue is consume $this->waitForEmptyQueue(); } else { $msgtype_send = 1; // Child process while ($server = $this->getFromQueue()) { $task_server_backup = new serverBackupTask($this->dispatcher, new sfFormatter()); $res = $task_server_backup->run(array('serverid' => $server->getId()), array('location' => $backup_location, 'shutdown' => 'true', 'do_not_generate_tar' => 'true', 'delete_backups_n_days' => 2)); $error = $task_server_backup->getLastError(); $message = $task_server_backup->getReport(); /*$res = 0; $message = "[INFO] Backup ".$server->getName()." VM successfully.\n"; $error = array('message'=>$message); $this->log($message);*/ // send report to the parent $msgObj = array('return' => $res, 'message' => $message, 'error' => $error, 'server' => $server); msg_send($this->queueResourceResponse, $msgtype_send, $msgObj); } } }
/** * * * Download server backup from snapshot * * request object is like this; * <code> * $request['id'] = $id; //server ID * $request['snapshot'] = $snapshot; //using snapshot * </code> * * @param sfWebRequest $request A request object * * donwload machine in OVF format * */ public function executeDownloadBackupSnapshot(sfWebRequest $request) { if ($sid = $request->getParameter('uuid')) { $etva_server = EtvaServerPeer::retrieveByUuid($sid); } else { if ($sid = $request->getParameter('name')) { $etva_server = EtvaServerPeer::retrieveByName($sid); } else { $sid = $request->getParameter('id'); $etva_server = EtvaServerPeer::retrieveByPK($sid); } } /*if(!$etva_server){ $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_,array('%id%'=>$sid)); return $this->renderText($msg_i18n); } $newsnapshot = $request->getParameter('newsnapshot'); $snapshot = $request->getParameter('snapshot'); $delete = $request->getParameter('delete'); if(!$etva_server->getHasSnapshots() && !$snapshot && !$newsnapshot && ($etva_server->getVmState() != 'stop') && ($etva_server->getVmState() != 'notrunning') ){ $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_,array('%id%'=>$sid)); return $this->renderText($msg_i18n); } $etva_node = $etva_server->getEtvaNode(); $server_va = new EtvaServer_VA($etva_server); if( !$etva_server->getHasSnapshots() || $newsnapshot ){ $response = $server_va->create_snapshot($etva_node,$newsnapshot); if( !$response['success'] ){ $msg_i18n = $response['info']; return $this->renderText($msg_i18n); } } $url = "http://".$etva_node->getIp(); $request_body = "uuid=".$etva_server->getUuid(); if( $snapshot ){ $request_body .= "&snapshot=$snapshot"; } $filename = $etva_server->getName().".tar"; $port = $etva_node->getPort(); if($port) $url.=":".$port; $url.="/vm_backup_snapshot_may_fork";*/ /* * get response stream data */ /*$ovf_curl = new ovfcURL($url); $ovf_curl->post($request_body); $ovf_curl->setFilename($filename); $ovf_curl->exec(); if($ovf_curl->getStatus()==500) return $this->renderText('Error 500');*/ $options_task_server_backup = array('filepath' => 'STDOUT'); $snapshot = $request->getParameter('snapshot'); if ($snapshot) { $options_task_server_backup['snapshot'] = $snapshot; } $newsnapshot = $request->getParameter('newsnapshot'); if ($newsnapshot) { $options_task_server_backup['newsnapshot'] = $newsnapshot; } $delete = $request->getParameter('delete'); if ($delete && $delete != 'false') { // delete after $options_task_server_backup['deletesnapshot'] = true; } $task_server_backup = new serverBackupTask($this->dispatcher, new sfFormatter()); $res_task = $task_server_backup->run(array('serverid' => $sid), $options_task_server_backup); if ($res_task < 0) { // TODO treat error return $this->renderText('Error 500'); } return sfView::NONE; }