3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2016 Kern Sibbald
8 * The main author of Baculum is Marcin Haba.
9 * The original author of Bacula is Kern Sibbald, with contributions
10 * from many others, a complete list can be found in the file AUTHORS.
12 * You may use this file and others of this release according to the
13 * license defined in the LICENSE file, which includes the Affero General
14 * Public License, v3.0 ("AGPLv3") and some additional permissions and
15 * terms pursuant to its AGPLv3 Section 7.
17 * This notice must be preserved when any source code is
18 * conveyed and/or propagated.
20 * Bacula(R) is a registered trademark of Kern Sibbald.
23 class RestoreRun extends BaculumAPI {
25 public function get() {}
27 public function create($params) {
28 $rfile = property_exists($params, 'rpath') ? $params->rpath : null;
29 $clientid = property_exists($params, 'clientid') ? intval($params->clientid) : null;
30 $fileset = property_exists($params, 'fileset') ? $params->fileset : null;
31 $priority = property_exists($params, 'priority') ? intval($params->priority) : null;
32 $where = property_exists($params, 'where') ? $params->where : null;
33 $replace = property_exists($params, 'replace') ? $params->replace : null;
35 $client = $this->getModule('client')->getClientById($clientid);
36 $misc = $this->getModule('misc');
38 if(!is_null($fileset)) {
39 if(!is_null($client)) {
40 if(preg_match($misc::RPATH_PATTERN, $rfile) === 1) {
41 if(!is_null($where)) {
42 if(!is_null($replace)) {
43 $restore = $this->getModule('bconsole')->bconsoleCommand($this->director, array('restore', 'file="?' . $rfile . '"', 'client="' . $client->name . '"', 'where="' . $where . '"', 'replace="' . $replace . '"', 'fileset="' . $fileset . '"', 'priority="' . $priority . '"', 'yes'), $this->user);
44 $this->removeTmpRestoreTable($rfile);
45 $this->output = $restore->output;
46 $this->error = (integer)$restore->exitcode;
48 $this->output = JobError::MSG_ERROR_INVALID_REPLACE_OPTION;
49 $this->error = JobError::ERROR_INVALID_REPLACE_OPTION;
52 $this->output = JobError::MSG_ERROR_INVALID_WHERE_OPTION;
53 $this->error = JobError::ERROR_INVALID_WHERE_OPTION;
56 $this->output = JobError::MSG_ERROR_INVALID_RPATH;
57 $this->error = JobError::ERROR_INVALID_RPATH;
60 $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS;
61 $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS;
64 $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS;
65 $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
69 private function removeTmpRestoreTable($tableName) {
70 $misc = $this->getModule('misc');
71 if (preg_match($misc::RPATH_PATTERN, $tableName) === 1) {
72 $db = new ActiveRecord();
73 $connection = $db->getDbConnection();
74 $connection->setActive(true);
75 $sql = "DROP TABLE $tableName";
76 $pdo = $connection->getPdoInstance();