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 /* Imported subroutines */
40 extern void term_scheduler();
41 extern void term_ua_server();
43 /* Imported variables */
44 extern time_t watchdog_time;
48 void init_job_server(int max_workers)
53 if ((stat = jobq_init(&job_queue, max_workers, job_thread)) != 0) {
55 Emsg1(M_ABORT, 0, _("Could not init job queue: ERR=%s\n"), be.strerror(stat));
58 wd->callback = job_monitor_watchdog;
59 wd->destructor = job_monitor_destructor;
62 wd->data = new_control_jcr("*JobMonitor*", JT_SYSTEM);
63 register_watchdog(wd);
66 void term_job_server()
68 jobq_destroy(&job_queue); /* ignore any errors */
72 * Run a job -- typically called by the scheduler, but may also
73 * be called by the UA (Console program).
75 * Returns: 0 on failure
79 JobId_t run_job(JCR *jcr)
85 sm_check(__FILE__, __LINE__, true);
86 init_msg(jcr, jcr->messages);
88 /* Initialize termination condition variable */
89 if ((errstat = pthread_cond_init(&jcr->term_wait, NULL)) != 0) {
91 Jmsg1(jcr, M_FATAL, 0, _("Unable to init job cond variable: ERR=%s\n"), be.strerror(errstat));
94 jcr->term_wait_inited = true;
99 Dmsg0(50, "Open database\n");
100 jcr->db=db_init_database(jcr, jcr->catalog->db_name, jcr->catalog->db_user,
101 jcr->catalog->db_password, jcr->catalog->db_address,
102 jcr->catalog->db_port, jcr->catalog->db_socket,
103 jcr->catalog->mult_db_connections);
104 if (!jcr->db || !db_open_database(jcr, jcr->db)) {
105 Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"),
106 jcr->catalog->db_name);
108 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
112 Dmsg0(50, "DB opened\n");
117 create_unique_job_name(jcr, jcr->job->hdr.name);
118 set_jcr_job_status(jcr, JS_Created);
119 init_jcr_job_record(jcr);
120 if (!db_create_job_record(jcr, jcr->db, &jcr->jr)) {
121 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
124 JobId = jcr->JobId = jcr->jr.JobId;
126 Dmsg4(100, "Created job record JobId=%d Name=%s Type=%c Level=%c\n",
127 jcr->JobId, jcr->Job, jcr->jr.JobType, jcr->jr.JobLevel);
129 if (!get_or_create_client_record(jcr)) {
134 jcr->fname = get_pool_memory(PM_FNAME);
137 /* Now, do pre-run stuff, like setting job level (Inc/diff, ...) */
138 switch (jcr->JobType) {
140 if (!do_backup_init(jcr)) {
141 backup_cleanup(jcr, JS_ErrorTerminated);
145 if (!do_verify_init(jcr)) {
146 verify_cleanup(jcr, JS_ErrorTerminated);
150 if (!do_restore_init(jcr)) {
151 restore_cleanup(jcr, JS_ErrorTerminated);
155 if (!do_admin_init(jcr)) {
156 admin_cleanup(jcr, JS_ErrorTerminated);
162 if (!do_mac_init(jcr)) { /* migration, archive, copy */
163 mac_cleanup(jcr, JS_ErrorTerminated);
167 Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
168 set_jcr_job_status(jcr, JS_ErrorTerminated);
171 if (job_canceled(jcr)) {
175 Dmsg0(200, "Add jrc to work queue\n");
177 /* Queue the job to be run */
178 if ((stat = jobq_add(&job_queue, jcr)) != 0) {
180 Jmsg(jcr, M_FATAL, 0, _("Could not add job queue: ERR=%s\n"), be.strerror(stat));
184 Dmsg0(100, "Done run_job()\n");
191 free_memory(jcr->fname);
201 * This is the engine called by jobq.c:jobq_add() when we were pulled
202 * from the work queue.
203 * At this point, we are running in our own thread and all
204 * necessary resources are allocated -- see jobq.c
206 static void *job_thread(void *arg)
208 JCR *jcr = (JCR *)arg;
210 jcr->my_thread_id = pthread_self();
211 pthread_detach(jcr->my_thread_id);
212 sm_check(__FILE__, __LINE__, true);
215 Dmsg0(200, "=====Start Job=========\n");
216 jcr->start_time = time(NULL); /* set the real start time */
217 jcr->jr.StartTime = jcr->start_time;
218 set_jcr_job_status(jcr, JS_Running);
219 if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
220 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
223 if (job_canceled(jcr)) {
224 update_job_end_record(jcr);
225 } else if (jcr->job->MaxStartDelay != 0 && jcr->job->MaxStartDelay <
226 (utime_t)(jcr->start_time - jcr->sched_time)) {
227 Jmsg(jcr, M_FATAL, 0, _("Job canceled because max start delay time exceeded.\n"));
228 set_jcr_job_status(jcr, JS_Canceled);
229 update_job_end_record(jcr);
233 generate_event(jcr, "StartJob");
234 if (jcr->job->RunBeforeJob) {
235 POOLMEM *before = get_pool_memory(PM_FNAME);
238 char line[MAXSTRING];
240 before = edit_job_codes(jcr, before, jcr->job->RunBeforeJob, "");
241 bpipe = open_bpipe(before, 0, "r");
242 free_pool_memory(before);
243 while (fgets(line, sizeof(line), bpipe->rfd)) {
244 Jmsg(jcr, M_INFO, 0, _("RunBefore: %s"), line);
246 status = close_bpipe(bpipe);
249 Jmsg(jcr, M_FATAL, 0, _("RunBeforeJob error: ERR=%s\n"), be.strerror(status));
250 set_jcr_job_status(jcr, JS_FatalError);
251 update_job_end_record(jcr);
255 switch (jcr->JobType) {
257 if (do_backup(jcr)) {
260 backup_cleanup(jcr, JS_ErrorTerminated);
264 if (do_verify(jcr)) {
267 verify_cleanup(jcr, JS_ErrorTerminated);
271 if (do_restore(jcr)) {
274 restore_cleanup(jcr, JS_ErrorTerminated);
281 admin_cleanup(jcr, JS_ErrorTerminated);
287 if (do_mac(jcr)) { /* migration, archive, copy */
290 mac_cleanup(jcr, JS_ErrorTerminated);
294 Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
297 if ((jcr->job->RunAfterJob && jcr->JobStatus == JS_Terminated) ||
298 (jcr->job->RunAfterFailedJob && jcr->JobStatus != JS_Terminated)) {
299 POOLMEM *after = get_pool_memory(PM_FNAME);
302 char line[MAXSTRING];
304 if (jcr->JobStatus == JS_Terminated) {
305 after = edit_job_codes(jcr, after, jcr->job->RunAfterJob, "");
307 after = edit_job_codes(jcr, after, jcr->job->RunAfterFailedJob, "");
309 bpipe = open_bpipe(after, 0, "r");
310 free_pool_memory(after);
311 while (fgets(line, sizeof(line), bpipe->rfd)) {
312 Jmsg(jcr, M_INFO, 0, _("RunAfter: %s"), line);
314 status = close_bpipe(bpipe);
316 * Note, if we get an error here, do not mark the
317 * job in error, simply report the error condition.
321 if (jcr->JobStatus == JS_Terminated) {
322 Jmsg(jcr, M_WARNING, 0, _("RunAfterJob error: ERR=%s\n"), be.strerror(status));
324 Jmsg(jcr, M_FATAL, 0, _("RunAfterFailedJob error: ERR=%s\n"), be.strerror(status));
328 generate_event(jcr, "EndJob");
329 /* Send off any queued messages */
330 if (jcr->msg_queue->size() > 0) {
331 dequeue_messages(jcr);
338 Dmsg1(50, "======== End Job stat=%c ==========\n", jcr->JobStatus);
339 sm_check(__FILE__, __LINE__, true);
345 * Cancel a job -- typically called by the UA (Console program), but may also
346 * be called by the job watchdog.
348 * Returns: 1 if cancel appears to be successful
349 * 0 on failure. Message sent to ua->jcr.
351 int cancel_job(UAContext *ua, JCR *jcr)
355 switch (jcr->JobStatus) {
358 case JS_WaitClientRes:
359 case JS_WaitStoreRes:
360 case JS_WaitPriority:
362 case JS_WaitStartTime:
363 set_jcr_job_status(jcr, JS_Canceled);
364 bsendmsg(ua, _("JobId %d, Job %s marked to be canceled.\n"),
365 jcr->JobId, jcr->Job);
366 jobq_remove(&job_queue, jcr); /* attempt to remove it from queue */
370 set_jcr_job_status(jcr, JS_Canceled);
372 /* Cancel File daemon */
373 if (jcr->file_bsock) {
374 ua->jcr->client = jcr->client;
375 if (!connect_to_file_daemon(ua->jcr, 10, FDConnectTimeout, 1)) {
376 bsendmsg(ua, _("Failed to connect to File daemon.\n"));
379 Dmsg0(200, "Connected to file daemon\n");
380 fd = ua->jcr->file_bsock;
381 bnet_fsend(fd, "cancel Job=%s\n", jcr->Job);
382 while (bnet_recv(fd) >= 0) {
383 bsendmsg(ua, "%s", fd->msg);
385 bnet_sig(fd, BNET_TERMINATE);
387 ua->jcr->file_bsock = NULL;
390 /* Cancel Storage daemon */
391 if (jcr->store_bsock) {
392 if (!ua->jcr->storage) {
393 copy_storage(ua->jcr, jcr);
395 set_storage(ua->jcr, jcr->store);
397 if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
398 bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
401 Dmsg0(200, "Connected to storage daemon\n");
402 sd = ua->jcr->store_bsock;
403 bnet_fsend(sd, "cancel Job=%s\n", jcr->Job);
404 while (bnet_recv(sd) >= 0) {
405 bsendmsg(ua, "%s", sd->msg);
407 bnet_sig(sd, BNET_TERMINATE);
409 ua->jcr->store_bsock = NULL;
417 static void job_monitor_destructor(watchdog_t *self)
419 JCR *control_jcr = (JCR *) self->data;
421 free_jcr(control_jcr);
424 static void job_monitor_watchdog(watchdog_t *self)
426 JCR *control_jcr, *jcr;
428 control_jcr = (JCR *)self->data;
430 Dmsg1(800, "job_monitor_watchdog %p called\n", self);
437 if (jcr->JobId == 0) {
438 Dmsg2(800, "Skipping JCR %p (%s) with JobId 0\n",
440 /* Keep reference counts correct */
441 free_locked_jcr(jcr);
445 /* check MaxWaitTime */
446 cancel = job_check_maxwaittime(control_jcr, jcr);
448 /* check MaxRunTime */
449 cancel |= job_check_maxruntime(control_jcr, jcr);
452 Dmsg3(800, "Cancelling JCR %p jobid %d (%s)\n",
453 jcr, jcr->JobId, jcr->Job);
455 UAContext *ua = new_ua_context(jcr);
456 ua->jcr = control_jcr;
460 Dmsg1(800, "Have cancelled JCR %p\n", jcr);
463 /* Keep reference counts correct */
464 free_locked_jcr(jcr);
470 * Check if the maxwaittime has expired and it is possible
473 static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr)
476 bool ok_to_cancel = false;
479 if (job->MaxWaitTime == 0 && job->FullMaxWaitTime == 0 &&
480 job->IncMaxWaitTime == 0 && job->DiffMaxWaitTime == 0) {
483 if (jcr->JobLevel == L_FULL && job->FullMaxWaitTime != 0 &&
484 (watchdog_time - jcr->start_time) >= job->FullMaxWaitTime) {
486 } else if (jcr->JobLevel == L_DIFFERENTIAL && job->DiffMaxWaitTime != 0 &&
487 (watchdog_time - jcr->start_time) >= job->DiffMaxWaitTime) {
489 } else if (jcr->JobLevel == L_INCREMENTAL && job->IncMaxWaitTime != 0 &&
490 (watchdog_time - jcr->start_time) >= job->IncMaxWaitTime) {
492 } else if (job->MaxWaitTime != 0 &&
493 (watchdog_time - jcr->start_time) >= job->MaxWaitTime) {
499 Dmsg3(800, "Job %d (%s): MaxWaitTime of %d seconds exceeded, "
501 jcr->JobId, jcr->Job, job->MaxWaitTime);
502 switch (jcr->JobStatus) {
507 case JS_WaitStoreRes:
508 case JS_WaitClientRes:
510 case JS_WaitPriority:
512 case JS_WaitStartTime:
514 Dmsg0(200, "JCR blocked in #1\n");
517 Dmsg0(800, "JCR running, checking SD status\n");
518 switch (jcr->SDJobStatus) {
523 Dmsg0(800, "JCR blocked in #2\n");
526 Dmsg0(800, "JCR not blocked in #2\n");
531 case JS_ErrorTerminated:
534 Dmsg0(800, "JCR already dead in #3\n");
537 Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
540 Dmsg3(800, "MaxWaitTime result: %scancel JCR %p (%s)\n",
541 cancel ? "" : "do not ", jcr, jcr->job);
547 * Check if maxruntime has expired and if the job can be
550 static bool job_check_maxruntime(JCR *control_jcr, JCR *jcr)
554 if (jcr->job->MaxRunTime == 0) {
557 if ((watchdog_time - jcr->start_time) < jcr->job->MaxRunTime) {
558 Dmsg3(200, "Job %p (%s) with MaxRunTime %d not expired\n",
559 jcr, jcr->Job, jcr->job->MaxRunTime);
563 switch (jcr->JobStatus) {
569 case JS_WaitStoreRes:
570 case JS_WaitClientRes:
572 case JS_WaitPriority:
574 case JS_WaitStartTime:
579 case JS_ErrorTerminated:
585 Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
589 Dmsg3(200, "MaxRunTime result: %scancel JCR %p (%s)\n",
590 cancel ? "" : "do not ", jcr, jcr->job);
597 * Get or create a Client record for this Job
599 bool get_or_create_client_record(JCR *jcr)
603 memset(&cr, 0, sizeof(cr));
604 bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name));
605 cr.AutoPrune = jcr->client->AutoPrune;
606 cr.FileRetention = jcr->client->FileRetention;
607 cr.JobRetention = jcr->client->JobRetention;
608 if (!jcr->client_name) {
609 jcr->client_name = get_pool_memory(PM_NAME);
611 pm_strcpy(jcr->client_name, jcr->client->hdr.name);
612 if (!db_create_client_record(jcr, jcr->db, &cr)) {
613 Jmsg(jcr, M_FATAL, 0, _("Could not create Client record. ERR=%s\n"),
614 db_strerror(jcr->db));
617 jcr->jr.ClientId = cr.ClientId;
619 if (!jcr->client_uname) {
620 jcr->client_uname = get_pool_memory(PM_NAME);
622 pm_strcpy(jcr->client_uname, cr.Uname);
624 Dmsg2(100, "Created Client %s record %d\n", jcr->client->hdr.name,
629 bool get_or_create_fileset_record(JCR *jcr, FILESET_DBR *fsr)
632 * Get or Create FileSet record
634 memset(fsr, 0, sizeof(FILESET_DBR));
635 bstrncpy(fsr->FileSet, jcr->fileset->hdr.name, sizeof(fsr->FileSet));
636 if (jcr->fileset->have_MD5) {
637 struct MD5Context md5c;
638 unsigned char signature[16];
639 memcpy(&md5c, &jcr->fileset->md5c, sizeof(md5c));
640 MD5Final(signature, &md5c);
641 bin_to_base64(fsr->MD5, (char *)signature, 16); /* encode 16 bytes */
642 bstrncpy(jcr->fileset->MD5, fsr->MD5, sizeof(jcr->fileset->MD5));
644 Jmsg(jcr, M_WARNING, 0, _("FileSet MD5 signature not found.\n"));
646 if (!jcr->fileset->ignore_fs_changes ||
647 !db_get_fileset_record(jcr, jcr->db, fsr)) {
648 if (!db_create_fileset_record(jcr, jcr->db, fsr)) {
649 Jmsg(jcr, M_ERROR, 0, _("Could not create FileSet \"%s\" record. ERR=%s\n"),
650 fsr->FileSet, db_strerror(jcr->db));
654 jcr->jr.FileSetId = fsr->FileSetId;
656 Jmsg(jcr, M_INFO, 0, _("Created new FileSet record \"%s\" %s\n"),
657 fsr->FileSet, fsr->cCreateTime);
659 Dmsg2(119, "Created FileSet %s record %u\n", jcr->fileset->hdr.name,
664 void init_jcr_job_record(JCR *jcr)
666 jcr->jr.SchedTime = jcr->sched_time;
667 jcr->jr.StartTime = jcr->start_time;
668 jcr->jr.EndTime = 0; /* perhaps rescheduled, clear it */
669 jcr->jr.JobType = jcr->JobType;
670 jcr->jr.JobLevel = jcr->JobLevel;
671 jcr->jr.JobStatus = jcr->JobStatus;
672 jcr->jr.JobId = jcr->JobId;
673 bstrncpy(jcr->jr.Name, jcr->job->hdr.name, sizeof(jcr->jr.Name));
674 bstrncpy(jcr->jr.Job, jcr->Job, sizeof(jcr->jr.Job));
678 * Write status and such in DB
680 void update_job_end_record(JCR *jcr)
682 jcr->jr.EndTime = time(NULL);
683 jcr->end_time = jcr->jr.EndTime;
684 jcr->jr.JobId = jcr->JobId;
685 jcr->jr.JobStatus = jcr->JobStatus;
686 jcr->jr.JobFiles = jcr->JobFiles;
687 jcr->jr.JobBytes = jcr->JobBytes;
688 jcr->jr.VolSessionId = jcr->VolSessionId;
689 jcr->jr.VolSessionTime = jcr->VolSessionTime;
690 if (!db_update_job_end_record(jcr, jcr->db, &jcr->jr)) {
691 Jmsg(jcr, M_WARNING, 0, _("Error updating job record. %s"),
692 db_strerror(jcr->db));
697 * Takes base_name and appends (unique) current
698 * date and time to form unique job name.
700 * Returns: unique job name in jcr->Job
701 * date/time in jcr->start_time
703 void create_unique_job_name(JCR *jcr, const char *base_name)
705 /* Job start mutex */
706 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
707 static time_t last_start_time = 0;
710 char dt[MAX_TIME_LENGTH];
711 char name[MAX_NAME_LENGTH];
714 /* Guarantee unique start time -- maximum one per second, and
715 * thus unique Job Name
717 P(mutex); /* lock creation of jobs */
719 while (now == last_start_time) {
720 bmicrosleep(0, 500000);
723 last_start_time = now;
724 V(mutex); /* allow creation of jobs */
725 jcr->start_time = now;
726 /* Form Unique JobName */
727 localtime_r(&now, &tm);
728 /* Use only characters that are permitted in Windows filenames */
729 strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm);
730 bstrncpy(name, base_name, sizeof(name));
731 name[sizeof(name)-22] = 0; /* truncate if too long */
732 bsnprintf(jcr->Job, sizeof(jcr->Job), "%s.%s", name, dt); /* add date & time */
733 /* Convert spaces into underscores */
734 for (p=jcr->Job; *p; p++) {
741 /* Called directly from job rescheduling */
742 void dird_free_jcr_pointers(JCR *jcr)
744 if (jcr->sd_auth_key) {
745 free(jcr->sd_auth_key);
746 jcr->sd_auth_key = NULL;
752 if (jcr->file_bsock) {
753 Dmsg0(200, "Close File bsock\n");
754 bnet_close(jcr->file_bsock);
755 jcr->file_bsock = NULL;
757 if (jcr->store_bsock) {
758 Dmsg0(200, "Close Store bsock\n");
759 bnet_close(jcr->store_bsock);
760 jcr->store_bsock = NULL;
763 Dmsg0(200, "Free JCR fname\n");
764 free_pool_memory(jcr->fname);
768 Dmsg0(200, "Free JCR stime\n");
769 free_pool_memory(jcr->stime);
772 if (jcr->RestoreBootstrap) {
773 free(jcr->RestoreBootstrap);
774 jcr->RestoreBootstrap = NULL;
776 if (jcr->client_uname) {
777 free_pool_memory(jcr->client_uname);
778 jcr->client_uname = NULL;
780 if (jcr->term_wait_inited) {
781 pthread_cond_destroy(&jcr->term_wait);
782 jcr->term_wait_inited = false;
787 * Free the Job Control Record if no one is still using it.
788 * Called from main free_jcr() routine in src/lib/jcr.c so
789 * that we can do our Director specific cleanup of the jcr.
791 void dird_free_jcr(JCR *jcr)
793 Dmsg0(200, "Start dird free_jcr\n");
795 dird_free_jcr_pointers(jcr);
797 /* Delete lists setup to hold storage pointers */
801 jcr->job_end_push.destroy();
802 Dmsg0(200, "End dird free_jcr\n");
806 * Set some defaults in the JCR necessary to
807 * run. These items are pulled from the job
808 * definition as defaults, but can be overridden
809 * later either by the Run record in the Schedule resource,
810 * or by the Console program.
812 void set_jcr_defaults(JCR *jcr, JOB *job)
816 jcr->JobType = job->JobType;
817 switch (jcr->JobType) {
820 jcr->JobLevel = L_NONE;
823 jcr->JobLevel = job->JobLevel;
826 jcr->JobPriority = job->Priority;
827 /* Copy storage definitions -- deleted in dir_free_jcr above */
832 jcr->storage = New(alist(10, not_owned_by_alist));
833 foreach_alist(st, job->storage) {
834 jcr->storage->append(st);
838 jcr->store = (STORE *)jcr->storage->first();
840 jcr->client = job->client;
841 if (!jcr->client_name) {
842 jcr->client_name = get_pool_memory(PM_NAME);
844 pm_strcpy(jcr->client_name, jcr->client->hdr.name);
845 jcr->pool = job->pool;
846 jcr->full_pool = job->full_pool;
847 jcr->inc_pool = job->inc_pool;
848 jcr->dif_pool = job->dif_pool;
849 jcr->catalog = job->client->catalog;
850 jcr->fileset = job->fileset;
851 jcr->messages = job->messages;
852 jcr->spool_data = job->spool_data;
853 jcr->write_part_after_job = job->write_part_after_job;
854 if (jcr->RestoreBootstrap) {
855 free(jcr->RestoreBootstrap);
856 jcr->RestoreBootstrap = NULL;
858 /* This can be overridden by Console program */
859 if (job->RestoreBootstrap) {
860 jcr->RestoreBootstrap = bstrdup(job->RestoreBootstrap);
862 /* This can be overridden by Console program */
863 jcr->verify_job = job->verify_job;
864 /* If no default level given, set one */
865 if (jcr->JobLevel == 0) {
866 switch (jcr->JobType) {
868 jcr->JobLevel = L_VERIFY_CATALOG;
871 jcr->JobLevel = L_INCREMENTAL;
875 jcr->JobLevel = L_NONE;
884 * copy the storage definitions from an old JCR to a new one
886 void copy_storage(JCR *new_jcr, JCR *old_jcr)
888 if (old_jcr->storage) {
890 if (old_jcr->storage) {
891 delete old_jcr->storage;
893 new_jcr->storage = New(alist(10, not_owned_by_alist));
894 foreach_alist(st, old_jcr->storage) {
895 new_jcr->storage->append(st);
898 if (old_jcr->store) {
899 new_jcr->store = old_jcr->store;
900 } else if (new_jcr->storage) {
901 new_jcr->store = (STORE *)new_jcr->storage->first();
905 /* Set storage override */
906 void set_storage(JCR *jcr, STORE *store)
911 foreach_alist(storage, jcr->storage) {
912 if (store == storage) {
916 /* Store not in list, so add it */
917 jcr->storage->prepend(store);