View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update | 
|---|---|---|---|---|---|
| 0000083 | bareos-core | installer / packages | public | 2013-02-21 11:48 | 2015-03-25 19:19 | 
| Reporter | joergs | Assigned To | |||
| Priority | normal | Severity | minor | Reproducibility | have not tried | 
| Status | closed | Resolution | fixed | ||
| Platform | Linux | OS | any | OS Version | 3 | 
| Product Version | 12.4.1 | ||||
| Summary | 0000083: Bareos packages do not contain query.sql | ||||
| Description | currently, the Bareos packages do not contain a query.sql file. In the past, the sample-query.sql has been included. The file is still referenced in /etc/bareos/bareos-dir.conf How should be continue here? The file src/dird/query.sql has following content: # # See the file <bareos-source>/examples/sample-query.sql # for some sample queries. # # 1 :The default file is empty, see <bareos-source>/examples/sample-query.sql for samples SELECT 'See <bareos-source>/examples/sample-query.sql for samples' AS Info; It references to <bareos-source>/examples/sample-query.sql, but the examples directory does not exist. Proposal: - src/dird/query.sql - add a working example - remove references to examples/sample-query.sql - install query.sql as config file to /etc/bareos/ - add query.sql to bareos-director package @Marco: do you agree with this?  | ||||
| Tags | No tags attached. | ||||
| 
	Yes I removed the examples on purpose as the contained very old stuff which wasn't accurate anymore for the current version. You can add some samples to the existing query.sql but keep in mind that it only can be generic SQL queries that work on any database backend (e.g. currently sqlite3, mysql, postgresql possibly more in the future.)  | 
|
| 
	I suggest the following: We start by checking which queries already work on all databases (at least mysql and postgresql) and add them to the query file. The queries that dont work can be added later.  | 
|
| 
	as I do not use queries, I assign this ticket to Erol. @Erol: please provide some useful queries.  | 
|
| I am through: all queries work well. Only query 17: "List Volumes Bacula thinks are eligible for the changer" might need adjustment. I will have to look deeper into it and report back. | |
| I will be able to check on 21th of May | |
| 
	query 18 is somewhat misleading as it gives the sum of JobBytes - is that useful information? | 000074L5 | 200 | server | 2013-06-03 19:00:05 | 1,442 | 114234516459126 | So we have in Volume 000074L5 around 108 TB  | 
|
| 
	query 18 should be this way (without the sum()) SELECT VolumeName, Job.JobId as JobID, Job.Name as JobName, Job.StartTime as Start, JobFiles AS Files,ROUND(JobBytes/1024.0/1024.0/1024.0,3) AS GB FROM Job,JobMedia,Media WHERE JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId GROUP by VolumeName, Job.JobID, Job.Name, Jobbytes, Jobfiles, Job.StartTime ORDER by VolumeName;  | 
|
| 
	and so with query 19: SELECT Job.Name as JobName, Job.JobId as JobID, VolumeName, Job.StartTime as Start, JobFiles AS Files,ROUND(JobBytes/1024.0/1024.0/1024.0,3) AS GB FROM Job,JobMedia,Media WHERE JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId GROUP by VolumeName, Job.JobID, Job.Name, JobBytes, JobFiles, Job.StartTime ORDER by JobName, Start;  | 
|
| 
	and so with query 20: SELECT Job.Name as JobName, Job.JobId as JobID, VolumeName, Job.StartTime as Start, JobFiles AS Files,ROUND(JobBytes/1024.0/1024.0/1024.0,3) AS Bytes FROM Job,JobMedia,Media WHERE Job.Name='%1' AND JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId GROUP by VolumeName, Job.JobID, Job.Name, JobFiles, JobBytes, Job.StartTime ORDER by JobName, Start;  | 
|
| 
	Added RecycleCounts and changed the order in favor of VolError instead of Volstatus for query 16 :List Volumes likely to need replacement from age or errors SELECT VolumeName AS Volume,VolErrors AS Errors, VolMounts AS Mounts, VolWrites AS Writes,RecycleCount,VolStatus AS Status FROM Media WHERE (VolErrors>0) OR (VolStatus='Error') OR (VolMounts>50) OR (VolStatus='Disabled') OR (VolWrites>3999999) ORDER BY VolErrors DESC, VolStatus, VolMounts,VolumeName DESC;  | 
