* Bacula(R) - The Network Backup Solution
* Baculum - Bacula web interface
*
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
*
* The main author of Baculum is Marcin Haba.
* The original author of Bacula is Kern Sibbald, with contributions
}
}
}
+
+ /**
+ * Get volumes for specific jobid and fileid.
+ *
+ * @param integer $jobid job identifier
+ * @param integer $fileid file identifier
+ * @return array volumes list
+ */
+ public function getVolumesForJob($jobid, $fileid) {
+ $connection = VolumeRecord::finder()->getDbConnection();
+ $connection->setActive(true);
+ $sql = sprintf('SELECT first_index, last_index, VolumeName AS volname, InChanger AS inchanger FROM (
+ SELECT VolumeName, InChanger, MIN(FirstIndex) as first_index, MAX(LastIndex) as last_index
+ FROM JobMedia JOIN Media ON (JobMedia.MediaId = Media.MediaId)
+ WHERE JobId = %d GROUP BY (VolumeName, InChanger)
+ ) AS gv, File
+ WHERE FileIndex >= first_index
+ AND FileIndex <= last_index
+ AND File.FileId = %d', $jobid, $fileid);
+ $pdo = $connection->getPdoInstance();
+ $result = $pdo->query($sql);
+ $ret = $result->fetchAll();
+ $pdo = null;
+ $volumes = array();
+ if (is_array($ret)) {
+ for ($i = 0; $i < count($ret); $i++) {
+ $volumes[] = array(
+ 'first_index' => $ret[$i]['first_index'],
+ 'last_index' => $ret[$i]['last_index'],
+ 'volume' => $ret[$i]['volname'],
+ 'inchanger' => $ret[$i]['inchanger']
+ );
+ }
+ }
+ return $volumes;
+ }
}
?>
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2017 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+class VolumesRequired extends BaculumAPIServer {
+
+ public function get() {
+ $jobid = $this->Request->contains('jobid') ? intval($this->Request['jobid']) : 0;
+ $fileid = $this->Request->contains('fileid') ? intval($this->Request['fileid']) : 0;
+ $volumes = $this->getModule('volume')->getVolumesForJob($jobid, $fileid);
+ $this->output = $volumes;
+ $this->error = VolumeError::ERROR_NO_ERRORS;
+ }
+}
+?>
<url ServiceParameter="API.Volume" pattern="api/volumes/{id}/" parameters.id="\d+" />
<url ServiceParameter="API.VolumePrune" pattern="api/volumes/prune/{id}/" parameters.id="\d+" />
<url ServiceParameter="API.VolumePurge" pattern="api/volumes/purge/{id}/" parameters.id="\d+" />
+ <url ServiceParameter="API.VolumesRequired" pattern="api/volumes/required/{jobid}/{fileid}/" parameters.jobid="\d+" parameters.fileid="\d+" />
<url ServiceParameter="API.JobsOnVolume" pattern="api/volumes/jobs/{id}/" parameters.id="\d+" />
<!-- pools endpoints -->
<url ServiceParameter="API.Pools" pattern="api/pools/" />