]> git.sur5r.net Git - bacula/bacula/commitdiff
- Correct bug I introduced into RunScripts enum.
authorKern Sibbald <kern@sibbald.com>
Mon, 10 Jul 2006 19:01:02 +0000 (19:01 +0000)
committerKern Sibbald <kern@sibbald.com>
Mon, 10 Jul 2006 19:01:02 +0000 (19:01 +0000)
- Add log table to Catalog
- Purge original job migrated if the migration terminates normally.
- Cleanup purging of files/jobs so that it is done only in a
  single subroutine.
- Add new VOLMGMT message class.
- Add Catalog message destination (user conf code remains to be written).

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3134 91ce42f0-d328-0410-95d8-f526ca767f89

19 files changed:
bacula/src/cats/make_mysql_tables.in
bacula/src/cats/make_postgresql_tables.in
bacula/src/cats/make_sqlite3_tables.in
bacula/src/cats/make_sqlite_tables.in
bacula/src/cats/update_mysql_tables.in
bacula/src/cats/update_postgresql_tables.in
bacula/src/cats/update_sqlite3_tables.in
bacula/src/cats/update_sqlite_tables.in
bacula/src/dird/autoprune.c
bacula/src/dird/dird.c
bacula/src/dird/migrate.c
bacula/src/dird/protos.h
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_prune.c
bacula/src/dird/ua_purge.c
bacula/src/lib/message.c
bacula/src/lib/message.h
bacula/src/lib/runscript.h
bacula/src/lib/tree.h

index 43cd01410093484edca84b162e5b0228415e4402..d2319f49c4924795ac6aa342ee6c674073995a8d 100644 (file)
@@ -240,6 +240,13 @@ CREATE TABLE Client (
    PRIMARY KEY(ClientId)
    );
 
+CREATE TABLE Log (
+   JobId INTEGER INTEGER UNSIGNED DEFAULT 0 REFERENCES JobId,
+   LogText BLOB NOT NULL,
+   INDEX (JobId)
+   );
+
+
 CREATE TABLE BaseFiles (
    BaseId INTEGER UNSIGNED AUTO_INCREMENT,
    BaseJobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
index 88c276642469336d58034a1eeba944194f39a10b..9641cd3da59e8ed081188640337e58f209969764 100644 (file)
@@ -245,6 +245,15 @@ CREATE TABLE client
 
 create unique index client_name_idx on client (name);
 
+CREATE TABLE Log
+(
+    JobId            serial      not null,
+    LogText          text        not null,
+);
+
+create index log_name_idx on Log (JobId);
+
+
 
 CREATE TABLE counters
 (
index f397fbd86fb1bbd1050df9ef20ae29e2534a31c5..3838ec31088735b579835cb64415a2e88ba406d6 100644 (file)
@@ -254,6 +254,13 @@ CREATE TABLE NextId (
    PRIMARY KEY (TableName)
    );
 
+CREATE TABLE Log  
+   JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
+   LogText TEXT NOT NULL,
+   KEY (JobId)
+   );
+
 -- Initialize JobId to start at 1
 INSERT INTO NextId (id, TableName) VALUES (1, "Job");
 
index f397fbd86fb1bbd1050df9ef20ae29e2534a31c5..3838ec31088735b579835cb64415a2e88ba406d6 100644 (file)
@@ -254,6 +254,13 @@ CREATE TABLE NextId (
    PRIMARY KEY (TableName)
    );
 
+CREATE TABLE Log  
+   JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
+   LogText TEXT NOT NULL,
+   KEY (JobId)
+   );
+
 -- Initialize JobId to start at 1
 INSERT INTO NextId (id, TableName) VALUES (1, "Job");
 
index 534eac78592b02b2cde56d7bcfaed879cbec09dc..7008e38cc1dcd5d32e0085f17f1b4105726cb794 100755 (executable)
@@ -26,6 +26,11 @@ ALTER TABLE JobMedia DROP ADD COLUMN Stripe;
 ALTER TABLE Job ADD COLUMN PriorJobId INTEGER UNSIGNED DEFAULT 0 REFERENCES Job;
 ALTER TABLE Job ADD COLUMN RealEndTime DATETIME DEFAULT 0;
 
