* 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
*/
JobId_t run_job(JCR *jcr)
{
- int stat, errstat;
- JobId_t JobId = 0;
+ int stat;
+ if (setup_job(jcr)) {
+ /* Queue the job to be run */
+ if ((stat = jobq_add(&job_queue, jcr)) != 0) {
+ berrno be;
+ Jmsg(jcr, M_FATAL, 0, _("Could not add job queue: ERR=%s\n"), be.strerror(stat));
+ return 0;
+ }
+ return jcr->JobId;
+ }
+ return 0;
+}
+
+bool setup_job(JCR *jcr)
+{
+ int errstat;
P(jcr->mutex);
sm_check(__FILE__, __LINE__, true);
Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
goto bail_out;
}
- JobId = jcr->JobId = jcr->jr.JobId;
+ jcr->JobId = jcr->jr.JobId;
Dmsg4(100, "Created job record JobId=%d Name=%s Type=%c Level=%c\n",
jcr->JobId, jcr->Job, jcr->jr.JobType, jcr->jr.JobLevel);
Dmsg0(200, "Add jrc to work queue\n");
- /* Queue the job to be run */
- if ((stat = jobq_add(&job_queue, jcr)) != 0) {
- berrno be;
- Jmsg(jcr, M_FATAL, 0, _("Could not add job queue: ERR=%s\n"), be.strerror(stat));
- JobId = 0;
- goto bail_out;
- }
- Dmsg0(100, "Done run_job()\n");
V(jcr->mutex);
- return JobId;
+ return true;
bail_out:
if (jcr->fname) {
jcr->fname = NULL;
}
V(jcr->mutex);
- return JobId;
+ return false;
}
return true;
default:
-
/* Cancel File daemon */
if (jcr->file_bsock) {
ua->jcr->client = jcr->client;
/* Cancel Storage daemon */
if (jcr->store_bsock) {
if (!ua->jcr->storage) {
- copy_storage(ua->jcr, jcr);
+ copy_storage(ua->jcr, jcr->storage);
} else {
set_storage(ua->jcr, jcr->store);
}
static void job_monitor_destructor(watchdog_t *self)
{
- JCR *control_jcr = (JCR *) self->data;
+ JCR *control_jcr = (JCR *)self->data;
free_jcr(control_jcr);
}
if (jcr->JobId == 0) {
Dmsg2(800, "Skipping JCR %p (%s) with JobId 0\n",
jcr, jcr->Job);
- /* Keep reference counts correct */
- free_jcr(jcr);
continue;
}
cancel_job(ua, jcr);
free_ua_context(ua);
- Dmsg1(800, "Have cancelled JCR %p\n", jcr);
+ Dmsg2(800, "Have cancelled JCR %p Job=%d\n", jcr, jcr->JobId);
}
/* Keep reference counts correct */
- free_jcr(jcr);
}
+ endeach_jcr(jcr);
}
/*
*/
void set_jcr_defaults(JCR *jcr, JOB *job)
{
- STORE *st;
jcr->job = job;
jcr->JobType = job->JobType;
switch (jcr->JobType) {
}
jcr->JobPriority = job->Priority;
/* Copy storage definitions -- deleted in dir_free_jcr above */
- if (job->storage) {
- if (jcr->storage) {
- delete jcr->storage;
- }
- jcr->storage = New(alist(10, not_owned_by_alist));
- foreach_alist(st, job->storage) {
- jcr->storage->append(st);
- }
- }
- if (jcr->storage) {
- jcr->store = (STORE *)jcr->storage->first();
- }
+ copy_storage(jcr, job->storage);
jcr->client = job->client;
if (!jcr->client_name) {
jcr->client_name = get_pool_memory(PM_NAME);
}
}
-/*
- * copy the storage definitions from an old JCR to a new one
+
+/*
+ * Copy the storage definitions from an alist to the JCR
*/
-void copy_storage(JCR *new_jcr, JCR *old_jcr)
+void copy_storage(JCR *jcr, alist *storage)
{
- if (old_jcr->storage) {
+ if (storage) {
STORE *st;
- if (old_jcr->storage) {
- delete old_jcr->storage;
+ if (jcr->storage) {
+ delete jcr->storage;
}
- new_jcr->storage = New(alist(10, not_owned_by_alist));
- foreach_alist(st, old_jcr->storage) {
- new_jcr->storage->append(st);
+ jcr->storage = New(alist(10, not_owned_by_alist));
+ foreach_alist(st, storage) {
+ jcr->storage->append(st);
}
- }
- if (old_jcr->store) {
- new_jcr->store = old_jcr->store;
- } else if (new_jcr->storage) {
- new_jcr->store = (STORE *)new_jcr->storage->first();
+ }
+ if (jcr->storage) {
+ jcr->store = (STORE *)jcr->storage->first();
}
}
+
/* Set storage override */
void set_storage(JCR *jcr, STORE *store)
{
/* Store not in list, so add it */
jcr->storage->prepend(store);
}
+
+void create_clones(JCR *jcr)
+{
+ /*
+ * Fire off any clone jobs (run directives)
+ */
+ Dmsg2(900, "cloned=%d run_cmds=%p\n", jcr->cloned, jcr->job->run_cmds);
+ if (!jcr->cloned && jcr->job->run_cmds) {
+ char *runcmd;
+ JOB *job = jcr->job;
+ POOLMEM *cmd = get_pool_memory(PM_FNAME);
+ UAContext *ua = new_ua_context(jcr);
+ ua->batch = true;
+ foreach_alist(runcmd, job->run_cmds) {
+ cmd = edit_job_codes(jcr, cmd, runcmd, "");
+ Mmsg(ua->cmd, "run %s cloned=yes", cmd);
+ Dmsg1(900, "=============== Clone cmd=%s\n", ua->cmd);
+ parse_ua_args(ua); /* parse command */
+ int stat = run_cmd(ua, ua->cmd);
+ if (stat == 0) {
+ Jmsg(jcr, M_ERROR, 0, _("Could not start clone job.\n"));
+ } else {
+ Jmsg(jcr, M_INFO, 0, _("Clone JobId %d started.\n"), stat);
+ }
+ }
+ free_ua_context(ua);
+ free_pool_memory(cmd);
+ }
+}
+
+bool create_restore_bootstrap_file(JCR *jcr)
+{
+ RESTORE_CTX rx;
+ UAContext *ua;
+ memset(&rx, 0, sizeof(rx));
+ rx.bsr = new_bsr();
+ rx.JobIds = "";
+ rx.bsr->JobId = jcr->target_jr.JobId;
+ ua = new_ua_context(jcr);
+ complete_bsr(ua, rx.bsr);
+ rx.bsr->fi = new_findex();
+ rx.bsr->fi->findex = 1;
+ rx.bsr->fi->findex2 = jcr->target_jr.JobFiles;
+ jcr->ExpectedFiles = write_bsr_file(ua, rx);
+ if (jcr->ExpectedFiles == 0) {
+ free_ua_context(ua);
+ free_bsr(rx.bsr);
+ return false;
+ }
+ if (jcr->RestoreBootstrap) {
+ free(jcr->RestoreBootstrap);
+ }
+ POOLMEM *fname = get_pool_memory(PM_MESSAGE);
+ make_unique_restore_filename(ua, &fname);
+ jcr->RestoreBootstrap = bstrdup(fname);
+ free_ua_context(ua);
+ free_bsr(rx.bsr);
+ free_pool_memory(fname);
+ jcr->needs_sd = true;
+ return true;
+}