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
15 Copyright (C) 2001, 2002 Kern Sibbald and John Walker
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License as
19 published by the Free Software Foundation; either version 2 of
20 the License, or (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received a copy of the GNU General Public
28 License along with this program; if not, write to the Free
29 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
35 /* The following is necessary so that we do not include
36 * the dummy external definition of DB.
38 #define __SQL_C /* indicate that this is sql.c */
46 /* Forward referenced functions */
48 /* -----------------------------------------------------------------------
50 * Bacula specific defines and subroutines
52 * -----------------------------------------------------------------------
56 * Submit general SQL query
58 int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx)
60 sendit(ctx, "SQL Queries not implemented with internal database.\n");
66 * List all the pool records
68 void db_list_pool_records(B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx)
73 Dmsg0(90, "Enter list_pool_records\n");
75 if (!bdb_open_pools_file(mdb)) {
79 sendit(ctx, " PoolId NumVols MaxVols Type PoolName\n");
80 sendit(ctx, "===================================================\n");
81 fseek(mdb->poolfd, 0L, SEEK_SET); /* rewind file */
83 while (fread(&pr, len, 1, mdb->poolfd) > 0) {
84 Mmsg(&mdb->cmd, " %7d %6d %6d %-10s %s\n",
85 pr.PoolId, pr.NumVols, pr.MaxVols, pr.PoolType, pr.Name);
86 sendit(ctx, mdb->cmd);
88 sendit(ctx, "===================================================\n");
90 Dmsg0(90, "Leave list_pool_records\n");
98 void db_list_media_records(B_DB *mdb, MEDIA_DBR *mdbr, DB_LIST_HANDLER *sendit, void *ctx)
105 if (!bdb_open_media_file(mdb)) {
109 sendit(ctx, " Status VolBytes MediaType VolumeName\n");
110 sendit(ctx, "=============================================================\n");
111 fseek(mdb->mediafd, 0L, SEEK_SET); /* rewind file */
113 while (fread(&mr, len, 1, mdb->mediafd) > 0) {
114 Mmsg(&mdb->cmd, " %-10s %17s %-15s %s\n",
115 mr.VolStatus, edit_uint_with_commas(mr.VolBytes, ewc),
116 mr.MediaType, mr.VolumeName);
117 sendit(ctx, mdb->cmd);
119 sendit(ctx, "====================================================================\n");
124 void db_list_jobmedia_records(B_DB *mdb, uint32_t JobId, DB_LIST_HANDLER *sendit, void *ctx)
131 if (!bdb_open_jobmedia_file(mdb)) {
135 if (!bdb_open_media_file(mdb)) {
139 sendit(ctx, " JobId VolumeName FirstIndex LastIndex\n");
140 sendit(ctx, "============================================\n");
143 fseek(mdb->jobmediafd, 0L, SEEK_SET); /* rewind the file */
144 while (fread(&jm, jmlen, 1, mdb->jobmediafd) > 0) {
147 if (jm.JobId == JobId) {
148 /* Now find VolumeName in corresponding Media record */
149 fseek(mdb->mediafd, 0L, SEEK_SET);
150 while (fread(&mr, mrlen, 1, mdb->mediafd) > 0) {
151 if (mr.MediaId == jm.MediaId) {
152 Mmsg(&mdb->cmd, " %7d %-10s %10d %10d\n",
153 jm.JobId, mr.VolumeName, jm.FirstIndex, jm.LastIndex);
154 sendit(ctx, mdb->cmd);
160 /* List all records */
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);
173 sendit(ctx, "============================================\n");
182 void db_list_job_records(B_DB *mdb, JOB_DBR *jr, DB_LIST_HANDLER *sendit, void *ctx)
187 char ewc1[30], ewc2[30];
188 char dt[MAX_TIME_LENGTH];
192 if (!bdb_open_jobs_file(mdb)) {
196 fseek(mdb->jobfd, 0L, SEEK_SET); /* rewind file */
198 * Linear search through Job records
200 sendit(ctx, " JobId StartTime Type Level Bytes Files Stat JobName\n");
201 sendit(ctx, "==========================================================================\n");
203 while (!done && fread(&ojr, jrlen, 1, mdb->jobfd) > 0) {
204 if (jr->JobId != 0) {
205 if (jr->JobId == ojr.JobId) {
211 localtime_r(&ojr.StartTime, &tm);
212 strftime(dt, sizeof(dt), "%m-%d %H:%M", &tm);
213 Mmsg(&mdb->cmd, " %7d %-10s %c %c %14s %10s %c %s\n",
214 ojr.JobId, dt, (char)ojr.Type, (char)ojr.Level,
215 edit_uint_with_commas(ojr.JobBytes, ewc1),
216 edit_uint_with_commas(ojr.JobFiles, ewc2),
217 (char)ojr.JobStatus, ojr.Name);
218 sendit(ctx, mdb->cmd);
220 sendit(ctx, "============================================================================\n");
229 void db_list_job_totals(B_DB *mdb, JOB_DBR *jr, DB_LIST_HANDLER *sendit, void *ctx)
231 char ewc1[30], ewc2[30], ewc3[30];
234 uint64_t total_bytes = 0;
235 uint64_t total_files = 0;
236 uint32_t total_jobs = 0;
239 if (!bdb_open_jobs_file(mdb)) {
243 fseek(mdb->jobfd, 0L, SEEK_SET); /* rewind file */
245 * Linear search through JobStart records
247 sendit(ctx, " NumJobs NumFiles NumBytes\n");
248 sendit(ctx, "=======================================\n");
250 while (fread(&ojr, jrlen, 1, mdb->jobfd) > 0) {
251 total_files += ojr.JobFiles;
252 total_bytes += ojr.JobBytes;
255 Mmsg(&mdb->cmd, " %7s %10s %15s\n",
256 edit_uint_with_commas(total_jobs, ewc1),
257 edit_uint_with_commas(total_files, ewc2),
258 edit_uint_with_commas(total_bytes, ewc3));
259 sendit(ctx, mdb->cmd);
260 sendit(ctx, "=======================================\n");
267 void db_list_files_for_job(B_DB *mdb, uint32_t jobid, DB_LIST_HANDLER *sendit, void *ctx) {}
269 #endif /* HAVE_BACULA_DB */