+CREATE TABLE Log (
+   JobId INTEGER INTEGER UNSIGNED DEFAULT 0 REFERENCES JobId,
+   LogText BLOB NOT NULL,
+   INDEX (JobId)
+   );
 
 CREATE TABLE Location (
    LocationId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
index 88d4ed00d4fd976887ae766b01580451052bd4b4..03b8ee8ca0c512eb9bd32dfdbfafdc531396a3cc 100755 (executable)
@@ -42,6 +42,14 @@ CREATE TABLE Location (
    PRIMARY KEY (LocationId)
 );
 
+CREATE TABLE Log
+(
+    JobId            serial      not null,
+    LogText          text        not null,
+);
+
+create index log_name_idx on Log (JobId);
+
 
 DELETE FROM version;
 INSERT INTO version (versionId) VALUES (10);
index d0871e5b3a6564778c61fd62145fc1dbde8fa507..b40c9a8bccecc03293ab31d8307f0fe978588a5a 100755 (executable)
@@ -213,6 +213,12 @@ INSERT INTO Job SELECT
 
 DROP TABLE Job_backup;
 
+CREATE TABLE Log  
+   JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
+   LogText TEXT NOT NULL,
+   KEY (JobId)
+   );
+
 CREATE TABLE Location (
    LocationId INTEGER,
    Location VARCHAR(128) NOT NULL,
index d0871e5b3a6564778c61fd62145fc1dbde8fa507..b40c9a8bccecc03293ab31d8307f0fe978588a5a 100755 (executable)
@@ -213,6 +213,12 @@ INSERT INTO Job SELECT
 
 DROP TABLE Job_backup;
 
+CREATE TABLE Log  
+   JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
+   LogText TEXT NOT NULL,
+   KEY (JobId)
+   );
+
 CREATE TABLE Location (
    LocationId INTEGER,
    Location VARCHAR(128) NOT NULL,
index 0995b74ab67cd0a61d3d45d1065846b98bea6c62..0fea7f8a7608e6dd4e2e4eb2558fb1f332844250 100644 (file)
  * Auto Prune Jobs and Files. This is called at the end of every
  *   Job.  We do not prune volumes here.
  */
-int do_autoprune(JCR *jcr)
+void do_autoprune(JCR *jcr)
 {
    UAContext *ua;
    CLIENT *client;
    bool pruned;
 
    if (!jcr->client) {                /* temp -- remove me */
-      return 1;
+      return;
    }
 
    ua = new_ua_context(jcr);
@@ -71,7 +71,7 @@ int do_autoprune(JCR *jcr)
    }
 
    free_ua_context(ua);
-   return 1;
+   return;
 }
 
 /*
index 26af749a6afb015e6e6de8d30a3a6eb6e89fb6dc..2d0afc38f73e14e27af7d692559332e54926c122 100644 (file)
@@ -27,7 +27,8 @@
 /* Forward referenced subroutines */
 static void terminate_dird(int sig);
 static int check_resources();
-
+static void dir_sql_query(JCR *jcr, const char *cmd);
+  
 /* Exported subroutines */
 extern "C" void reload_config(int sig);
 extern void invalidate_schedules();
@@ -212,6 +213,9 @@ int main (int argc, char *argv[])
 
    my_name_is(0, NULL, director->hdr.name);    /* set user defined name */
 
+   /* Plug database interface for library routines */
+   p_sql_query = (sql_query)dir_sql_query;                                   
+
    FDConnectTimeout = (int)director->FDConnectTimeout;
    SDConnectTimeout = (int)director->SDConnectTimeout;
 
@@ -260,6 +264,14 @@ int main (int argc, char *argv[])
    return 0;
 }
 
+static void dir_sql_query(JCR *jcr, const char *cmd)
+{
+   if (!jcr || !jcr->db) {
+      return;
+   }
+   db_sql_query(jcr->db, cmd, NULL, NULL);
+}
+
 /* Cleanup and then exit */
 static void terminate_dird(int sig)
 {
@@ -566,13 +578,13 @@ static int check_resources()
          /* Handle RunScripts alists specifically */
          if (jobdefs->RunScripts) {
             RUNSCRIPT *rs, *elt;
-           
-           if (!job->RunScripts) {
-              job->RunScripts = New(alist(10, not_owned_by_alist));
-           }
-          
-           foreach_alist(rs, jobdefs->RunScripts) {
-              elt = copy_runscript(rs);
+            
+            if (!job->RunScripts) {
+               job->RunScripts = New(alist(10, not_owned_by_alist));
+            }
+           
+            foreach_alist(rs, jobdefs->RunScripts) {
+               elt = copy_runscript(rs);
                job->RunScripts->append(elt); /* we have to free it */
             }
          }
index defc5e504a00b3e448236ba01388ccf56ac1a9b9..24e8b113254474c0b4acbd07b81b67d595e00aa9 100644 (file)
@@ -271,11 +271,16 @@ bool do_migration(JCR *jcr)
    wait_for_storage_daemon_termination(jcr);
 
    set_jcr_job_status(jcr, jcr->SDJobStatus);
-   if (jcr->JobStatus == JS_Terminated) {
-      migration_cleanup(jcr, jcr->JobStatus);
-      return true;
+   if (jcr->JobStatus != JS_Terminated) {
+      return false;
    }
-   return false;
+   migration_cleanup(jcr, jcr->JobStatus);
+   if (prev_jcr) {
+      UAContext *ua = new_ua_context(jcr);
+      purge_files_from_job(ua, jcr->previous_jr.JobId);
+      free_ua_context(ua);
+   }
+   return true;
 }
 
 struct idpkt {
index 55e9dad4a1934202df0256990d3447806d7897f7..f24adf4a5c4510fecc62f948e4312a846c422c52 100644 (file)
@@ -4,7 +4,7 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000-2005 Kern Sibbald
+   Copyright (C) 2000-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -30,7 +30,7 @@ extern int authenticate_file_daemon(JCR *jcr);
 extern int authenticate_user_agent(UAContext *ua);
 
 /* autoprune.c */
-extern int do_autoprune(JCR *jcr);
+extern void do_autoprune(JCR *jcr);
 extern int prune_volumes(JCR *jcr);
 
 /* autorecycle.c */
@@ -235,7 +235,8 @@ bool prune_volume(UAContext *ua, MEDIA_DBR *mr);
 bool mark_media_purged(UAContext *ua, MEDIA_DBR *mr);
 void purge_files_from_volume(UAContext *ua, MEDIA_DBR *mr );
 int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr);
-void purge_files_from_job(UAContext *ua, JOB_DBR *jr);
+void purge_files_from_job(UAContext *ua, JobId_t JobId);
+void purge_job_from_catalog(UAContext *ua, JobId_t JobId);
 
 
 /* ua_run.c */
index 90b44cce687ee33309495bd0bcb516dc1c2ff28f..9869bb281e92c78df6555c2f20cf81dd84f6258b 100644 (file)
@@ -1237,23 +1237,15 @@ static void delete_job_id_range(UAContext *ua, char *tok)
 
 /*
  * do_job_delete now performs the actual delete operation atomically
- * we always return 1 because C++ is pissy about void functions
  */
 
 static void do_job_delete(UAContext *ua, JobId_t JobId)
 {
-   POOLMEM *query = get_pool_memory(PM_MESSAGE);
+   POOL_MEM query(PM_MESSAGE);
    char ed1[50];
 
-   Mmsg(query, "DELETE FROM Job WHERE JobId=%s", edit_int64(JobId, ed1));
-   db_sql_query(ua->db, query, NULL, (void *)NULL);
-   Mmsg(query, "DELETE FROM MAC WHERE JobId=%s", ed1);
-   db_sql_query(ua->db, query, NULL, (void *)NULL);
-   Mmsg(query, "DELETE FROM File WHERE JobId=%s", ed1);
-   db_sql_query(ua->db, query, NULL, (void *)NULL);
-   Mmsg(query, "DELETE FROM JobMedia WHERE JobId=%s", ed1);
-   db_sql_query(ua->db, query, NULL, (void *)NULL);
-   free_pool_memory(query);
+   purge_files_from_job(ua, JobId);
+   purge_job_from_catalog(ua, JobId);
    bsendmsg(ua, _("Job %s and associated records deleted from the catalog.\n"), edit_int64(JobId, ed1));
 }
 
index bfbaf8f748dfeb52b2bc82d59628a69769733b02..4e83cc50b7a4dcbc3579aefbfe03eb3c94c2c5d8 100644 (file)
@@ -42,8 +42,6 @@ extern const char *select_verify_del;
 extern const char *select_restore_del;
 extern const char *select_admin_del;
 extern const char *cnt_File;
-extern const char *del_File;
-extern const char *upd_Purged;
 extern const char *cnt_DelCand;
 extern const char *del_Job;
 extern const char *del_MAC;
@@ -270,18 +268,7 @@ int prune_files(UAContext *ua, CLIENT *client)
    db_sql_query(ua->db, query, file_delete_handler, (void *)&del);
 
    for (i=0; i < del.num_ids; i++) {
-      Mmsg(query, del_File, edit_int64(del.JobId[i], ed1));
-      Dmsg1(200, "Delete Files JobId=%s\n", ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      /*
-       * Now mark Job as having files purged. This is necessary to
-       * avoid having too many Jobs to process in future prunings. If
-       * we don't do this, the number of JobId's in our in memory list
-       * could grow very large.
-       */
-      Mmsg(query, upd_Purged, edit_int64(del.JobId[i], ed1));
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Dmsg1(200, "Update Purged sql=%s\n", query);
+      purge_files_from_job(ua, del.JobId[i]);
    }
    edit_uint64_with_commas(del.num_ids, ed1);
    bsendmsg(ua, _("Pruned Files from %s Jobs for client %s from catalog.\n"),
@@ -429,27 +416,10 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType)
     * Then delete the Job entry, and finally and JobMedia records.
     */
    for (i=0; i < del.num_ids; i++) {
-      edit_int64(del.JobId[i], ed1);
-      Dmsg1(050, "Delete JobId=%s\n", ed1);
       if (!del.PurgedFiles[i]) {
-         Mmsg(query, del_File, ed1);
-         if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) {
-            bsendmsg(ua, "%s", db_strerror(ua->db));
-         }
-         Dmsg1(050, "Del sql=%s\n", query);
+         purge_files_from_job(ua, del.JobId[i]);
       }
-
-      Mmsg(query, del_Job, ed1);
-      if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) {
-         bsendmsg(ua, "%s", db_strerror(ua->db));
-      }
-      Dmsg1(050, "Del sql=%s\n", query);
-
-      Mmsg(query, del_JobMedia, ed1);
-      if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) {
-         bsendmsg(ua, "%s", db_strerror(ua->db));
-      }
-      Dmsg1(050, "Del sql=%s\n", query);
+      purge_job_from_catalog(ua, del.JobId[i]);
    }
    bsendmsg(ua, _("Pruned %d %s for client %s from catalog.\n"), del.num_ids,
       del.num_ids==1?_("Job"):_("Jobs"), client->hdr.name);
@@ -554,17 +524,8 @@ bool prune_volume(UAContext *ua, MEDIA_DBR *mr)
       if (jr.JobTDate >= (now - period)) {
          continue;
       }
-      edit_int64(del.JobId[i], ed1);
-      Dmsg2(200, "Delete JobId=%s Job=%s\n", ed1, jr.Job);
-      Mmsg(query, del_File, ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Mmsg(query, del_Job, ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Mmsg(query, del_JobMedia, ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Mmsg(query, del_MAC, ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Dmsg1(050, "Del sql=%s\n", query);
+      purge_files_from_job(ua, del.JobId[i]);
+      purge_job_from_catalog(ua, del.JobId[i]);
       del.num_del++;
    }
    if (del.JobId) {
index 41a5c5634918c02ca65d7bc5408bbcb6100e7bd2..fd4bc81a69423cef897dfc5bfcfb790ea74cc482 100644 (file)
@@ -28,6 +28,9 @@
 #include "bacula.h"
 #include "dird.h"
 
+extern const char *del_File;
+extern const char *upd_Purged;
+
 /* Forward referenced functions */
 static int purge_files_from_client(UAContext *ua, CLIENT *client);
 static int purge_jobs_from_client(UAContext *ua, CLIENT *client);
@@ -191,7 +194,7 @@ int purgecmd(UAContext *ua, const char *cmd)
       case 0:                         /* Job */
       case 1:                         /* JobId */
          if (get_job_dbr(ua, &jr)) {
-            purge_files_from_job(ua, &jr);
+            purge_files_from_job(ua, jr.JobId);
          }
          return 1;
       case 2:                         /* client */
@@ -308,19 +311,7 @@ static int purge_files_from_client(UAContext *ua, CLIENT *client)
    db_sql_query(ua->db, query, file_delete_handler, (void *)&del);
 
    for (i=0; i < del.num_ids; i++) {
-      edit_int64(del.JobId[i], ed1);
-      Dmsg1(050, "Delete Files JobId=%s\n", ed1);
-      Mmsg(query, "DELETE FROM File WHERE JobId=%s", ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      /*
-       * Now mark Job as having files purged. This is necessary to
-       * avoid having too many Jobs to process in future prunings. If
-       * we don't do this, the number of JobId's in our in memory list
-       * will grow very large.
-       */
-      Mmsg(query, "UPDATE Job Set PurgedFiles=1 WHERE JobId=%s", ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Dmsg1(050, "Update Purged sql=%s\n", query);
+      purge_files_from_job(ua, del.JobId[i]);
    }
    bsendmsg(ua, _("%d Files for client \"%s\" purged from %s catalog.\n"), del.num_ids,
       client->hdr.name, client->catalog->hdr.name);
@@ -393,25 +384,11 @@ static int purge_jobs_from_client(UAContext *ua, CLIENT *client)
     * Then delete the Job entry, and finally and JobMedia records.
     */
    for (i=0; i < del.num_ids; i++) {
-      edit_int64(del.JobId[i], ed1);
       Dmsg1(050, "Delete Files JobId=%s\n", ed1); 
       if (!del.PurgedFiles[i]) {
-         Mmsg(query, "DELETE FROM File WHERE JobId=%s", ed1);
-         db_sql_query(ua->db, query, NULL, (void *)NULL);
-         Dmsg1(050, "Del sql=%s\n", query);
+         purge_files_from_job(ua, del.JobId[i]);
       }
-
-      Mmsg(query, "DELETE FROM Job WHERE JobId=%s", ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Dmsg1(050, "Delete Job sql=%s\n", query);
-
-      Mmsg(query, "DELETE FROM MAC WHERE JobId=%s", ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Dmsg1(050, "Delete MAC sql=%s\n", query);
-
-      Mmsg(query, "DELETE FROM JobMedia WHERE JobId=%s", ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Dmsg1(050, "Delete JobMedia sql=%s\n", query);
+      purge_job_from_catalog(ua, del.JobId[i]);
    }
    bsendmsg(ua, _("%d Jobs for client %s purged from %s catalog.\n"), del.num_ids,
       client->hdr.name, client->catalog->hdr.name);
@@ -427,19 +404,42 @@ bail_out:
    return 1;
 }
 
-void purge_files_from_job(UAContext *ua, JOB_DBR *jr)
+void purge_job_from_catalog(UAContext *ua, JobId_t JobId)
 {
-   POOLMEM *query = get_pool_memory(PM_MESSAGE);
+   POOL_MEM query(PM_MESSAGE);
    char ed1[50];
 
-   edit_int64(jr->JobId, ed1);
-   Mmsg(query, "DELETE FROM File WHERE JobId=%s", ed1);
-   db_sql_query(ua->db, query, NULL, (void *)NULL);
+   edit_int64(JobId, ed1);
+   Mmsg(query, "DELETE FROM Job WHERE JobId=%s", ed1);
+   db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
+   Dmsg1(050, "Delete Job sql=%s\n", query.c_str());
 
-   Mmsg(query, "UPDATE Job Set PurgedFiles=1 WHERE JobId=%s", ed1);
-   db_sql_query(ua->db, query, NULL, (void *)NULL);
+   Mmsg(query, "DELETE FROM JobMedia WHERE JobId=%s", ed1);
+   db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
+   Dmsg1(050, "Delete JobMedia sql=%s\n", query.c_str());
 
-   free_pool_memory(query);
+   Mmsg(query, "DELETE FROM Log WHERE JobId=%s", ed1);
+   db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
+   Dmsg1(050, "Delete Log sql=%s\n", query.c_str());
+
+}
+
+void purge_files_from_job(UAContext *ua, JobId_t JobId)
+{
+   POOL_MEM query(PM_MESSAGE);
+   char ed1[50];
+
+   edit_int64(JobId, ed1);
+   Mmsg(query, del_File, ed1);
+   db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
+
+   /*
+    * Now mark Job as having files purged. This is necessary to
+    * avoid having too many Jobs to process in future prunings. If
+    * we don't do this, the number of JobId's in our in memory list
+    * could grow very large.
+    */
+   Mmsg(query, upd_Purged, ed1);
 }
 
 void purge_files_from_volume(UAContext *ua, MEDIA_DBR *mr )
@@ -521,17 +521,8 @@ int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr)
    }
 
    for (i=0; i < del.num_ids; i++) {
-      edit_int64(del.JobId[i], ed1);
-      Dmsg1(050, "Delete JobId=%s\n", ed1);
-      Mmsg(query, "DELETE FROM File WHERE JobId=%s", ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Mmsg(query, "DELETE FROM Job WHERE JobId=%s", ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Mmsg(query, "DELETE FROM MAC WHERE JobId=%s", ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Mmsg(query, "DELETE FROM JobMedia WHERE JobId=%s", ed1);
-      db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Dmsg1(050, "Del sql=%s\n", query);
+      purge_files_from_job(ua, del.JobId[i]);
+      purge_job_from_catalog(ua, del.JobId[i]);
       del.num_del++;
    }
    if (del.JobId) {
index bac2f479da39e9a7b546f2f34098ad8661fc1d1c..93417d3a3f21712b5fb815f168020ce1e58bbf9e 100755 (executable)
@@ -26,6 +26,8 @@
 #include "bacula.h"
 #include "jcr.h"
 
+sql_query p_sql_query = NULL;
+
 #define FULL_LOCATION 1               /* set for file:line in Debug messages */
 
 /*
@@ -60,7 +62,7 @@ const char *host_os = HOST_OS;
 const char *distname = DISTNAME;
 const char *distver = DISTVER;
 static FILE *trace_fd = NULL;
-#ifdef HAVE_WIN32
+#if defined(HAVE_WIN32)
 static bool trace = true;
 #else
 static bool trace = false;
@@ -152,15 +154,12 @@ void
 init_msg(JCR *jcr, MSGS *msg)
 {
    DEST *d, *dnew, *temp_chain = NULL;
-#ifndef HAVE_WIN32
-   int i;
-#endif
 
    if (jcr == NULL && msg == NULL) {
       init_last_jobs_list();
    }
 
-#ifndef HAVE_WIN32
+#if defined(HAVE_WIN32)
    /*
     * Make sure we have fd's 0, 1, 2 open
     *  If we don't do this one of our sockets may open
@@ -169,6 +168,7 @@ init_msg(JCR *jcr, MSGS *msg)
     *
     */
    int fd;
+   int i;
    fd = open("/dev/null", O_RDONLY, 0644);
    if (fd > 2) {
       close(fd);
@@ -185,7 +185,7 @@ init_msg(JCR *jcr, MSGS *msg)
    if (msg == NULL) {
       daemon_msgs = (MSGS *)malloc(sizeof(MSGS));
       memset(daemon_msgs, 0, sizeof(MSGS));
-#ifndef HAVE_WIN32
+#if defined(HAVE_WIN32)
       for (i=1; i<=M_MAX; i++) {
          add_msg_dest(daemon_msgs, MD_STDOUT, i, NULL, NULL);
       }
@@ -577,7 +577,7 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg)
     }
 
     if (type == M_ABORT || type == M_ERROR_TERM) {
-#ifndef HAVE_WIN32
+#if !defined(HAVE_WIN32)
        fputs(dt, stdout);
        fputs(msg, stdout);         /* print this here to INSURE that it is printed */
        fflush(stdout);
@@ -595,6 +595,18 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg)
     for (d=msgs->dest_chain; d; d=d->next) {
        if (bit_is_set(type, d->msg_types)) {
           switch (d->dest_code) {
+             case MD_CATALOG:
+                char ed1[50];
+                if (!jcr || !jcr->db) {
+                   break;
+                }
+                if (p_sql_query) {
+                   POOL_MEM cmd(PM_MESSAGE);
+                   Mmsg(cmd, "INSERT INTO Log (JobId, LogText) VALUES (%s, '%s')",
+                         edit_int64(jcr->JobId, ed1), msg);
+                   p_sql_query(jcr, cmd.c_str());
+                }
+                break;
              case MD_CONSOLE:
                 Dmsg1(850, "CONSOLE for following msg: %s", msg);
                 if (!con_fd) {
index a9a6152229e0b7f385dafec8c52cf88a5cde654d..328dc588640e0a51d5ba5385bd4d372edc0a4e18 100644 (file)
@@ -33,6 +33,7 @@
 #undef  M_RESTORED
 #undef  M_SECURITY
 #undef  M_ALERT
+#undef  M_VOLMGMT
 
 /*
  * Most of these message levels are more or less obvious.
@@ -63,6 +64,7 @@
  *
  *  M_ALERT       For Tape Alert messages.
  *
+ *  M_VOLMGMT     Volume Management message
  */
 
 enum {
@@ -81,10 +83,11 @@ enum {
    M_TERM,                            /* Terminating daemon normally */
    M_RESTORED,                        /* ls -l of restored files */
    M_SECURITY,                        /* security violation */
-   M_ALERT                            /* tape alert messages */
+   M_ALERT,                           /* tape alert messages */
+   M_VOLMGMT                          /* Volume management messages */
 };
 
-#define M_MAX      M_ALERT            /* keep this updated ! */
+#define M_MAX      M_VOLMGMT          /* keep this updated ! */
 
 /* Define message destination structure */
 /* *** FIXME **** where should be extended to handle multiple values */
@@ -110,7 +113,8 @@ enum {
    MD_DIRECTOR,                       /* send message to the Director */
    MD_OPERATOR,                       /* email a single message to the operator */
    MD_CONSOLE,                        /* send msg to UserAgent or console */
-   MD_MAIL_ON_ERROR                   /* email messages if job errors */
+   MD_MAIL_ON_ERROR,                  /* email messages if job errors */
+   MD_CATALOG                         /* sent to catalog Log table */
 };
 
 /* Queued message item */
@@ -121,13 +125,15 @@ struct MQUEUE_ITEM {
    char msg[1];
 };
 
-
 void d_msg(const char *file, int line, int level, const char *fmt,...);
 void e_msg(const char *file, int line, int type, int level, const char *fmt,...);
 void Jmsg(JCR *jcr, int type, time_t mtime, const char *fmt,...);
 void Qmsg(JCR *jcr, int type, time_t mtime, const char *fmt,...);
 bool get_trace(void);
 
+typedef void (*sql_query)(JCR *jcr, const char *cmd);
+extern sql_query p_sql_query;
 
 extern int           DLL_IMP_EXP debug_level;
 extern int           DLL_IMP_EXP verbose;
index f50feb9699f411d944daa21f528b888aed3bed23..f6b2ed99a3d520ef894d9d77dde2c0d6bd3fa73c 100644 (file)
  */
 
 /* 
- * RUNSCRIPT->when can take following value : 
+ * RUNSCRIPT->when can take following bit values:
  */
 enum {
-   SCRIPT_Never  = 1,
-   SCRIPT_After  = 2,           /* AfterJob */
-   SCRIPT_Before = 3,           /* BeforeJob */
-   SCRIPT_Any    = 4            /* Before and After */
+   SCRIPT_Never  = 0,
+   SCRIPT_After  = (1<<0),      /* AfterJob */
+   SCRIPT_Before = (1<<1),      /* BeforeJob */
+   SCRIPT_Any    = SCRIPT_Before | SCRIPT_After
 };
 
 /*
index c5faa14945dfa5461d250aec7e45d10fc4a9e961..ffa697c218f8ffaa80d5666d7100cfcbd9128f12 100644 (file)
@@ -56,7 +56,8 @@ struct s_tree_node {
    unsigned int extract_dir: 1;       /* extract dir entry only */
    unsigned int hard_link: 1;         /* set if have hard link */
    unsigned int soft_link: 1;         /* set if is soft link */
-   unsigned int inserted: 1;          /* set when newly inserted */
+   unsigned int inserted: 1;          /* set when node newly inserted */
+   unsigned int loaded: 1;            /* set when the dir is in the tree */
    struct s_tree_node *parent;
    struct s_tree_node *next;          /* next hash of FileIndex */
 };
@@ -76,6 +77,7 @@ struct s_tree_root {
    unsigned int extract_dir: 1;       /* extract dir entry only */
    unsigned int have_link: 1;         /* set if have hard link */
    unsigned int inserted: 1;          /* set when newly inserted */
+   unsigned int loaded: 1;            /* set when the dir is in the tree */
    struct s_tree_node *parent;
    struct s_tree_node *next;          /* next hash of FileIndex */