|
| 
	added ROUND() # 15 :List Volumes Bacula thinks are in changer SELECT MediaId,VolumeName,ROUND(VolBytes/(1024.0*1024.0*1024.0),3) AS GB,Storage.Name AS Storage,Slot,Pool.Name AS Pool,MediaType,VolStatus FROM Media,Pool,Storage WHERE Media.PoolId=Pool.PoolId AND Slot>0 AND InChanger=1 AND Media.StorageId=Storage.StorageId ORDER BY MediaType ASC, Slot ASC;  | 
|
| 
		
		 
			  2013-07-25 16:43 
  | 
	
	  query.sql (9,350 bytes)   
 
#
# This file contains sample queries that you can possibly use in
# your query.sql file.  However, please note that these examples
# are not supported. They may or may not work -- in fact, they may
# work with one SQL engine and not another.  As a consequence,
# please do not submit bug reports on either query.sql or 
# sample-query.sql
#
# If you find that they work for MySQL and not for PostgreSQL,
#  then please send us a whole new file corrected for PostgreSQL
#  and we will post it in the examples directory for everyone
#  to use.
#
# 1 
:List up to 20 places where a File is saved regardless of the directory and Client
*Enter Filename (no path):
SELECT DISTINCT Job.JobId AS JobId, Client.Name AS Client,
  Path.Path,Filename.Name,StartTime,Level,JobFiles,ROUND(JobBytes/1024.0/1024.0/1024.0,3) AS GB
 FROM Client,Job,File,Filename,Path WHERE Client.ClientId=Job.ClientId
 AND JobStatus IN ('T','W') AND Job.JobId=File.JobId
 AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId
 AND Filename.Name='%1' 
 ORDER BY Job.StartTime LIMIT 20;
# 2
:List where the most recent copies of a file with path of a Client are saved
*Enter path with trailing slash:
*Enter filename:
*Enter Client name:
SELECT DISTINCT Job.JobId,StartTime AS JobStartTime,VolumeName,Client.Name AS ClientName
 FROM Job,File,Path,Filename,Media,JobMedia,Client
 WHERE File.JobId=Job.JobId
 AND Path.Path='%1'
 AND Filename.Name='%2'
 AND Client.Name='%3'
 AND Path.PathId=File.PathId
 AND Filename.FilenameId=File.FilenameId
 AND JobMedia.JobId=Job.JobId
 AND JobMedia.MediaId=Media.MediaId
 AND Client.ClientId=Job.ClientId
 ORDER BY Job.StartTime DESC LIMIT 5;
# 3
:List last 20 Full Backups for a Client
*Enter Client name:
SELECT DISTINCT Job.JobId,Client.Name AS Client,Starttime,JobFiles,ROUND(JobBytes/1024.0/1024.0/1024.0,3) AS GB
 FROM Client,Job,JobMedia,Media
 WHERE Client.Name='%1'
 AND Client.ClientId=Job.ClientId
 AND Level='F' AND JobStatus IN ('T', 'W')
 AND JobMedia.JobId=Job.JobId
 AND JobMedia.MediaId=Media.MediaId
 ORDER BY Job.StartTime DESC LIMIT 20;
# 4
:List all backups for a Client after a specified time
*Enter Client Name:
*Enter time in YYYY-MM-DD HH:MM:SS format:
SELECT DISTINCT Job.JobId,Client.Name AS Client,Level,StartTime,JobFiles,ROUND(JobBytes/1024.0/1024.0/1024.0,3) AS GB,Count(VolumeName) AS Volumes
 FROM Client,Job,JobMedia,Media
 WHERE Client.Name='%1'
 AND Client.ClientId=Job.ClientId
 AND JobStatus IN ('T', 'W')
 AND JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId
 AND Job.StartTime >= '%2'
 GROUP BY Job.JobId,Client.Name,Level,StartTime,JobFiles,JobBytes
 ORDER BY Job.StartTime;
# 5
:List all backups for a Client and COUNT the Volumes which been used
*Enter Client Name:
SELECT DISTINCT Job.JobId AS JobId,Client.Name AS Client,
   FileSet.FileSet AS FileSet,Level,StartTime,
   JobFiles,ROUND(JobBytes/1024.0/1024.0/1024.0,3) AS GB,Count(VolumeName) AS Volumes
 FROM Client,Job,JobMedia,Media,FileSet
 WHERE Client.Name='%1'
 AND Client.ClientId=Job.ClientId AND Job.Type='B'
 AND Job.JobStatus IN ('T','W') AND Job.FileSetId=FileSet.FileSetId
 AND JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId
 GROUP BY Job.JobId,Client.Name,FileSet.FileSet,Level,StartTime,JobFiles,JobBytes
 ORDER BY Job.StartTime;
