extern void term_ua_server();
/* Imported variables */
-extern time_t watchdog_time;
jobq_t job_queue;
goto bail_out;
}
- Dmsg0(200, "Add jrc to work queue\n");
- return true;
-
-bail_out:
- return false;
-}
-
-
-/*
- * This is the engine called by jobq.c:jobq_add() when we were pulled
- * from the work queue.
- * At this point, we are running in our own thread and all
- * necessary resources are allocated -- see jobq.c
- */
-static void *job_thread(void *arg)
-{
- JCR *jcr = (JCR *)arg;
-
- jcr->my_thread_id = pthread_self();
- pthread_detach(jcr->my_thread_id);
- sm_check(__FILE__, __LINE__, true);
-
- Dmsg0(200, "=====Start Job=========\n");
- jcr->start_time = time(NULL); /* set the real start time */
- jcr->jr.StartTime = jcr->start_time;
-
- if (jcr->job->MaxStartDelay != 0 && jcr->job->MaxStartDelay <
- (utime_t)(jcr->start_time - jcr->sched_time)) {
- Jmsg(jcr, M_FATAL, 0, _("Job canceled because max start delay time exceeded.\n"));
- set_jcr_job_status(jcr, JS_Canceled);
- }
-
- /* TODO : check if it is used somewhere */
- if (jcr->job->RunScripts == NULL)
- {
- Dmsg0(200, "Warning, job->RunScripts is empty\n");
- jcr->job->RunScripts = New(alist(10, not_owned_by_alist));
- }
-
- /*
- * Note, we continue, even if the job is canceled above. This
- * will permit proper setting of the job start record and
- * the error (cancel) will be picked up below.
- */
-
- generate_job_event(jcr, "JobInit");
- set_jcr_job_status(jcr, JS_Running); /* this will be set only if no error */
-
/*
* Now, do pre-run stuff, like setting job level (Inc/diff, ...)
break;
}
+ generate_job_event(jcr, "JobInit");
+
+ Dmsg0(200, "Add jrc to work queue\n");
+ return true;
+
+bail_out:
+ return false;
+}
+
+
+/*
+ * This is the engine called by jobq.c:jobq_add() when we were pulled
+ * from the work queue.
+ * At this point, we are running in our own thread and all
+ * necessary resources are allocated -- see jobq.c
+ */
+static void *job_thread(void *arg)
+{
+ JCR *jcr = (JCR *)arg;
+
+ jcr->my_thread_id = pthread_self();
+ pthread_detach(jcr->my_thread_id);
+ sm_check(__FILE__, __LINE__, true);
+
+ Dmsg0(200, "=====Start Job=========\n");
+ set_jcr_job_status(jcr, JS_Running); /* this will be set only if no error */
+ jcr->start_time = time(NULL); /* set the real start time */
+ jcr->jr.StartTime = jcr->start_time;
+
+ if (jcr->job->MaxStartDelay != 0 && jcr->job->MaxStartDelay <
+ (utime_t)(jcr->start_time - jcr->sched_time)) {
+ Jmsg(jcr, M_FATAL, 0, _("Job canceled because max start delay time exceeded.\n"));
+ set_jcr_job_status(jcr, JS_Canceled);
+ }
+
+ /* TODO : check if it is used somewhere */
+ if (jcr->job->RunScripts == NULL) {
+ Dmsg0(200, "Warning, job->RunScripts is empty\n");
+ jcr->job->RunScripts = New(alist(10, not_owned_by_alist));
+ }
+
if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
}
+ /* Run any script BeforeJob on dird */
+ run_scripts(jcr, jcr->job->RunScripts, "BeforeJob");
+
if (job_canceled(jcr)) {
update_job_end_record(jcr);
- } else {
- /* Run any script BeforeJob on dird */
- run_scripts(jcr, jcr->job->RunScripts, "BeforeJob");
+ } else {
/*
* We re-update the job start record so that the start
* time is set after the run before job. This avoids
run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
/* Send off any queued messages */
- if (jcr->msg_queue->size() > 0) {
+ if (jcr->msg_queue && jcr->msg_queue->size() > 0) {
dequeue_messages(jcr);
}
}
/* Cancel Storage daemon */
if (jcr->store_bsock) {
- if (!ua->jcr->storage) {
- copy_storage(ua->jcr, jcr->storage, _("Job resource"));
+ if (!ua->jcr->wstorage) {
+ if (jcr->rstorage) {
+ copy_wstorage(ua->jcr, jcr->rstorage, _("Job resource"));
+ } else {
+ copy_wstorage(ua->jcr, jcr->wstorage, _("Job resource"));
+ }
} else {
- set_storage(ua->jcr, jcr->store);
+ if (jcr->rstorage) {
+ set_wstorage(ua->jcr, jcr->rstore);
+ } else {
+ set_wstorage(ua->jcr, jcr->wstore);
+ }
}
if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
unsigned char digest[MD5HashSize];
memcpy(&md5c, &jcr->fileset->md5c, sizeof(md5c));
MD5Final(digest, &md5c);
- bin_to_base64(fsr.MD5, (char *)digest, MD5HashSize);
+ /*
+ * Keep the flag (last arg) set to false otherwise old FileSets will
+ * get new MD5 sums and the user will get Full backups on everything
+ */
+ bin_to_base64(fsr.MD5, sizeof(fsr.MD5), (char *)digest, MD5HashSize, false);
bstrncpy(jcr->fileset->MD5, fsr.MD5, sizeof(jcr->fileset->MD5));
} else {
Jmsg(jcr, M_WARNING, 0, _("FileSet MD5 digest not found.\n"));
V(mutex); /* allow creation of jobs */
jcr->start_time = now;
/* Form Unique JobName */
- localtime_r(&now, &tm);
+ (void)localtime_r(&now, &tm);
/* Use only characters that are permitted in Windows filenames */
strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm);
bstrncpy(name, base_name, sizeof(name));
}
/* Delete lists setup to hold storage pointers */
- if (jcr->storage) {
- delete jcr->storage;
- }
+ free_rwstorage(jcr);
+
jcr->job_end_push.destroy();
Dmsg0(200, "End dird free_jcr\n");
}
}
jcr->JobPriority = job->Priority;
/* Copy storage definitions -- deleted in dir_free_jcr above */
- copy_storage(jcr, job->storage, _("Job resource"));
+ copy_rwstorage(jcr, job->storage, _("Job resource"));
jcr->client = job->client;
if (!jcr->client_name) {
jcr->client_name = get_pool_memory(PM_NAME);
}
}
+/*
+ * Copy the storage definitions from an alist to the JCR
+ */
+void copy_rwstorage(JCR *jcr, alist *storage, const char *where)
+{
+ copy_rstorage(jcr, storage, where);
+ copy_wstorage(jcr, storage, where);
+}
+
+
+/* Set storage override */
+void set_rwstorage(JCR *jcr, STORE *store)
+{
+ set_rstorage(jcr, store);
+ set_wstorage(jcr, store);
+}
+
+void free_rwstorage(JCR *jcr)
+{
+ free_rstorage(jcr);
+ free_wstorage(jcr);
+}
/*
* Copy the storage definitions from an alist to the JCR
*/
-void copy_storage(JCR *jcr, alist *storage, const char *where)
+void copy_rstorage(JCR *jcr, alist *storage, const char *where)
{
if (storage) {
STORE *st;
- if (jcr->storage) {
- delete jcr->storage;
+ if (jcr->rstorage) {
+ delete jcr->rstorage;
}
- jcr->storage = New(alist(10, not_owned_by_alist));
+ jcr->rstorage = New(alist(10, not_owned_by_alist));
foreach_alist(st, storage) {
- jcr->storage->append(st);
+ jcr->rstorage->append(st);
}
pm_strcpy(jcr->storage_source, where);
}
- if (jcr->storage) {
- jcr->store = (STORE *)jcr->storage->first();
+ if (jcr->rstorage) {
+ jcr->rstore = (STORE *)jcr->rstorage->first();
}
}
/* Set storage override */
-void set_storage(JCR *jcr, STORE *store)
+void set_rstorage(JCR *jcr, STORE *store)
{
STORE *storage;
- jcr->store = store;
- foreach_alist(storage, jcr->storage) {
+ jcr->rstore = store;
+ foreach_alist(storage, jcr->rstorage) {
if (store == storage) {
return;
}
}
/* Store not in list, so add it */
- jcr->storage->prepend(store);
+ jcr->rstorage->prepend(store);
}
+void free_rstorage(JCR *jcr)
+{
+ if (jcr->rstorage) {
+ delete jcr->rstorage;
+ jcr->rstorage = NULL;
+ }
+ jcr->rstore = NULL;
+}
+
+/*
+ * Copy the storage definitions from an alist to the JCR
+ */
+void copy_wstorage(JCR *jcr, alist *storage, const char *where)
+{
+ if (storage) {
+ STORE *st;
+ if (jcr->wstorage) {
+ delete jcr->wstorage;
+ }
+ jcr->wstorage = New(alist(10, not_owned_by_alist));
+ foreach_alist(st, storage) {
+ jcr->wstorage->append(st);
+ }
+ pm_strcpy(jcr->storage_source, where);
+ }
+ if (jcr->wstorage) {
+ jcr->wstore = (STORE *)jcr->wstorage->first();
+ }
+}
+
+
+/* Set storage override */
+void set_wstorage(JCR *jcr, STORE *store)
+{
+ STORE *storage;
+
+ jcr->wstore = store;
+ foreach_alist(storage, jcr->wstorage) {
+ if (store == storage) {
+ return;
+ }
+ }
+ /* Store not in list, so add it */
+ jcr->wstorage->prepend(store);
+}
+
+void free_wstorage(JCR *jcr)
+{
+ if (jcr->wstorage) {
+ delete jcr->wstorage;
+ jcr->wstorage = NULL;
+ }
+ jcr->wstore = NULL;
+}
+
+
+
void create_clones(JCR *jcr)
{
/*