3 * Bacula Director Job processing routines
5 * Kern Sibbald, October MM
10 Copyright (C) 2000-2005 Kern Sibbald
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of
15 the License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public
23 License along with this program; if not, write to the Free
24 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32 /* Forward referenced subroutines */
33 static void *job_thread(void *arg);
34 static void job_monitor_watchdog(watchdog_t *self);
35 static void job_monitor_destructor(watchdog_t *self);
36 static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr);
37 static bool job_check_maxruntime(JCR *control_jcr, JCR *jcr);
39 /* Exported subroutines */
41 /* Imported subroutines */
42 extern void term_scheduler();
43 extern void term_ua_server();
45 /* Imported variables */
46 extern time_t watchdog_time;
50 void init_job_server(int max_workers)
55 if ((stat = jobq_init(&job_queue, max_workers, job_thread)) != 0) {
57 Emsg1(M_ABORT, 0, _("Could not init job queue: ERR=%s\n"), be.strerror(stat));
59 if ((wd = new_watchdog()) == NULL) {
60 Emsg0(M_ABORT, 0, _("Could not init job monitor watchdogs\n"));
62 wd->callback = job_monitor_watchdog;
63 wd->destructor = job_monitor_destructor;
66 wd->data = new_control_jcr("*JobMonitor*", JT_SYSTEM);
67 register_watchdog(wd);
70 void term_job_server()
72 jobq_destroy(&job_queue); /* ignore any errors */
76 * Run a job -- typically called by the scheduler, but may also
77 * be called by the UA (Console program).
79 * Returns: 0 on failure
83 JobId_t run_job(JCR *jcr)
89 sm_check(__FILE__, __LINE__, true);
90 init_msg(jcr, jcr->messages);
92 /* Initialize termination condition variable */
93 if ((errstat = pthread_cond_init(&jcr->term_wait, NULL)) != 0) {
95 Jmsg1(jcr, M_FATAL, 0, _("Unable to init job cond variable: ERR=%s\n"), be.strerror(errstat));
98 jcr->term_wait_inited = true;
103 Dmsg0(50, "Open database\n");
104 jcr->db=db_init_database(jcr, jcr->catalog->db_name, jcr->catalog->db_user,
105 jcr->catalog->db_password, jcr->catalog->db_address,
106 jcr->catalog->db_port, jcr->catalog->db_socket,
107 jcr->catalog->mult_db_connections);
108 if (!jcr->db || !db_open_database(jcr, jcr->db)) {
109 Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"),
110 jcr->catalog->db_name);
112 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
116 Dmsg0(50, "DB opened\n");
121 create_unique_job_name(jcr, jcr->job->hdr.name);
122 set_jcr_job_status(jcr, JS_Created);
123 init_jcr_job_record(jcr);
124 if (!db_create_job_record(jcr, jcr->db, &jcr->jr)) {
125 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
128 JobId = jcr->JobId = jcr->jr.JobId;
130 Dmsg4(100, "Created job record JobId=%d Name=%s Type=%c Level=%c\n",
131 jcr->JobId, jcr->Job, jcr->jr.JobType, jcr->jr.JobLevel);
133 if (!get_or_create_client_record(jcr)) {
138 jcr->fname = get_pool_memory(PM_FNAME);
141 /* Now, do pre-run stuff, like setting job level (Inc/diff, ...) */
142 switch (jcr->JobType) {
144 if (!do_backup_init(jcr)) {
145 backup_cleanup(jcr, JS_ErrorTerminated);
149 if (!do_verify_init(jcr)) {
150 verify_cleanup(jcr, JS_ErrorTerminated);
154 if (!do_restore_init(jcr)) {
155 restore_cleanup(jcr, JS_ErrorTerminated);
159 if (!do_admin_init(jcr)) {
160 admin_cleanup(jcr, JS_ErrorTerminated);
166 if (!do_mac_init(jcr)) { /* migration, archive, copy */
167 mac_cleanup(jcr, JS_ErrorTerminated);
171 Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
172 set_jcr_job_status(jcr, JS_ErrorTerminated);
175 if (job_canceled(jcr)) {
179 Dmsg0(200, "Add jrc to work queue\n");
181 /* Queue the job to be run */
182 if ((stat = jobq_add(&job_queue, jcr)) != 0) {
184 Jmsg(jcr, M_FATAL, 0, _("Could not add job queue: ERR=%s\n"), be.strerror(stat));
188 Dmsg0(100, "Done run_job()\n");
195 free_memory(jcr->fname);
205 * This is the engine called by jobq.c:jobq_add() when we were pulled
206 * from the work queue.
207 * At this point, we are running in our own thread and all
208 * necessary resources are allocated -- see jobq.c
210 static void *job_thread(void *arg)
212 JCR *jcr = (JCR *)arg;
214 jcr->my_thread_id = pthread_self();
215 pthread_detach(jcr->my_thread_id);
216 sm_check(__FILE__, __LINE__, true);
219 Dmsg0(200, "=====Start Job=========\n");
220 jcr->start_time = time(NULL); /* set the real start time */
221 jcr->jr.StartTime = jcr->start_time;
222 set_jcr_job_status(jcr, JS_Running);
223 if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
224 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
227 if (job_canceled(jcr)) {
228 update_job_end_record(jcr);
229 } else if (jcr->job->MaxStartDelay != 0 && jcr->job->MaxStartDelay <
230 (utime_t)(jcr->start_time - jcr->sched_time)) {
231 Jmsg(jcr, M_FATAL, 0, _("Job canceled because max start delay time exceeded.\n"));
232 set_jcr_job_status(jcr, JS_Canceled);
233 update_job_end_record(jcr);
237 generate_event(jcr, "StartJob");
238 if (jcr->job->RunBeforeJob) {
239 POOLMEM *before = get_pool_memory(PM_FNAME);
242 char line[MAXSTRING];
244 before = edit_job_codes(jcr, before, jcr->job->RunBeforeJob, "");
245 bpipe = open_bpipe(before, 0, "r");
246 free_pool_memory(before);
247 while (fgets(line, sizeof(line), bpipe->rfd)) {
248 Jmsg(jcr, M_INFO, 0, _("RunBefore: %s"), line);
250 status = close_bpipe(bpipe);
253 Jmsg(jcr, M_FATAL, 0, _("RunBeforeJob error: ERR=%s\n"), be.strerror(status));
254 set_jcr_job_status(jcr, JS_FatalError);
255 update_job_end_record(jcr);
259 switch (jcr->JobType) {
261 if (do_backup(jcr)) {
264 backup_cleanup(jcr, JS_ErrorTerminated);
268 if (do_verify(jcr)) {
271 verify_cleanup(jcr, JS_ErrorTerminated);
275 if (do_restore(jcr)) {
278 restore_cleanup(jcr, JS_ErrorTerminated);
285 admin_cleanup(jcr, JS_ErrorTerminated);
291 if (do_mac(jcr)) { /* migration, archive, copy */
294 mac_cleanup(jcr, JS_ErrorTerminated);
298 Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
301 if ((jcr->job->RunAfterJob && jcr->JobStatus == JS_Terminated) ||
302 (jcr->job->RunAfterFailedJob && jcr->JobStatus != JS_Terminated)) {
303 POOLMEM *after = get_pool_memory(PM_FNAME);
306 char line[MAXSTRING];
308 if (jcr->JobStatus == JS_Terminated) {
309 after = edit_job_codes(jcr, after, jcr->job->RunAfterJob, "");
311 after = edit_job_codes(jcr, after, jcr->job->RunAfterFailedJob, "");
313 bpipe = open_bpipe(after, 0, "r");
314 free_pool_memory(after);
315 while (fgets(line, sizeof(line), bpipe->rfd)) {
316 Jmsg(jcr, M_INFO, 0, _("RunAfter: %s"), line);
318 status = close_bpipe(bpipe);
320 * Note, if we get an error here, do not mark the
321 * job in error, simply report the error condition.
325 if (jcr->JobStatus == JS_Terminated) {
326 Jmsg(jcr, M_WARNING, 0, _("RunAfterJob error: ERR=%s\n"), be.strerror(status));
328 Jmsg(jcr, M_FATAL, 0, _("RunAfterFailedJob error: ERR=%s\n"), be.strerror(status));
332 generate_event(jcr, "EndJob");
333 /* Send off any queued messages */
334 if (jcr->msg_queue->size() > 0) {
335 dequeue_messages(jcr);
342 Dmsg1(50, "======== End Job stat=%c ==========\n", jcr->JobStatus);
343 sm_check(__FILE__, __LINE__, true);
349 * Cancel a job -- typically called by the UA (Console program), but may also
350 * be called by the job watchdog.
352 * Returns: 1 if cancel appears to be successful
353 * 0 on failure. Message sent to ua->jcr.
355 int cancel_job(UAContext *ua, JCR *jcr)
359 switch (jcr->JobStatus) {
362 case JS_WaitClientRes:
363 case JS_WaitStoreRes:
364 case JS_WaitPriority:
366 case JS_WaitStartTime:
367 set_jcr_job_status(jcr, JS_Canceled);
368 bsendmsg(ua, _("JobId %d, Job %s marked to be canceled.\n"),
369 jcr->JobId, jcr->Job);
370 jobq_remove(&job_queue, jcr); /* attempt to remove it from queue */
374 set_jcr_job_status(jcr, JS_Canceled);
376 /* Cancel File daemon */
377 if (jcr->file_bsock) {
378 ua->jcr->client = jcr->client;
379 if (!connect_to_file_daemon(ua->jcr, 10, FDConnectTimeout, 1)) {
380 bsendmsg(ua, _("Failed to connect to File daemon.\n"));
383 Dmsg0(200, "Connected to file daemon\n");
384 fd = ua->jcr->file_bsock;
385 bnet_fsend(fd, "cancel Job=%s\n", jcr->Job);
386 while (bnet_recv(fd) >= 0) {
387 bsendmsg(ua, "%s", fd->msg);
389 bnet_sig(fd, BNET_TERMINATE);
391 ua->jcr->file_bsock = NULL;
394 /* Cancel Storage daemon */
395 if (jcr->store_bsock) {
396 if (!ua->jcr->storage) {
397 copy_storage(ua->jcr, jcr);
399 set_storage(ua->jcr, jcr->store);
401 if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
402 bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
405 Dmsg0(200, "Connected to storage daemon\n");
406 sd = ua->jcr->store_bsock;
407 bnet_fsend(sd, "cancel Job=%s\n", jcr->Job);
408 while (bnet_recv(sd) >= 0) {
409 bsendmsg(ua, "%s", sd->msg);
411 bnet_sig(sd, BNET_TERMINATE);
413 ua->jcr->store_bsock = NULL;
421 static void job_monitor_destructor(watchdog_t *self)
423 JCR *control_jcr = (JCR *) self->data;
425 free_jcr(control_jcr);
428 static void job_monitor_watchdog(watchdog_t *self)
430 JCR *control_jcr, *jcr;
432 control_jcr = (JCR *)self->data;
434 Dmsg1(800, "job_monitor_watchdog %p called\n", self);
441 if (jcr->JobId == 0) {
442 Dmsg2(800, "Skipping JCR %p (%s) with JobId 0\n",
444 /* Keep reference counts correct */
445 free_locked_jcr(jcr);
449 /* check MaxWaitTime */
450 cancel = job_check_maxwaittime(control_jcr, jcr);
452 /* check MaxRunTime */
453 cancel |= job_check_maxruntime(control_jcr, jcr);
456 Dmsg3(800, "Cancelling JCR %p jobid %d (%s)\n",
457 jcr, jcr->JobId, jcr->Job);
459 UAContext *ua = new_ua_context(jcr);
460 ua->jcr = control_jcr;
464 Dmsg1(800, "Have cancelled JCR %p\n", jcr);
467 /* Keep reference counts correct */
468 free_locked_jcr(jcr);
474 * Check if the maxwaittime has expired and it is possible
477 static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr)
480 bool ok_to_cancel = false;
483 if (job->MaxWaitTime == 0 && job->FullMaxWaitTime == 0 &&
484 job->IncMaxWaitTime == 0 && job->DiffMaxWaitTime == 0) {
487 if (jcr->JobLevel == L_FULL && job->FullMaxWaitTime != 0 &&
488 (watchdog_time - jcr->start_time) >= job->FullMaxWaitTime) {
490 } else if (jcr->JobLevel == L_DIFFERENTIAL && job->DiffMaxWaitTime != 0 &&
491 (watchdog_time - jcr->start_time) >= job->DiffMaxWaitTime) {
493 } else if (jcr->JobLevel == L_INCREMENTAL && job->IncMaxWaitTime != 0 &&
494 (watchdog_time - jcr->start_time) >= job->IncMaxWaitTime) {
496 } else if (job->MaxWaitTime != 0 &&
497 (watchdog_time - jcr->start_time) >= job->MaxWaitTime) {
503 Dmsg3(800, "Job %d (%s): MaxWaitTime of %d seconds exceeded, "
505 jcr->JobId, jcr->Job, job->MaxWaitTime);
506 switch (jcr->JobStatus) {
511 case JS_WaitStoreRes:
512 case JS_WaitClientRes:
514 case JS_WaitPriority:
516 case JS_WaitStartTime:
518 Dmsg0(200, "JCR blocked in #1\n");
521 Dmsg0(800, "JCR running, checking SD status\n");
522 switch (jcr->SDJobStatus) {
527 Dmsg0(800, "JCR blocked in #2\n");
530 Dmsg0(800, "JCR not blocked in #2\n");
535 case JS_ErrorTerminated:
538 Dmsg0(800, "JCR already dead in #3\n");
541 Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
544 Dmsg3(800, "MaxWaitTime result: %scancel JCR %p (%s)\n",
545 cancel ? "" : "do not ", jcr, jcr->job);
551 * Check if maxruntime has expired and if the job can be
554 static bool job_check_maxruntime(JCR *control_jcr, JCR *jcr)
558 if (jcr->job->MaxRunTime == 0) {
561 if ((watchdog_time - jcr->start_time) < jcr->job->MaxRunTime) {
562 Dmsg3(200, "Job %p (%s) with MaxRunTime %d not expired\n",
563 jcr, jcr->Job, jcr->job->MaxRunTime);
567 switch (jcr->JobStatus) {
573 case JS_WaitStoreRes:
574 case JS_WaitClientRes:
576 case JS_WaitPriority:
578 case JS_WaitStartTime:
583 case JS_ErrorTerminated:
589 Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
593 Dmsg3(200, "MaxRunTime result: %scancel JCR %p (%s)\n",
594 cancel ? "" : "do not ", jcr, jcr->job);
601 * Get or create a Client record for this Job
603 bool get_or_create_client_record(JCR *jcr)
607 memset(&cr, 0, sizeof(cr));
608 bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name));
609 cr.AutoPrune = jcr->client->AutoPrune;
610 cr.FileRetention = jcr->client->FileRetention;
611 cr.JobRetention = jcr->client->JobRetention;
612 if (!jcr->client_name) {
613 jcr->client_name = get_pool_memory(PM_NAME);
615 pm_strcpy(jcr->client_name, jcr->client->hdr.name);
616 if (!db_create_client_record(jcr, jcr->db, &cr)) {
617 Jmsg(jcr, M_FATAL, 0, _("Could not create Client record. ERR=%s\n"),
618 db_strerror(jcr->db));
621 jcr->jr.ClientId = cr.ClientId;
623 if (!jcr->client_uname) {
624 jcr->client_uname = get_pool_memory(PM_NAME);
626 pm_strcpy(jcr->client_uname, cr.Uname);
628 Dmsg2(100, "Created Client %s record %d\n", jcr->client->hdr.name,
633 bool get_or_create_fileset_record(JCR *jcr, FILESET_DBR *fsr)
636 * Get or Create FileSet record
638 memset(fsr, 0, sizeof(FILESET_DBR));
639 bstrncpy(fsr->FileSet, jcr->fileset->hdr.name, sizeof(fsr->FileSet));
640 if (jcr->fileset->have_MD5) {
641 struct MD5Context md5c;
642 unsigned char signature[16];
643 memcpy(&md5c, &jcr->fileset->md5c, sizeof(md5c));
644 MD5Final(signature, &md5c);
645 bin_to_base64(fsr->MD5, (char *)signature, 16); /* encode 16 bytes */
646 bstrncpy(jcr->fileset->MD5, fsr->MD5, sizeof(jcr->fileset->MD5));
648 Jmsg(jcr, M_WARNING, 0, _("FileSet MD5 signature not found.\n"));
650 if (!jcr->fileset->ignore_fs_changes ||
651 !db_get_fileset_record(jcr, jcr->db, fsr)) {
652 if (!db_create_fileset_record(jcr, jcr->db, fsr)) {
653 Jmsg(jcr, M_ERROR, 0, _("Could not create FileSet \"%s\" record. ERR=%s\n"),
654 fsr->FileSet, db_strerror(jcr->db));
658 jcr->jr.FileSetId = fsr->FileSetId;
660 Jmsg(jcr, M_INFO, 0, _("Created new FileSet record \"%s\" %s\n"),
661 fsr->FileSet, fsr->cCreateTime);
663 Dmsg2(119, "Created FileSet %s record %u\n", jcr->fileset->hdr.name,
668 void init_jcr_job_record(JCR *jcr)
670 jcr->jr.SchedTime = jcr->sched_time;
671 jcr->jr.StartTime = jcr->start_time;
672 jcr->jr.EndTime = 0; /* perhaps rescheduled, clear it */
673 jcr->jr.JobType = jcr->JobType;
674 jcr->jr.JobLevel = jcr->JobLevel;
675 jcr->jr.JobStatus = jcr->JobStatus;
676 jcr->jr.JobId = jcr->JobId;
677 bstrncpy(jcr->jr.Name, jcr->job->hdr.name, sizeof(jcr->jr.Name));
678 bstrncpy(jcr->jr.Job, jcr->Job, sizeof(jcr->jr.Job));
682 * Write status and such in DB
684 void update_job_end_record(JCR *jcr)
686 jcr->jr.EndTime = time(NULL);
687 jcr->end_time = jcr->jr.EndTime;
688 jcr->jr.JobId = jcr->JobId;
689 jcr->jr.JobStatus = jcr->JobStatus;
690 jcr->jr.JobFiles = jcr->JobFiles;
691 jcr->jr.JobBytes = jcr->JobBytes;
692 jcr->jr.VolSessionId = jcr->VolSessionId;
693 jcr->jr.VolSessionTime = jcr->VolSessionTime;
694 if (!db_update_job_end_record(jcr, jcr->db, &jcr->jr)) {
695 Jmsg(jcr, M_WARNING, 0, _("Error updating job record. %s"),
696 db_strerror(jcr->db));
701 * Takes base_name and appends (unique) current
702 * date and time to form unique job name.
704 * Returns: unique job name in jcr->Job
705 * date/time in jcr->start_time
707 void create_unique_job_name(JCR *jcr, const char *base_name)
709 /* Job start mutex */
710 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
711 static time_t last_start_time = 0;
714 char dt[MAX_TIME_LENGTH];
715 char name[MAX_NAME_LENGTH];
718 /* Guarantee unique start time -- maximum one per second, and
719 * thus unique Job Name
721 P(mutex); /* lock creation of jobs */
723 while (now == last_start_time) {
724 bmicrosleep(0, 500000);
727 last_start_time = now;
728 V(mutex); /* allow creation of jobs */
729 jcr->start_time = now;
730 /* Form Unique JobName */
731 localtime_r(&now, &tm);
732 /* Use only characters that are permitted in Windows filenames */
733 strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm);
734 bstrncpy(name, base_name, sizeof(name));
735 name[sizeof(name)-22] = 0; /* truncate if too long */
736 bsnprintf(jcr->Job, sizeof(jcr->Job), "%s.%s", name, dt); /* add date & time */
737 /* Convert spaces into underscores */
738 for (p=jcr->Job; *p; p++) {
746 * Free the Job Control Record if no one is still using it.
747 * Called from main free_jcr() routine in src/lib/jcr.c so
748 * that we can do our Director specific cleanup of the jcr.
750 void dird_free_jcr(JCR *jcr)
752 Dmsg0(200, "Start dird free_jcr\n");
754 if (jcr->sd_auth_key) {
755 free(jcr->sd_auth_key);
756 jcr->sd_auth_key = NULL;
762 if (jcr->file_bsock) {
763 Dmsg0(200, "Close File bsock\n");
764 bnet_close(jcr->file_bsock);
765 jcr->file_bsock = NULL;
767 if (jcr->store_bsock) {
768 Dmsg0(200, "Close Store bsock\n");
769 bnet_close(jcr->store_bsock);
770 jcr->store_bsock = NULL;
773 Dmsg0(200, "Free JCR fname\n");
774 free_pool_memory(jcr->fname);
778 Dmsg0(200, "Free JCR stime\n");
779 free_pool_memory(jcr->stime);
782 if (jcr->RestoreBootstrap) {
783 free(jcr->RestoreBootstrap);
784 jcr->RestoreBootstrap = NULL;
786 if (jcr->client_uname) {
787 free_pool_memory(jcr->client_uname);
788 jcr->client_uname = NULL;
790 if (jcr->term_wait_inited) {
791 pthread_cond_destroy(&jcr->term_wait);
793 /* Delete lists setup to hold storage pointers */
797 jcr->job_end_push.destroy();
798 Dmsg0(200, "End dird free_jcr\n");
802 * Set some defaults in the JCR necessary to
803 * run. These items are pulled from the job
804 * definition as defaults, but can be overridden
805 * later either by the Run record in the Schedule resource,
806 * or by the Console program.
808 void set_jcr_defaults(JCR *jcr, JOB *job)
812 jcr->JobType = job->JobType;
813 switch (jcr->JobType) {
816 jcr->JobLevel = L_NONE;
819 jcr->JobLevel = job->JobLevel;
822 jcr->JobPriority = job->Priority;
823 /* Copy storage definitions -- deleted in dir_free_jcr above */
828 jcr->storage = New(alist(10, not_owned_by_alist));
829 foreach_alist(st, job->storage) {
830 jcr->storage->append(st);
834 jcr->store = (STORE *)jcr->storage->first();
836 jcr->client = job->client;
837 if (!jcr->client_name) {
838 jcr->client_name = get_pool_memory(PM_NAME);
840 pm_strcpy(jcr->client_name, jcr->client->hdr.name);
841 jcr->pool = job->pool;
842 jcr->full_pool = job->full_pool;
843 jcr->inc_pool = job->inc_pool;
844 jcr->dif_pool = job->dif_pool;
845 jcr->catalog = job->client->catalog;
846 jcr->fileset = job->fileset;
847 jcr->messages = job->messages;
848 jcr->spool_data = job->spool_data;
849 jcr->write_part_after_job = job->write_part_after_job;
850 if (jcr->RestoreBootstrap) {
851 free(jcr->RestoreBootstrap);
852 jcr->RestoreBootstrap = NULL;
854 /* This can be overridden by Console program */
855 if (job->RestoreBootstrap) {
856 jcr->RestoreBootstrap = bstrdup(job->RestoreBootstrap);
858 /* This can be overridden by Console program */
859 jcr->verify_job = job->verify_job;
860 /* If no default level given, set one */
861 if (jcr->JobLevel == 0) {
862 switch (jcr->JobType) {
864 jcr->JobLevel = L_VERIFY_CATALOG;
867 jcr->JobLevel = L_INCREMENTAL;
871 jcr->JobLevel = L_NONE;
880 * copy the storage definitions from an old JCR to a new one
882 void copy_storage(JCR *new_jcr, JCR *old_jcr)
884 if (old_jcr->storage) {
886 if (old_jcr->storage) {
887 delete old_jcr->storage;
889 new_jcr->storage = New(alist(10, not_owned_by_alist));
890 foreach_alist(st, old_jcr->storage) {
891 new_jcr->storage->append(st);
894 if (old_jcr->store) {
895 new_jcr->store = old_jcr->store;
896 } else if (new_jcr->storage) {
897 new_jcr->store = (STORE *)new_jcr->storage->first();
901 /* Set storage override */
902 void set_storage(JCR *jcr, STORE *store)
907 foreach_alist(storage, jcr->storage) {
908 if (store == storage) {
912 /* Store not in list, so add it */
913 jcr->storage->prepend(store);