+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
+
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation and included
+ in the file LICENSE.
+
+ 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of Kern Sibbald.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
/*
* Bacula Catalog Database List records interface routines
*
*
* Version $Id$
*/
-/*
- Copyright (C) 2000-2006 Kern Sibbald
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as amended with additional clauses defined in the
- file LICENSE in the main source directory.
-
- 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
- the file LICENSE for additional details.
-
- */
/* The following is necessary so that we do not include
* the dummy external definition of DB.
#include "bacula.h"
#include "cats.h"
-#if HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL
+extern int db_type;
+
+#if HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL || HAVE_DBI
/* -----------------------------------------------------------------------
*
* -----------------------------------------------------------------------
*/
-/* Imported subroutines */
-extern void list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
-extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd);
-
-
/*
* Submit general SQL query
*/
-int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit,
+int db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit,
void *ctx, int verbose, e_list_type type)
{
db_lock(mdb);
}
void
-db_list_pool_records(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr,
+db_list_pool_records(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr,
DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
{
db_lock(mdb);
Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,Slot,PoolId,"
"MediaType,FirstWritten,LastWritten,LabelDate,VolJobs,"
"VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites,"
- "VolCapacityBytes,VolStatus,Recycle,VolRetention,"
+ "VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention,"
"VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,"
- "EndFile,EndBlock,VolParts,LabelType,StorageId"
+ "EndFile,EndBlock,VolParts,LabelType,StorageId,DeviceId,"
+ "LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
+ "Comment"
" FROM Media WHERE Media.VolumeName='%s'", mdbr->VolumeName);
} else {
Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,Slot,PoolId,"
"MediaType,FirstWritten,LastWritten,LabelDate,VolJobs,"
"VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites,"
- "VolCapacityBytes,VolStatus,Recycle,VolRetention,"
+ "VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention,"
"VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,"
- "EndFile,EndBlock,VolParts,LabelType,StorageId"
- " FROM Media WHERE Media.PoolId=%s ORDER BY MediaId",
+ "EndFile,EndBlock,VolParts,LabelType,StorageId,DeviceId,"
+ "LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
+ "Comment"
+ " FROM Media WHERE Media.PoolId=%s ORDER BY MediaId",
edit_int64(mdbr->PoolId, ed1));
}
} else {
if (mdbr->VolumeName[0] != 0) {
- Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolStatus,"
+ Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolStatus,Enabled,"
"VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,MediaType,LastWritten "
"FROM Media WHERE Media.VolumeName='%s'", mdbr->VolumeName);
} else {
- Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolStatus,"
+ Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolStatus,Enabled,"
"VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,MediaType,LastWritten "
- "FROM Media WHERE Media.PoolId=%s ORDER BY MediaId",
+ "FROM Media WHERE Media.PoolId=%s ORDER BY MediaId",
edit_int64(mdbr->PoolId, ed1));
}
}
}
+void db_list_copies_records(JCR *jcr, B_DB *mdb, uint32_t limit, char *JobIds,
+ DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
+{
+ POOL_MEM str_limit(PM_MESSAGE);
+ POOL_MEM str_jobids(PM_MESSAGE);
+
+ if (limit > 0) {
+ Mmsg(str_limit, " LIMIT %d", limit);
+ }
+
+ if (JobIds && JobIds[0]) {
+ Mmsg(str_jobids, " AND (C.PriorJobId IN (%s) OR C.JobId IN (%s)) ",
+ JobIds, JobIds);
+ }
+
+ db_lock(mdb);
+ Mmsg(mdb->cmd,
+ "SELECT DISTINCT C.PriorJobId AS JobId, C.Job, "
+ "C.JobId AS CopyJobId, M.MediaType "
+ "FROM Job AS C "
+ "JOIN JobMedia USING (JobId) "
+ "JOIN Media AS M USING (MediaId) "
+ "WHERE C.Type = '%c' %s ORDER BY C.PriorJobId DESC %s",
+ (char) JT_JOB_COPY, str_jobids.c_str(), str_limit.c_str());
+
+ if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
+ goto bail_out;
+ }
+
+ list_result(jcr, mdb, sendit, ctx, type);
+
+ sql_free_result(mdb);
+
+bail_out:
+ db_unlock(mdb);
+}
+
+void db_list_joblog_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
+ DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
+{
+ char ed1[50];
+ db_lock(mdb);
+ if (JobId <= 0) {
+ return;
+ }
+ if (type == VERT_LIST) {
+ Mmsg(mdb->cmd, "SELECT Time,LogText FROM Log "
+ "WHERE Log.JobId=%s", edit_int64(JobId, ed1));
+ } else {
+ Mmsg(mdb->cmd, "SELECT LogText FROM Log "
+ "WHERE Log.JobId=%s", edit_int64(JobId, ed1));
+ }
+ if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
+ goto bail_out;
+ }
+
+ list_result(jcr, mdb, sendit, ctx, type);
+
+ sql_free_result(mdb);
+
+bail_out:
+ db_unlock(mdb);
+}
+
/*
* List Job record(s) that match JOB_DBR
if (jr->JobId == 0 && jr->Job[0] == 0) {
Mmsg(mdb->cmd,
"SELECT JobId,Job,Job.Name,PurgedFiles,Type,Level,"
- "Job.ClientId,Client.Name,JobStatus,SchedTime,"
- "StartTime,EndTime,JobTDate,"
+ "Job.ClientId,Client.Name as ClientName,JobStatus,SchedTime,"
+ "StartTime,EndTime,RealEndTime,JobTDate,"
"VolSessionId,VolSessionTime,JobFiles,JobErrors,"
- "JobMissingFiles,Job.PoolId,Pool.Name,Job.FileSetId,FileSet.FileSet "
+ "JobMissingFiles,Job.PoolId,Pool.Name as PooLname,PriorJobId,"
+ "Job.FileSetId,FileSet.FileSet "
"FROM Job,Client,Pool,FileSet WHERE "
"Client.ClientId=Job.ClientId AND Pool.PoolId=Job.PoolId "
"AND FileSet.FileSetId=Job.FileSetId ORDER BY StartTime%s", limit);
Mmsg(mdb->cmd,
"SELECT JobId,Job,Job.Name,PurgedFiles,Type,Level,"
"Job.ClientId,Client.Name,JobStatus,SchedTime,"
- "StartTime,EndTime,JobTDate,"
+ "StartTime,EndTime,RealEndTime,JobTDate,"
"VolSessionId,VolSessionTime,JobFiles,JobErrors,"
- "JobMissingFiles,Job.PoolId,Pool.Name,Job.FileSetId,FileSet.FileSet "
+ "JobMissingFiles,Job.PoolId,Pool.Name as PooLname,PriorJobId,"
+ "Job.FileSetId,FileSet.FileSet "
"FROM Job,Client,Pool,FileSet WHERE Job.JobId=%s AND "
"Client.ClientId=Job.ClientId AND Pool.PoolId=Job.PoolId "
- "AND FileSet.FileSetId=Job.FileSetId",
+ "AND FileSet.FileSetId=Job.FileSetId",
edit_int64(jr->JobId, ed1));
}
} else {
"SELECT JobId,Name,StartTime,Type,Level,JobFiles,JobBytes,JobStatus "
"FROM Job WHERE Job='%s' ORDER BY StartTime,JobId ASC", jr->Job);
} else if (jr->JobId != 0) {
- Mmsg(mdb->cmd,
+ Mmsg(mdb->cmd,
"SELECT JobId,Name,StartTime,Type,Level,JobFiles,JobBytes,JobStatus "
"FROM Job WHERE JobId=%s", edit_int64(jr->JobId, ed1));
} else { /* all records */
db_unlock(mdb);
}
-/*
- * Stupid MySQL is NON-STANDARD !
- */
-#ifdef HAVE_MYSQL
-#define FN "CONCAT(Path.Path,Filename.Name)"
-#else
-#define FN "Path.Path||Filename.Name"
-#endif
-
void
db_list_files_for_job(JCR *jcr, B_DB *mdb, JobId_t jobid, DB_LIST_HANDLER *sendit, void *ctx)
{
char ed1[50];
db_lock(mdb);
- Mmsg(mdb->cmd, "SELECT " FN " AS Filename FROM File,"
-"Filename,Path WHERE File.JobId=%s AND Filename.FilenameId=File.FilenameId "
-"AND Path.PathId=File.PathId",
- edit_int64(jobid, ed1));
+ /*
+ * Stupid MySQL is NON-STANDARD !
+ */
+ if (db_type == SQL_TYPE_MYSQL) {
+ Mmsg(mdb->cmd, "SELECT CONCAT(Path.Path,Filename.Name) AS Filename FROM File,"
+ "Filename,Path WHERE File.JobId=%s AND Filename.FilenameId=File.FilenameId "
+ "AND Path.PathId=File.PathId",
+ edit_int64(jobid, ed1));
+ } else {
+ Mmsg(mdb->cmd, "SELECT Path.Path||Filename.Name AS Filename FROM File,"
+ "Filename,Path WHERE File.JobId=%s AND Filename.FilenameId=File.FilenameId "
+ "AND Path.PathId=File.PathId",
+ edit_int64(jobid, ed1));
+ }
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
db_unlock(mdb);