]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #9035 Sync the Job and JobHisto table when "update stats" is issued
authorEric Bollengier <eric@baculasystems.com>
Tue, 12 Apr 2022 16:08:43 +0000 (18:08 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:58 +0000 (13:56 +0200)
bacula/src/cats/sql_cmds.c
bacula/src/cats/sql_cmds.h
bacula/src/dird/ua_update.c

index 756dc6a2ca42116690ae1c29f0a69acf6be470a5..610d0bb97cd08195261d84c154e66981aea01ba3 100644 (file)
@@ -47,6 +47,21 @@ const char *cleanup_created_job =
 const char *cleanup_running_job = 
    "UPDATE Job SET JobStatus='f', EndTime=StartTime WHERE JobStatus = 'R'";
 
+const char *sync_jobhisto_def = "UPDATE JobHisto SET PurgedFiles=Job.PurgedFiles, HasCache=Job.HasCache,Reviewed=Job.Reviewed "
+    "FROM Job WHERE Job.JobId=JobHisto.JobId and Job.Job = JobHisto.Job "
+      "AND (Job.HasCache <> JobHisto.HasCache OR Job.PurgedFiles <> JobHisto.PurgedFiles OR Job.Reviewed <> JobHisto.Reviewed)";
+const char *sync_jobhisto[] =
+{
+   // MySQL
+   "UPDATE JobHisto JOIN Job USING (JobId) SET JobHisto.PurgedFiles=Job.PurgedFiles, JobHisto.HasCache=Job.HasCache, JobHisto.Reviewed=Job.Reviewed "
+   "WHERE Job.JobId=JobHisto.JobId and Job.Job = JobHisto.Job "
+   "AND (Job.HasCache <> JobHisto.HasCache OR Job.PurgedFiles <> JobHisto.PurgedFiles OR Job.Reviewed <> JobHisto.Reviewed)",
+   // PostgreSQL
+   sync_jobhisto_def,
+   // SQLite
+   sync_jobhisto_def
+};
+
 /* For sql_update.c db_update_stats */
 const char *fill_jobhisto =
         "INSERT INTO JobHisto (JobId, Job, Name, Type, Level,"
index 641952c7490027e004e2d33408473b61f6d6ee79..2f78896bd11c9d9d1abb9f0a6ab075f98686f730 100644 (file)
@@ -36,6 +36,7 @@ extern const char CATS_IMP_EXP *bvfs_select_delta_version_with_basejob_and_delta
 extern const char CATS_IMP_EXP *get_created_running_job;
 extern const char CATS_IMP_EXP *cleanup_created_job;
 extern const char CATS_IMP_EXP *cleanup_running_job;
+extern const char CATS_IMP_EXP *sync_jobhisto[];
 extern const char CATS_IMP_EXP *client_backups;
 extern const char CATS_IMP_EXP *cnt_File;
 extern const char CATS_IMP_EXP *create_delindex;
index 16dbb78db586d5c9910c4db36b6c9f1d3c7ffbc2..927ed922419ed6f6b29751198558a4e6a5e2482c 100644 (file)
@@ -882,6 +882,11 @@ static bool update_stats(UAContext *ua)
    int nb = db_update_stats(ua->jcr, ua->db, since);
    ua->info_msg(_("Updating %i job(s).\n"), nb);
 
+   /* Can be removed in 2024. This is a workaround for a minor issue
+    * about the "update stats" command.
+    */
+   db_sql_query(ua->db, sync_jobhisto[db_get_type_index(ua->db)], NULL, NULL);
+
    return true;
 }