# 6
:List Volume Attributes for a selected Volume
*Enter Volume name:
SELECT Slot,MaxVolBytes,VolCapacityBytes,VolStatus,Recycle,VolRetention,
  VolUseDuration,MaxVolJobs,MaxVolFiles
 FROM Media   
 WHERE VolumeName='%1';
# 7
:List Volumes used by selected JobId
*Enter JobId:
SELECT DISTINCT Job.JobId,VolumeName 
 FROM Job,JobMedia,Media 
 WHERE Job.JobId=%1 
 AND Job.JobId=JobMedia.JobId 
 AND JobMedia.MediaId=Media.MediaId;
# 8
:List Volumes to Restore All Files
*Enter Client Name:
!DROP TABLE temp;
!DROP TABLE temp2;
CREATE TABLE temp (JobId BIGINT NOT NULL,
 JobTDate BIGINT,
 ClientId BIGINT,
 Level CHAR,
 StartTime TEXT,
 VolumeName TEXT,
 StartFile BIGINT, 
 VolSessionId BIGINT,
 VolSessionTime BIGINT );
CREATE TABLE temp2 (JobId BIGINT NOT NULL,
 StartTime TEXT,
 VolumeName TEXT,
 Level CHAR,
 StartFile BIGINT, 
 VolSessionId BIGINT,
 VolSessionTime BIGINT);
# Select last Full save
INSERT INTO temp SELECT Job.JobId,JobTDate,Job.ClientId,Job.Level,
  StartTime,VolumeName,JobMedia.StartFile,VolSessionId,VolSessionTime
 FROM Client,Job,JobMedia,Media WHERE Client.Name='%1'
 AND Client.ClientId=Job.ClientId
 AND Level='F' AND JobStatus IN ('T', 'W')
 AND JobMedia.JobId=Job.JobId 
 AND JobMedia.MediaId=Media.MediaId
 ORDER BY Job.JobTDate DESC LIMIT 1;
# Copy into temp 2 getting all volumes of Full save
INSERT INTO temp2 SELECT Job.JobId,Job.StartTime,Media.VolumeName,Job.Level,
  JobMedia.StartFile,Job.VolSessionId,Job.VolSessionTime
 FROM temp,Job,JobMedia,Media WHERE temp.JobId=Job.JobId
 AND Job.Level='F' AND Job.JobStatus IN ('T', 'W')
 AND JobMedia.JobId=Job.JobId
 AND JobMedia.MediaId=Media.MediaId;
# Now add subsequent incrementals
INSERT INTO temp2 SELECT DISTINCT Job.JobId,Job.StartTime,Media.VolumeName,
  Job.Level,JobMedia.StartFile,Job.VolSessionId,Job.VolSessionTime
 FROM Job,temp,JobMedia,Media
 WHERE Job.JobTDate>temp.JobTDate 
 AND Job.ClientId=temp.ClientId
 AND Job.Level IN ('I','D') AND JobStatus IN ('T', 'W')
 AND JobMedia.JobId=Job.JobId 
 AND JobMedia.MediaId=Media.MediaId;
# list results
SELECT DISTINCT VolumeName from temp2;
!DROP TABLE temp;
!DROP TABLE temp2;
# 9
:List Pool Attributes for a selected Pool
*Enter Pool name:
SELECT Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes
 FROM Pool
 WHERE Name='%1';
# 10
:List total files/bytes by Job
SELECT COUNT(*) AS Jobs,SUM(JobFiles) AS Files,ROUND(SUM(JobBytes/1024.0/1024.0/1024.0),3) AS GB, Name AS Job
 FROM Job 
 GROUP by Name;
# 11
:List total files/bytes by Volume
SELECT COUNT(*) AS Jobs,SUM(JobFiles) AS Files,ROUND(SUM(JobBytes/1024.0/1024.0/1024.0),3) AS GB, VolumeName
 FROM Job,JobMedia,Media
 WHERE JobMedia.JobId=Job.JobId
 AND JobMedia.MediaId=Media.MediaId
 GROUP by VolumeName;  
# 12
:List Files for a selected JobId
*Enter JobId:
SELECT Path.Path,Filename.Name FROM File,Filename,Path WHERE File.JobId=%1 
 AND Filename.FilenameId=File.FilenameId 
 AND Path.PathId=File.PathId ORDER BY
 Path.Path,Filename.Name;
