]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Print events when the Director has fixed Job catalog records during startup
authorEric Bollengier <eric@baculasystems.com>
Mon, 31 Aug 2020 08:48:48 +0000 (10:48 +0200)
committerEric Bollengier <eric@baculasystems.com>
Tue, 1 Mar 2022 14:36:17 +0000 (15:36 +0100)
bacula/src/cats/sql_cmds.c
bacula/src/cats/sql_cmds.h
bacula/src/dird/dird.c

index f5ea4ae6567ec116914e5cb578a738aeec38e956..2e50e2db16a76e85701f5ec71816061904d67e0a 100644 (file)
@@ -39,7 +39,8 @@ const char *get_restore_objects =
    "WHERE JobId IN (%s) "
      "AND ObjectType = %d "
    "ORDER BY ObjectIndex ASC";
-
+const char *get_created_running_job =
+   "SELECT JobId, Job, JobStatus FROM Job WHERE JobStatus IN ('C', 'R')";
 const char *cleanup_created_job =
    "UPDATE Job SET JobStatus='f', StartTime=SchedTime, EndTime=SchedTime "
    "WHERE JobStatus = 'C'";
index 3b54df11ae73e1506ab29251b9c7855e80fc5360..b8d6f0baad28e76a600b16d6a8b3dc2e44ac608e 100644 (file)
@@ -33,6 +33,7 @@ extern const char CATS_IMP_EXP *batch_lock_filename_query[];
 extern const char CATS_IMP_EXP *batch_lock_path_query[];
 extern const char CATS_IMP_EXP *batch_unlock_tables_query[];
 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 *client_backups;
index c841cb7c8cc7415328b21ed3a3d4d3d1ebe8a466..7dd43d8ca5896bee7b0377b3490d0fb7f90aa0c6 100644 (file)
@@ -422,6 +422,13 @@ int main (int argc, char *argv[])
    /* initialize a statistics collector */
    initialize_statcollector();
 
+   /* The check_catalog() can send events */
+   if (!test_config) {
+      /* Plug database interface for library routines */
+      p_sql_log = (sql_insert_log)dir_sql_log;
+      p_sql_event = (sql_insert_event)dir_sql_event;
+   }
+
    /* If we are in testing mode, we don't try to fix the catalog */
    cat_op mode=(test_config)?CHECK_CONNECTION:UPDATE_AND_FIX;
 
@@ -440,10 +447,6 @@ int main (int argc, char *argv[])
    update_trace_file_location(false);
    cleanup_old_files();
 
-   /* Plug database interface for library routines */
-   p_sql_log = (sql_insert_log)dir_sql_log;
-   p_sql_event = (sql_insert_event)dir_sql_event;
-
    FDConnectTimeout = (int)director->FDConnectTimeout;
    SDConnectTimeout = (int)director->SDConnectTimeout;
 
@@ -1342,6 +1345,20 @@ static bool check_resources()
    return OK;
 }
 
+
+/* Take note of all jobs to be canceled when we start the director 
+ * We don't send events directly here because the events might also
+ * be sent to the Catalog. Better to return a list of message.
+ */
+static int log_cleanup(void *ctx, int count, char **row)
+{
+   char buf[512];               /* 77 + 50 + 128 + 1 < 512 */
+   alist *events = (alist *)ctx;
+   bsnprintf(buf, sizeof(buf), "Cleanup Job %s \"%s\" JobStatus from %s to f (failed) during Director startup", row[0], row[1], row[2]);
+   events->append(bstrdup(buf));
+   return 0;
+}
+
 /*
  * In this routine,
  *  - we can check the connection (mode=CHECK_CONNECTION)
@@ -1660,8 +1677,17 @@ static bool check_catalog(cat_op mode)
       }
       /* cleanup old job records */
       if (mode == UPDATE_AND_FIX) {
+         alist events(100, not_owned_by_alist);
+         char *p;
+         db_sql_query(db, get_created_running_job, log_cleanup, &events);
          db_sql_query(db, cleanup_created_job, NULL, NULL);
          db_sql_query(db, cleanup_running_job, NULL, NULL);
+         foreach_alist(p, &events) {
+            events_send_msg(NULL, "DD0003", EVENTS_TYPE_DAEMON, "*Director*",
+                            (intptr_t)get_first_port_host_order(director->DIRaddrs),
+                            p);
+            free(p);
+         }
       }
 
       /* Set SQL engine name in global for debugging */