Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Restore most recent client backup (full)
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergkemper committed May 29, 2015
1 parent 909d051 commit 3415535
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 12 deletions.
2 changes: 1 addition & 1 deletion module/Application/config/module.config.php
Expand Up @@ -177,11 +177,11 @@
'label' => 'Logs',
'route' => 'log',
),
/*
array(
'label' => 'Restore',
'route' => 'restore',
),
/*
array(
'label' => 'Statistics',
'route' => 'statistics',
Expand Down
27 changes: 25 additions & 2 deletions module/Client/view/client/client/index.phtml
Expand Up @@ -39,7 +39,7 @@ Clients per page:
<th>Autoprune</th>
<th>Fileretention</th>
<th>Jobretention</th>
<!-- <th>Online status</th> -->
<th>Action</th>
</tr>

<?php foreach($this->paginator as $client) : ?>
Expand All @@ -52,7 +52,30 @@ Clients per page:
<td><?php echo $this->escapeHtml($client->autoprune); ?></td>
<td><?php echo $this->printRetention($client->fileretention) . " days"; ?></td>
<td><?php echo $this->printRetention($client->jobretention) . " days"; ?></td>
<!-- <td></td> -->
<td>
<div class="btn-group">
<button type="button" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-cog"></span></button>
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="
<?php
echo $this->url(
'restore',
array('action' => 'index'),
array('query' => array(
'type' => 1,
'client' => $client->name,
'restoreclient' => $client->name
)
));
?>
"><span class="glyphicon glyphicon-import"></span> Restore most recent backup</a></li>
</ul>
</div>
</td>

</tr>

Expand Down
58 changes: 52 additions & 6 deletions module/Restore/src/Restore/Controller/RestoreController.php
Expand Up @@ -49,7 +49,7 @@ public function indexAction()
$this->restore_params,
$this->getJobs("long"),
$this->getClients("long"),
null//$this->getFilesets("long")
$this->getFilesets("long")
);

// Set the method attribute for the form
Expand All @@ -64,14 +64,29 @@ public function indexAction()
$form->setData( $request->getPost() );

if($form->isValid()) {

$job = $form->getInputFilter()->getValue('job');
$client = $form->getInputFilter()->getValue('client');
$restoreclient = $form->getInputFilter()->getValue('restoreclient');
$fileset = $form->getInputFilter()->getValue('fileset');
$before = $form->getInputFilter()->getValue('before');
$where = $form->getInputFilter()->getValue('where');

return $this->redirect()->toRoute('restore', array('action' => 'confirm'));
return $this->redirect()->toRoute(
'restore',
array(
'controller'=>'restore',
'action' => 'queued'
),
array(
'query' => array(
'type' => $this->restore_params['type'],
'client' => $client,
'restoreclient' => $restoreclient,
'fileset' => $fileset,
'where' => $where
)
));
}
else {
return new ViewModel(array(
Expand Down Expand Up @@ -108,7 +123,10 @@ public function confirmAction()
// 3. modify restore job
// 4. cancel restore job

return new ViewModel();
$this->getRestoreParams();

return new ViewModel(
);

}
else {
Expand All @@ -123,11 +141,18 @@ public function queuedAction()
{
if($_SESSION['bareos']['authenticated'] == true) {

// TODO
$this->getRestoreParams();

// 1. display restore job queued
$result = $this->restore(
$this->restore_params['client'],
$this->restore_params['restoreclient'],
$this->restore_params['fileset'],
$this->restore_params['where']
);

return new ViewModel();
return new ViewModel(array(
'result' => $result
));

}
else {
Expand Down Expand Up @@ -174,6 +199,27 @@ private function getRestoreParams()
else {
$this->restore_params['fileset'] = null;
}

if($this->params()->fromQuery('where')) {
$this->restore_params['where'] = $this->params()->fromQuery('where');
}
else {
$this->restore_params['where'] = null;
}
}

/**
*
*/
private function restore($client=null, $restoreclient=null, $fileset=null, $where=null)
{
$director = $this->getServiceLocator()->get('director');

$cmd = "restore client=$client restoreclient=$restoreclient fileset=$fileset where=$where current select all done yes";

$result = $director->send_command($cmd, 0);

return $result;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions module/Restore/src/Restore/Form/RestoreForm.php
Expand Up @@ -194,7 +194,7 @@ public function __construct($restore_params=null, $jobs=null, $clients=null, $fi
'label' => 'Where'
),
'attributes' => array(
'value' => '/tmp/bareos-restore/'
'value' => '/tmp/bareos-restores/'
)
)
);
Expand Down Expand Up @@ -250,10 +250,9 @@ private function getFilesetList()
$selectData = array();
if(!empty($this->filesets)) {
foreach($this->filesets as $fileset) {
$selectData[$fileset['name']] = $fileset['name'];
$selectData[$fileset['fileset']] = $fileset['fileset'];
}
}
$selectData = array('fileset-1'=>'fileset-1');
return $selectData;
}

Expand Down
1 change: 1 addition & 0 deletions module/Restore/view/restore/restore/index.phtml
Expand Up @@ -48,6 +48,7 @@ $this->headTitle($title);
echo $this->formRow($form->get('client')->setAttribute('class','form-control'));
echo $this->formRow($form->get('fileset')->setAttribute('class','form-control'));
echo $this->formRow($form->get('restoreclient')->setAttribute('class','form-control'));
echo $this->formRow($form->get('where')->setAttribute('class','form-control'));
break;
case 2:
break;
Expand Down
42 changes: 42 additions & 0 deletions module/Restore/view/restore/restore/queued.phtml
@@ -0,0 +1,42 @@
<?php

/**
*
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2014 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

$title = 'Restore';
$this->headTitle($title);

?>

<h3 class="text-muted"><?php echo $title; ?></h3>
<hr />

<div class="row">
<div class="col-md-12">
<pre style="font-size: 8pt;">
<code>
<?php echo $this->result; ?>
</code>
</pre>
</div>
</div>

0 comments on commit 3415535

Please sign in to comment.