# 13
:List Jobs stored on a selected MediaId
*Enter MediaId:
SELECT DISTINCT Job.JobId,Job.Name,Job.StartTime,Job.Type,
  Job.Level,Job.JobFiles,ROUND(Job.JobBytes/1024.0/1024.0/1024.0,3) AS GB,Job.JobStatus
 FROM JobMedia,Job
 WHERE JobMedia.JobId=Job.JobId
 AND JobMedia.MediaId=%1 
 ORDER by Job.StartTime;
# 14  
:List Jobs stored for a given Volume name
*Enter Volume name:
SELECT DISTINCT Job.JobId AS JobId,Job.Name AS Name,Job.StartTime AS StartTime,
  Job.Type AS Type,Job.Level AS Level,Job.JobFiles AS Files,
  ROUND(Job.JobBytes/1024.0/1024.0/1024.0,3) AS GB ,Job.JobStatus AS Status
 FROM Media,JobMedia,Job
 WHERE Media.VolumeName='%1'
 AND Media.MediaId=JobMedia.MediaId              
 AND JobMedia.JobId=Job.JobId
 ORDER by Job.StartTime;
# 15
:List Volumes Bareos thinks are in changer
SELECT MediaId,VolumeName,ROUND(VolBytes/(1024.0*1024.0*1024.0),3) AS GB,Storage.Name
  AS Storage,Slot,Pool.Name AS Pool,MediaType,VolStatus
  FROM Media,Pool,Storage
  WHERE Media.PoolId=Pool.PoolId
  AND Slot>0 AND InChanger=1
  AND Media.StorageId=Storage.StorageId
  ORDER BY MediaType ASC, Slot ASC;
# 16
:List Volumes likely to need replacement from age or errors
SELECT VolumeName AS Volume,VolErrors AS Errors, VolMounts AS Mounts,
VolWrites AS Writes,RecycleCount,VolStatus AS Status
  FROM Media
  WHERE (VolErrors>0) OR (VolStatus='Error') OR (VolMounts>50) OR
        (VolStatus='Disabled') OR (VolWrites>3999999)
  ORDER BY VolErrors DESC, VolStatus, VolMounts,VolumeName DESC;
#  17
:List Volumes Bareos thinks are eligible for the changer
SELECT VolumeName,VolStatus,Storage.Name AS Location,
   VolBytes/(1024*1024*1024) AS GB,MediaId,MediaType,Pool.Name AS Pool
   FROM Media,Pool,Storage
   WHERE Media.PoolId=Pool.PoolId
   AND Media.StorageId=Storage.StorageId
   AND InChanger=0
   AND ((VolStatus='Purged') OR (VolStatus='Append') OR (VolStatus='Recycle'))
   ORDER BY VolMounts ASC, Pool.Name ASC, VolumeName ASC
# 18
:List Volumes by Volume:
SELECT VolumeName, Job.JobId AS JobID, Job.Name AS JobName, Job.StartTime AS
Start, JobFiles AS Files,ROUND(JobBytes/1024.0/1024.0/1024.0,3) AS GB
 FROM Job,JobMedia,Media
 WHERE JobMedia.JobId=Job.JobId
 AND JobMedia.MediaId=Media.MediaId
 GROUP by VolumeName, Job.JobID, Job.Name, JobBytes, JobFiles, Job.StartTime
 ORDER by VolumeName; 
# 19
:List Volumes by Jobs:
SELECT Job.Name AS JobName, Job.JobId AS JobID, VolumeName, Job.StartTime AS
Start, JobFiles AS Files,ROUND(JobBytes/1024.0/1024.0/1024.0,3) AS GB
 FROM Job,JobMedia,Media
 WHERE JobMedia.JobId=Job.JobId
 AND JobMedia.MediaId=Media.MediaId
 GROUP by VolumeName, Job.JobID, Job.Name, JobBytes, JobFiles, Job.StartTime
 ORDER by JobName, Start; 
# 20
:List Volumes for a jobname:
*Enter Job name:
SELECT Job.Name AS JobName, Job.JobId AS JobID, VolumeName, Job.StartTime AS
Start, JobFiles AS Files,ROUND(JobBytes/1024.0/1024.0/1024.0,3) AS Bytes
 FROM Job,JobMedia,Media
 WHERE Job.Name='%1'
 AND JobMedia.JobId=Job.JobId
 AND JobMedia.MediaId=Media.MediaId
 GROUP by VolumeName, Job.JobID, Job.Name, JobBytes, JobFiles, Job.StartTime
 ORDER by JobName, Start;
 | 
