2 * Bacula Catalog Database Update record 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
18 Copyright (C) 2001, 2002 Kern Sibbald and John Walker
20 This program is free software; you can redistribute it and/or
21 modify it under the terms of the GNU General Public License as
22 published by the Free Software Foundation; either version 2 of
23 the License, or (at your option) any later version.
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 General Public License for more details.
30 You should have received a copy of the GNU General Public
31 License along with this program; if not, write to the Free
32 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
38 /* The following is necessary so that we do not include
39 * the dummy external definition of DB.
41 #define __SQL_C /* indicate that this is sql.c */
49 /* Forward referenced functions */
51 /* -----------------------------------------------------------------------
53 * Bacula specific defines and subroutines
55 * -----------------------------------------------------------------------
60 * This is called at Job start time to add the
61 * most current start fields to the job record.
62 * It is assumed that you did a db_create_job_record() already.
64 int db_update_job_start_record(B_DB *mdb, JOB_DBR *jr)
69 Dmsg0(200, "In db_update_job_start_record\n");
71 memcpy(&ojr, jr, len);
73 if (!db_get_job_record(mdb, &ojr)) {
79 fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
80 if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
81 Mmsg1(&mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
91 * This is called at Job termination time to add all the
92 * other fields to the job record.
94 int db_update_job_end_record(B_DB *mdb, JOB_DBR *jr)
99 Dmsg0(200, "In db_update_job_start_record\n");
101 memcpy(&ojr, jr, len);
103 if (!db_get_job_record(mdb, &ojr)) {
109 fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
110 if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
111 Mmsg1(&mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
121 int db_update_media_record(B_DB *mdb, MEDIA_DBR *mr)
127 Dmsg0(200, "In db_update_media_record\n");
130 memcpy(&omr, mr, len);
132 if (!db_get_media_record(mdb, &omr)) {
138 /* Don't allow some fields to change by copying from master record */
139 strcpy(mr->VolumeName, omr.VolumeName);
140 strcpy(mr->MediaType, omr.MediaType);
141 mr->MediaId = omr.MediaId;
142 mr->PoolId = omr.PoolId;
143 mr->MaxVolBytes = omr.MaxVolBytes;
144 mr->VolCapacityBytes = omr.VolCapacityBytes;
145 mr->Recycle = omr.Recycle;
147 fseek(mdb->mediafd, omr.rec_addr, SEEK_SET);
148 if (fwrite(mr, len, 1, mdb->mediafd) != 1) {
149 Mmsg1(&mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
152 fflush(mdb->mediafd);
158 int db_update_pool_record(B_DB *mdb, POOL_DBR *pr)
164 Dmsg0(200, "In db_update_pool_record\n");
166 memcpy(&opr, pr, len);
168 if (!db_get_pool_record(mdb, &opr)) {
174 /* Update specific fields */
175 opr.NumVols = pr->NumVols;
176 opr.MaxVols = pr->MaxVols;
177 opr.UseOnce = pr->UseOnce;
178 opr.UseCatalog = pr->UseCatalog;
179 opr.AcceptAnyVolume = pr->AcceptAnyVolume;
180 strcpy(opr.LabelFormat, pr->LabelFormat);
182 fseek(mdb->poolfd, opr.rec_addr, SEEK_SET);
183 if (fwrite(&opr, len, 1, mdb->poolfd) != 1) {
184 Mmsg1(&mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
187 memcpy(pr, &opr, len); /* return record written */
195 int db_add_MD5_to_file_record(B_DB *mdb, FileId_t FileId, char *MD5)
200 int db_mark_file_record(B_DB *mdb, FileId_t FileId, JobId_t JobId)
206 #endif /* HAVE_BACULA_DB */