2 * Bacula Catalog Database List records interface routines
4 * Bacula Catalog Database routines written specifically
5 * for Bacula. Note, these routines are VERY dumb and
6 * do not provide all the functionality of an SQL database.
7 * The purpose of these routines is to ensure that Bacula
8 * can limp along if no real database is loaded on the
11 * Kern Sibbald, January MMI
16 Bacula® - The Network Backup Solution
18 Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
20 The main author of Bacula is Kern Sibbald, with contributions from
21 many others, a complete list can be found in the file AUTHORS.
22 This program is Free Software; you can redistribute it and/or
23 modify it under the terms of version two of the GNU General Public
24 License as published by the Free Software Foundation plus additions
25 that are listed in the file LICENSE.
27 This program is distributed in the hope that it will be useful, but
28 WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 General Public License for more details.
32 You should have received a copy of the GNU General Public License
33 along with this program; if not, write to the Free Software
34 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
37 Bacula® is a registered trademark of John Walker.
38 The licensor of Bacula is the Free Software Foundation Europe
39 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
40 Switzerland, email:ftf@fsfeurope.org.
44 /* The following is necessary so that we do not include
45 * the dummy external definition of DB.
47 #define __SQL_C /* indicate that this is sql.c */
55 /* Forward referenced functions */
57 /* -----------------------------------------------------------------------
59 * Bacula specific defines and subroutines
61 * -----------------------------------------------------------------------
65 * Submit general SQL query
67 int db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit,
68 void *ctx, int verbose)
70 sendit(ctx, "SQL Queries not implemented with internal database.\n");
76 * List all the pool records
78 void db_list_pool_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx)
83 Dmsg0(90, "Enter list_pool_records\n");
85 if (!bdb_open_pools_file(mdb)) {
89 sendit(ctx, " PoolId NumVols MaxVols Type PoolName\n");
90 sendit(ctx, "===================================================\n");
91 fseek(mdb->poolfd, 0L, SEEK_SET); /* rewind file */
93 while (fread(&pr, len, 1, mdb->poolfd) > 0) {
94 Mmsg(mdb->cmd, " %7d %6d %6d %-10s %s\n",
95 pr.PoolId, pr.NumVols, pr.MaxVols, pr.PoolType, pr.Name);
96 sendit(ctx, mdb->cmd);
98 sendit(ctx, "===================================================\n");
100 Dmsg0(90, "Leave list_pool_records\n");
108 void db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
109 DB_LIST_HANDLER *sendit, void *ctx)
116 if (!bdb_open_media_file(mdb)) {
120 sendit(ctx, " Status VolBytes MediaType VolumeName\n");
121 sendit(ctx, "=============================================================\n");
122 fseek(mdb->mediafd, 0L, SEEK_SET); /* rewind file */
124 while (fread(&mr, len, 1, mdb->mediafd) > 0) {
125 Mmsg(mdb->cmd, " %-10s %17s %-15s %s\n",
126 mr.VolStatus, edit_uint64_with_commas(mr.VolBytes, ewc),
127 mr.MediaType, mr.VolumeName);
128 sendit(ctx, mdb->cmd);
130 sendit(ctx, "====================================================================\n");
135 void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
136 DB_LIST_HANDLER *sendit, void *ctx)
143 if (!bdb_open_jobmedia_file(mdb)) {
147 if (!bdb_open_media_file(mdb)) {
151 sendit(ctx, " JobId VolumeName FirstIndex LastIndex\n");
152 sendit(ctx, "============================================\n");
155 fseek(mdb->jobmediafd, 0L, SEEK_SET); /* rewind the file */
156 while (fread(&jm, jmlen, 1, mdb->jobmediafd) > 0) {
159 if (jm.JobId == JobId) {
160 /* Now find VolumeName in corresponding Media record */
161 fseek(mdb->mediafd, 0L, SEEK_SET);
162 while (fread(&mr, mrlen, 1, mdb->mediafd) > 0) {
163 if (mr.MediaId == jm.MediaId) {
164 Mmsg(mdb->cmd, " %7d %-10s %10d %10d\n",
165 jm.JobId, mr.VolumeName, jm.FirstIndex, jm.LastIndex);
166 sendit(ctx, mdb->cmd);
172 /* List all records */
173 fseek(mdb->mediafd, 0L, SEEK_SET);
174 while (fread(&mr, mrlen, 1, mdb->mediafd) > 0) {
175 if (mr.MediaId == jm.MediaId) {
176 Mmsg(mdb->cmd, " %7d %-10s %10d %10d\n",
177 jm.JobId, mr.VolumeName, jm.FirstIndex, jm.LastIndex);
178 sendit(ctx, mdb->cmd);
185 sendit(ctx, "============================================\n");
194 void db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr,
195 DB_LIST_HANDLER *sendit, void *ctx)
201 char ewc1[30], ewc2[30];
202 char dt[MAX_TIME_LENGTH];
206 if (!bdb_open_jobs_file(mdb)) {
210 fseek(mdb->jobfd, 0L, SEEK_SET); /* rewind file */
212 * Linear search through Job records
214 sendit(ctx, " JobId StartTime Type Level Bytes Files Stat JobName\n");
215 sendit(ctx, "==========================================================================\n");
217 while (!done && fread(&ojr, jrlen, 1, mdb->jobfd) > 0) {
218 if (jr->JobId != 0) {
219 if (jr->JobId == ojr.JobId) {
225 localtime_r(&ojr.StartTime, &tm);
226 strftime(dt, sizeof(dt), "%m-%d %H:%M", &tm);
227 Mmsg(mdb->cmd, " %7d %-10s %c %c %14s %10s %c %s\n",
228 ojr.JobId, dt, (char)ojr.JobType, (char)ojr.JobLevel,
229 edit_uint64_with_commas(ojr.JobBytes, ewc1),
230 edit_uint64_with_commas(ojr.JobFiles, ewc2),
231 (char)ojr.JobStatus, ojr.Name);
232 sendit(ctx, mdb->cmd);
234 sendit(ctx, "============================================================================\n");
244 void db_list_job_totals(JCR *jcr, B_DB *mdb, JOB_DBR *jr,
245 DB_LIST_HANDLER *sendit, void *ctx)
247 char ewc1[30], ewc2[30], ewc3[30];
250 uint64_t total_bytes = 0;
251 uint64_t total_files = 0;
252 uint32_t total_jobs = 0;
255 if (!bdb_open_jobs_file(mdb)) {
259 fseek(mdb->jobfd, 0L, SEEK_SET); /* rewind file */
261 * Linear search through JobStart records
263 sendit(ctx, " NumJobs NumFiles NumBytes\n");
264 sendit(ctx, "=======================================\n");
266 while (fread(&ojr, jrlen, 1, mdb->jobfd) > 0) {
267 total_files += ojr.JobFiles;
268 total_bytes += ojr.JobBytes;
271 Mmsg(mdb->cmd, " %7s %10s %15s\n",
272 edit_uint64_with_commas(total_jobs, ewc1),
273 edit_uint64_with_commas(total_files, ewc2),
274 edit_uint64_with_commas(total_bytes, ewc3));
275 sendit(ctx, mdb->cmd);
276 sendit(ctx, "=======================================\n");
283 void db_list_files_for_job(JCR *jcr, B_DB *mdb, uint32_t jobid, DB_LIST_HANDLER *sendit, void *ctx)
286 void db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx)
289 int db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit,
290 void *ctx, int verbose, e_list_type type)
296 db_list_pool_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
300 db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
301 DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
304 void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
305 DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
309 db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, DB_LIST_HANDLER *sendit,
310 void *ctx, e_list_type type)
314 db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
320 #endif /* HAVE_BACULA_DB */