| 
	Dear Jörg, please integrate. Thanks! Best regards, Erol  | 
|
| Fix committed to bareos master branch with changesetid 532. | |
| Fix committed to bareos master branch with changesetid 596. | |
| Fix committed to bareos2015 bareos-14.2 branch with changesetid 5084. | |
| 
	Due to the reimport of the Github repository to bugs.bareos.org, the status of some tickets have been changed. These tickets will be closed again. Sorry for the noise.  | 
|
| 
	
	 bareos: master aa9861c5 2013-07-26 17:21 Committer: Ported: N/A Details Diff | 
sample sql queries provide sample sql queries, that can be used by the bconsole query command. Fixes 0000083: Bareos packages do not contain query.sql Signed-off-by: Marco van Wieringen <marco.van.wieringen@bareos.com>  | 
Affected Issues 0000083  | 
|
| mod - src/dird/query.sql | Diff File | ||
| 
	
	 bareos2015: bareos-14.2 e75cb33b 2013-07-26 19:21 Committer: mvwieringen Ported: N/A Details Diff | 
sample sql queries provide sample sql queries, that can be used by the bconsole query command. Fixes 0000083: Bareos packages do not contain query.sql Signed-off-by: Marco van Wieringen <marco.van.wieringen@bareos.com>  | 
Affected Issues 0000083  | 
|
| mod - src/dird/query.sql | Diff File | ||
| Date Modified | Username | Field | Change | 
|---|---|---|---|
| 2013-02-21 11:48 | joergs | New Issue | |
| 2013-02-21 11:48 | joergs | Status | new => assigned | 
| 2013-02-21 11:48 | joergs | Assigned To | => mvwieringen | 
| 2013-02-21 13:34 | mvwieringen | Note Added: 0000141 | |
| 2013-02-21 13:34 | mvwieringen | Assigned To | mvwieringen => joergs | 
| 2013-02-23 08:01 | pstorz | Note Added: 0000148 | |
| 2013-02-25 14:48 | joergs | Assigned To | joergs => user12 | 
| 2013-02-25 14:48 | joergs | Note Added: 0000157 | |
| 2013-04-19 13:39 | 
					 | 
				Note Added: 0000357 | |
| 2013-05-07 14:52 | 
					 | 
				Note Added: 0000399 | |
| 2013-06-05 16:33 | 
					 | 
				Note Added: 0000444 | |
| 2013-07-24 18:01 | 
					 | 
				Note Added: 0000541 | |
| 2013-07-24 18:05 | 
					 | 
				Note Added: 0000542 | |
| 2013-07-24 18:08 | 
					 | 
				Note Added: 0000543 | |
| 2013-07-25 15:08 | 
					 | 
				Note Added: 0000544 | |
| 2013-07-25 15:11 | 
					 | 
				Note Added: 0000545 | |
| 2013-07-25 16:43 | 
					 | 
				File Added: query.sql | |
| 2013-07-25 16:44 | 
					 | 
				Assigned To | user12 => joergs | 
| 2013-07-25 16:44 | 
					 | 
				Note Added: 0000549 | |
| 2013-07-27 17:11 | mvwieringen | Changeset attached | => bareos master 3279438d | 
| 2013-07-27 17:11 | mvwieringen | Note Added: 0000559 | |
| 2013-07-27 17:11 | mvwieringen | Assigned To | joergs => mvwieringen | 
| 2013-07-27 17:11 | mvwieringen | Status | assigned => resolved | 
| 2013-07-27 17:11 | mvwieringen | Resolution | open => fixed | 
| 2013-08-13 03:12 | 
					 | 
				Changeset attached | => bareos master aa9861c5 | 
| 2013-08-13 03:12 | 
					 | 
				Note Added: 0000573 | |
| 2013-08-13 03:12 | 
					 | 
				Assigned To | mvwieringen => mvwieringen adm | 
| 2013-09-06 13:11 | mvwieringen | Status | resolved => closed | 
| 2013-09-06 13:11 | mvwieringen | Assigned To | mvwieringen adm => | 
| 2015-03-25 16:51 | mvwieringen | Changeset attached | => bareos2015 bareos-14.2 e75cb33b | 
| 2015-03-25 16:51 | mvwieringen | Note Added: 0001491 | |
| 2015-03-25 16:51 | mvwieringen | Status | closed => resolved | 
| 2015-03-25 19:19 | joergs | Note Added: 0001641 | |
| 2015-03-25 19:19 | joergs | Status | resolved => closed |