]> git.sur5r.net Git - bacula/bacula/commitdiff
ebl Add patch to cleanup orphaned jobs during startup
authorEric Bollengier <eric@eb.homelinux.org>
Thu, 19 Jun 2008 12:45:12 +0000 (12:45 +0000)
committerEric Bollengier <eric@eb.homelinux.org>
Thu, 19 Jun 2008 12:45:12 +0000 (12:45 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7174 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/patches/testing/cleanup_CR_catalog_at_start.patch [new file with mode: 0644]

diff --git a/bacula/patches/testing/cleanup_CR_catalog_at_start.patch b/bacula/patches/testing/cleanup_CR_catalog_at_start.patch
new file mode 100644 (file)
index 0000000..65e4a90
--- /dev/null
@@ -0,0 +1,107 @@
+This patch fixes all orphan jobs from catalog (Running/Created) during
+startup.
+
+This avoid phantom jobs with bweb or bat.
+
+  cd <bacula-source>
+  patch -p0 < cleanup_CR_catalog_at_start.patch
+  ./configure <your options>
+  make
+  ...
+  make install
+
+
+Index: src/dird/dird.c
+===================================================================
+--- src/dird/dird.c    (revision 7173)
++++ src/dird/dird.c    (working copy)
+@@ -40,6 +40,7 @@
+ /* Forward referenced subroutines */
+ void terminate_dird(int sig);
+ static bool check_resources();
++static void cleanup_catalog();
+ static bool check_catalog();
+ static void dir_sql_query(JCR *jcr, const char *cmd);
+   
+@@ -286,6 +287,8 @@
+    set_thread_concurrency(director->MaxConcurrentJobs * 2 +
+       4 /* UA */ + 4 /* sched+watchdog+jobsvr+misc */);
++   cleanup_catalog();                 /* cleanup old running jobs */
++
+    Dmsg0(200, "Start UA server\n");
+    start_UA_server(director->DIRaddrs);
+@@ -881,6 +884,37 @@
+    return OK;
+ }
++/* Cleanup old catalog records during starting */
++static void cleanup_catalog()
++{
++   CAT *catalog;
++   foreach_res(catalog, R_CATALOG) {
++      B_DB *db;
++      /*
++       * Make sure we can open catalog, otherwise print a warning
++       * message because the server is probably not running.
++       */
++      db = db_init(NULL, catalog->db_driver, catalog->db_name, catalog->db_user,
++                         catalog->db_password, catalog->db_address,
++                         catalog->db_port, catalog->db_socket,
++                         catalog->mult_db_connections);
++      if (!db || !db_open_database(NULL, db)) {
++         Pmsg2(000, _("Could not open Catalog \"%s\", database \"%s\".\n"),
++              catalog->name(), catalog->db_name);
++         Jmsg(NULL, M_FATAL, 0, _("Could not open Catalog \"%s\", database \"%s\".\n"),
++              catalog->name(), catalog->db_name);
++         if (db) {
++            Jmsg(NULL, M_FATAL, 0, _("%s"), db_strerror(db));
++            Pmsg1(000, "%s", db_strerror(db));
++            db_close_database(NULL, db);
++         }
++
++      } else {                            /* connection is OK */
++       db_cleanup_job_record(NULL, db); /* check if jobs are running ?? */
++      }
++   }
++}
++
+ static bool check_catalog()
+ {
+    bool OK = true;
+Index: src/cats/sql_update.c
+===================================================================
+--- src/cats/sql_update.c      (revision 7173)
++++ src/cats/sql_update.c      (working copy)
+@@ -288,6 +288,18 @@
+ }
+ bool
++db_cleanup_job_record(JCR *jcr, B_DB *mdb)
++{
++   int stat;
++   char query[] = "UPDATE Job SET JobStatus = 'f' WHERE JobStatus IN ('R', 'C')";
++
++   db_lock(mdb);
++   stat = UPDATE_DB(jcr, mdb, mdb->cmd);
++   db_unlock(mdb);
++   return stat;
++}
++
++bool
+ db_update_storage_record(JCR *jcr, B_DB *mdb, STORAGE_DBR *sr)
+ {
+    int stat;
+Index: src/cats/protos.h
+===================================================================
+--- src/cats/protos.h  (revision 7173)
++++ src/cats/protos.h  (working copy)
+@@ -123,6 +123,7 @@
+ void db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
+ /* sql_update.c */
++bool db_cleanup_job_record(JCR *jcr, B_DB *mdb);
+ bool db_update_job_start_record(JCR *jcr, B_DB *db, JOB_DBR *jr);
+ int  db_update_job_end_record(JCR *jcr, B_DB *db, JOB_DBR *jr, bool stats_enabled);
+ int  db_update_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr);