From ea215608c5a258f63390eb3a0dc8a6ae49586824 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 10 Jul 2006 19:01:02 +0000 Subject: [PATCH] - Correct bug I introduced into RunScripts enum. - 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 --- bacula/src/cats/make_mysql_tables.in | 7 ++ bacula/src/cats/make_postgresql_tables.in | 9 +++ bacula/src/cats/make_sqlite3_tables.in | 7 ++ bacula/src/cats/make_sqlite_tables.in | 7 ++ bacula/src/cats/update_mysql_tables.in | 5 ++ bacula/src/cats/update_postgresql_tables.in | 8 ++ bacula/src/cats/update_sqlite3_tables.in | 6 ++ bacula/src/cats/update_sqlite_tables.in | 6 ++ bacula/src/dird/autoprune.c | 6 +- bacula/src/dird/dird.c | 28 +++++-- bacula/src/dird/migrate.c | 13 ++- bacula/src/dird/protos.h | 7 +- bacula/src/dird/ua_cmds.c | 14 +--- bacula/src/dird/ua_prune.c | 49 ++---------- bacula/src/dird/ua_purge.c | 89 +++++++++------------ bacula/src/lib/message.c | 26 ++++-- bacula/src/lib/message.h | 14 +++- bacula/src/lib/runscript.h | 10 +-- bacula/src/lib/tree.h | 4 +- 19 files changed, 176 insertions(+), 139 deletions(-) diff --git a/bacula/src/cats/make_mysql_tables.in b/bacula/src/cats/make_mysql_tables.in index 43cd014100..d2319f49c4 100644 --- a/bacula/src/cats/make_mysql_tables.in +++ b/bacula/src/cats/make_mysql_tables.in @@ -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, diff --git a/bacula/src/cats/make_postgresql_tables.in b/bacula/src/cats/make_postgresql_tables.in index 88c2766424..9641cd3da5 100644 --- a/bacula/src/cats/make_postgresql_tables.in +++ b/bacula/src/cats/make_postgresql_tables.in @@ -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 ( diff --git a/bacula/src/cats/make_sqlite3_tables.in b/bacula/src/cats/make_sqlite3_tables.in index f397fbd86f..3838ec3108 100644 --- a/bacula/src/cats/make_sqlite3_tables.in +++ b/bacula/src/cats/make_sqlite3_tables.in @@ -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"); diff --git a/bacula/src/cats/make_sqlite_tables.in b/bacula/src/cats/make_sqlite_tables.in index f397fbd86f..3838ec3108 100644 --- a/bacula/src/cats/make_sqlite_tables.in +++ b/bacula/src/cats/make_sqlite_tables.in @@ -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"); diff --git a/bacula/src/cats/update_mysql_tables.in b/bacula/src/cats/update_mysql_tables.in index 534eac7859..7008e38cc1 100755 --- a/bacula/src/cats/update_mysql_tables.in +++ b/bacula/src/cats/update_mysql_tables.in @@ -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, diff --git a/bacula/src/cats/update_postgresql_tables.in b/bacula/src/cats/update_postgresql_tables.in index 88d4ed00d4..03b8ee8ca0 100755 --- a/bacula/src/cats/update_postgresql_tables.in +++ b/bacula/src/cats/update_postgresql_tables.in @@ -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); diff --git a/bacula/src/cats/update_sqlite3_tables.in b/bacula/src/cats/update_sqlite3_tables.in index d0871e5b3a..b40c9a8bcc 100755 --- a/bacula/src/cats/update_sqlite3_tables.in +++ b/bacula/src/cats/update_sqlite3_tables.in @@ -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, diff --git a/bacula/src/cats/update_sqlite_tables.in b/bacula/src/cats/update_sqlite_tables.in index d0871e5b3a..b40c9a8bcc 100755 --- a/bacula/src/cats/update_sqlite_tables.in +++ b/bacula/src/cats/update_sqlite_tables.in @@ -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, diff --git a/bacula/src/dird/autoprune.c b/bacula/src/dird/autoprune.c index 0995b74ab6..0fea7f8a76 100644 --- a/bacula/src/dird/autoprune.c +++ b/bacula/src/dird/autoprune.c @@ -39,14 +39,14 @@ * 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; } /* diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 26af749a6a..2d0afc38f7 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -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 */ } } diff --git a/bacula/src/dird/migrate.c b/bacula/src/dird/migrate.c index defc5e504a..24e8b11325 100644 --- a/bacula/src/dird/migrate.c +++ b/bacula/src/dird/migrate.c @@ -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 { diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 55e9dad4a1..f24adf4a5c 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -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 */ diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 90b44cce68..9869bb281e 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -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)); } diff --git a/bacula/src/dird/ua_prune.c b/bacula/src/dird/ua_prune.c index bfbaf8f748..4e83cc50b7 100644 --- a/bacula/src/dird/ua_prune.c +++ b/bacula/src/dird/ua_prune.c @@ -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) { diff --git a/bacula/src/dird/ua_purge.c b/bacula/src/dird/ua_purge.c index 41a5c56349..fd4bc81a69 100644 --- a/bacula/src/dird/ua_purge.c +++ b/bacula/src/dird/ua_purge.c @@ -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) { diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index bac2f479da..93417d3a3f 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -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) { diff --git a/bacula/src/lib/message.h b/bacula/src/lib/message.h index a9a6152229..328dc58864 100644 --- a/bacula/src/lib/message.h +++ b/bacula/src/lib/message.h @@ -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; diff --git a/bacula/src/lib/runscript.h b/bacula/src/lib/runscript.h index f50feb9699..f6b2ed99a3 100644 --- a/bacula/src/lib/runscript.h +++ b/bacula/src/lib/runscript.h @@ -37,13 +37,13 @@ */ /* - * 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 }; /* diff --git a/bacula/src/lib/tree.h b/bacula/src/lib/tree.h index c5faa14945..ffa697c218 100644 --- a/bacula/src/lib/tree.h +++ b/bacula/src/lib/tree.h @@ -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 */ -- 2.39.5