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-2006 Kern Sibbald
20 This program is free software; you can redistribute it and/or
21 modify it under the terms of the GNU General Public License
22 version 2 as amended with additional clauses defined in the
23 file LICENSE in the main source directory.
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
28 the file LICENSE for additional details.
33 /* The following is necessary so that we do not include
34 * the dummy external definition of DB.
36 #define __SQL_C /* indicate that this is sql.c */
44 /* -----------------------------------------------------------------------
46 * Bacula specific defines and subroutines
48 * -----------------------------------------------------------------------
53 * This is called at Job start time to add the
54 * most current start fields to the job record.
55 * It is assumed that you did a db_create_job_record() already.
57 bool db_update_job_start_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
64 Dmsg0(200, "In db_update_job_start_record\n");
66 memcpy(&ojr, jr, len);
68 if (!db_get_job_record(jcr, mdb, &ojr)) {
74 fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
75 if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
76 Mmsg1(mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
86 * This is called at Job termination time to add all the
87 * other fields to the job record.
89 int db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
96 Dmsg0(200, "In db_update_job_start_record\n");
98 memcpy(&ojr, jr, len);
100 if (!db_get_job_record(jcr, mdb, &ojr)) {
105 fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
106 if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
107 Mmsg1(&mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
117 int db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
124 Dmsg0(200, "In db_update_media_record\n");
127 memcpy(&omr, mr, len);
129 if (!db_get_media_record(jcr, mdb, &omr)) {
135 /* Don't allow some fields to change by copying from master record */
136 strcpy(mr->VolumeName, omr.VolumeName);
137 strcpy(mr->MediaType, omr.MediaType);
138 mr->MediaId = omr.MediaId;
139 mr->PoolId = omr.PoolId;
140 mr->MaxVolBytes = omr.MaxVolBytes;
141 mr->VolCapacityBytes = omr.VolCapacityBytes;
142 mr->Recycle = omr.Recycle;
144 fseek(mdb->mediafd, omr.rec_addr, SEEK_SET);
145 if (fwrite(mr, len, 1, mdb->mediafd) != 1) {
146 Mmsg1(mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
149 fflush(mdb->mediafd);
155 int db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
162 Dmsg0(200, "In db_update_pool_record\n");
164 memcpy(&opr, pr, len);
166 if (!db_get_pool_record(jcr, mdb, &opr)) {
172 /* Update specific fields */
173 opr.NumVols = pr->NumVols;
174 opr.MaxVols = pr->MaxVols;
175 opr.UseOnce = pr->UseOnce;
176 opr.UseCatalog = pr->UseCatalog;
177 opr.AcceptAnyVolume = pr->AcceptAnyVolume;
178 strcpy(opr.LabelFormat, pr->LabelFormat);
180 fseek(mdb->poolfd, opr.rec_addr, SEEK_SET);
181 if (fwrite(&opr, len, 1, mdb->poolfd) != 1) {
182 Mmsg1(mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
185 memcpy(pr, &opr, len); /* return record written */
193 int db_add_digest_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *digest, int type)
198 int db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId)
203 int db_update_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr)
208 int db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
213 int db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
218 void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
223 #endif /* HAVE_BACULA_DB */