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
17 Bacula® - The Network Backup Solution
19 Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
21 The main author of Bacula is Kern Sibbald, with contributions from
22 many others, a complete list can be found in the file AUTHORS.
23 This program is Free Software; you can redistribute it and/or
24 modify it under the terms of version two of the GNU General Public
25 License as published by the Free Software Foundation and included
28 This program is distributed in the hope that it will be useful, but
29 WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with this program; if not, write to the Free Software
35 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
38 Bacula® is a registered trademark of John Walker.
39 The licensor of Bacula is the Free Software Foundation Europe
40 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
41 Switzerland, email:ftf@fsfeurope.org.
45 /* The following is necessary so that we do not include
46 * the dummy external definition of DB.
48 #define __SQL_C /* indicate that this is sql.c */
56 /* -----------------------------------------------------------------------
58 * Bacula specific defines and subroutines
60 * -----------------------------------------------------------------------
65 * This is called at Job start time to add the
66 * most current start fields to the job record.
67 * It is assumed that you did a db_create_job_record() already.
69 bool db_update_job_start_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
76 Dmsg0(200, "In db_update_job_start_record\n");
78 memcpy(&ojr, jr, len);
80 if (!db_get_job_record(jcr, mdb, &ojr)) {
86 fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
87 if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
88 Mmsg1(mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
98 * This is called at Job termination time to add all the
99 * other fields to the job record.
101 int db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
108 Dmsg0(200, "In db_update_job_start_record\n");
110 memcpy(&ojr, jr, len);
112 if (!db_get_job_record(jcr, mdb, &ojr)) {
117 fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
118 if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
119 Mmsg1(&mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
129 int db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
136 Dmsg0(200, "In db_update_media_record\n");
139 memcpy(&omr, mr, len);
141 if (!db_get_media_record(jcr, mdb, &omr)) {
147 /* Don't allow some fields to change by copying from master record */
148 strcpy(mr->VolumeName, omr.VolumeName);
149 strcpy(mr->MediaType, omr.MediaType);
150 mr->MediaId = omr.MediaId;
151 mr->PoolId = omr.PoolId;
152 mr->MaxVolBytes = omr.MaxVolBytes;
153 mr->VolCapacityBytes = omr.VolCapacityBytes;
154 mr->Recycle = omr.Recycle;
156 fseek(mdb->mediafd, omr.rec_addr, SEEK_SET);
157 if (fwrite(mr, len, 1, mdb->mediafd) != 1) {
158 Mmsg1(mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
161 fflush(mdb->mediafd);
167 int db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
174 Dmsg0(200, "In db_update_pool_record\n");
176 memcpy(&opr, pr, len);
178 if (!db_get_pool_record(jcr, mdb, &opr)) {
184 /* Update specific fields */
185 opr.NumVols = pr->NumVols;
186 opr.MaxVols = pr->MaxVols;
187 opr.UseOnce = pr->UseOnce;
188 opr.UseCatalog = pr->UseCatalog;
189 opr.AcceptAnyVolume = pr->AcceptAnyVolume;
190 strcpy(opr.LabelFormat, pr->LabelFormat);
192 fseek(mdb->poolfd, opr.rec_addr, SEEK_SET);
193 if (fwrite(&opr, len, 1, mdb->poolfd) != 1) {
194 Mmsg1(mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
197 memcpy(pr, &opr, len); /* return record written */
205 int db_add_digest_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *digest, int type)
210 int db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId)
215 int db_update_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr)
220 int db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
225 int db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
230 void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
235 #endif /* HAVE_BACULA_DB */