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,
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
(
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");
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");
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,
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);
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,
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,
* 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);
}
free_ua_context(ua);
- return 1;
+ return;
}
/*
/* 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();
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;
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)
{
/* 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 */
}
}
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 {
* 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
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 */
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 */
/*
* 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));
}
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;
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"),
* 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);
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) {
#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);
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 */
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);
* 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);
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 )
}
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) {
#include "bacula.h"
#include "jcr.h"
+sql_query p_sql_query = NULL;
+
#define FULL_LOCATION 1 /* set for file:line in Debug messages */
/*
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;
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
*
*/
int fd;
+ int i;
fd = open("/dev/null", O_RDONLY, 0644);
if (fd > 2) {
close(fd);
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);
}
}
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);
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) {
#undef M_RESTORED
#undef M_SECURITY
#undef M_ALERT
+#undef M_VOLMGMT
/*
* Most of these message levels are more or less obvious.
*
* M_ALERT For Tape Alert messages.
*
+ * M_VOLMGMT Volume Management message
*/
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 */
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 */
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;
*/
/*
- * 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
};
/*
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 */
};
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 */