3 * Bacula® - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2014 Marcin Haba
8 * The main author of Baculum is Marcin Haba.
9 * The main author of Bacula is Kern Sibbald, with contributions from many
10 * 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 * Bacula® is a registered trademark of Kern Sibbald.
20 class JobRun extends BaculumAPI {
22 public function get() {}
24 public function create($params) {
25 $jobid = property_exists($params, 'id') ? intval($params->id) : 0;
26 $job = $jobid > 0 ? $this->getModule('job')->getJobById($jobid)->name : (property_exists($params, 'name') ? $params->name : null);
27 $level = $params->level;
28 $fileset = property_exists($params, 'fileset') ? $params->fileset : null;
29 $clientid = property_exists($params, 'clientid') ? intval($params->clientid) : null;
30 $client = $this->getModule('client')->getClientById($clientid);
31 $storageid = property_exists($params, 'storageid') ? intval($params->storageid) : null;
32 $storage = $this->getModule('storage')->getStorageById($storageid);
33 $poolid = property_exists($params, 'poolid') ? intval($params->poolid) : null;
34 $pool = $this->getModule('pool')->getPoolById($poolid);
35 $priority = property_exists($params, 'priority') ? intval($params->priority) : 10; // default priority is set to 10
38 $isValidLevel = $this->getModule('misc')->isValidJobLevel($params->level);
39 if($isValidLevel === true) {
40 if(!is_null($fileset)) {
41 if(!is_null($client)) {
42 if(!is_null($storage)) {
44 $joblevels = $this->getModule('misc')->getJobLevels();
45 $run = $this->getModule('bconsole')->bconsoleCommand($this->director, array('run', 'job="' . $job . '"', 'level="' . $joblevels[$level] . '"', 'fileset="' . $fileset . '"', 'client="' . $client->name . '"', 'storage="' . $storage->name . '"', 'pool="' . $pool->name . '"' , 'priority="' . $priority . '"', 'yes'));
46 $this->output = $run->output;
47 $this->error = (integer)$run->exitcode;
49 $this->output = JobError::MSG_ERROR_POOLID_DOES_NOT_EXISTS;
50 $this->error = JobError::ERROR_POOLID_DOES_NOT_EXISTS;
53 $this->output = JobError::MSG_ERROR_STORAGEID_DOES_NOT_EXISTS;
54 $this->error = JobError::ERROR_STORAGEID_DOES_NOT_EXISTS;
57 $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS;
58 $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS;
61 $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS;
62 $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
65 $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL;
66 $this->error = JobError::ERROR_INVALID_JOBLEVEL;
69 $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
70 $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;