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;
100 Dmsg0(50, "Open database\n");
101 jcr->db=db_init_database(jcr, jcr->catalog->db_name, jcr->catalog->db_user,
102 jcr->catalog->db_password, jcr->catalog->db_address,
103 jcr->catalog->db_port, jcr->catalog->db_socket,
104 jcr->catalog->mult_db_connections);
105 if (!jcr->db || !db_open_database(jcr, jcr->db)) {
106 Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"),
107 jcr->catalog->db_name);
109 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
113 Dmsg0(50, "DB opened\n");
118 create_unique_job_name(jcr, jcr->job->hdr.name);
119 set_jcr_job_status(jcr, JS_Created);
120 init_jcr_job_record(jcr);
121 if (!db_create_job_record(jcr, jcr->db, &jcr->jr)) {
122 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
125 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 generate_daemon_event(jcr, "JobStart");
131 if (!get_or_create_client_record(jcr)) {
135 if (job_canceled(jcr)) {
139 Dmsg0(200, "Add jrc to work queue\n");
141 /* Queue the job to be run */
142 if ((stat = jobq_add(&job_queue, jcr)) != 0) {
144 Jmsg(jcr, M_FATAL, 0, _("Could not add job queue: ERR=%s\n"), be.strerror(stat));
148 Dmsg0(100, "Done run_job()\n");
154 generate_daemon_event(jcr, "JobEnd");
156 free_memory(jcr->fname);
165 * This is the engine called by jobq.c:jobq_add() when we were pulled
166 * from the work queue.
167 * At this point, we are running in our own thread and all
168 * necessary resources are allocated -- see jobq.c
170 static void *job_thread(void *arg)
172 JCR *jcr = (JCR *)arg;
174 jcr->my_thread_id = pthread_self();
175 pthread_detach(jcr->my_thread_id);
176 sm_check(__FILE__, __LINE__, true);
178 Dmsg0(200, "=====Start Job=========\n");
179 jcr->start_time = time(NULL); /* set the real start time */
180 jcr->jr.StartTime = jcr->start_time;
181 set_jcr_job_status(jcr, JS_Running);
184 jcr->fname = get_pool_memory(PM_FNAME);
188 * Now, do pre-run stuff, like setting job level (Inc/diff, ...)
189 * this allows us to setup a proper job start record for restarting
190 * in case of later errors.
192 switch (jcr->JobType) {
194 if (!do_backup_init(jcr)) {
195 backup_cleanup(jcr, JS_ErrorTerminated);
199 if (!do_verify_init(jcr)) {
200 verify_cleanup(jcr, JS_ErrorTerminated);
204 if (!do_restore_init(jcr)) {
205 restore_cleanup(jcr, JS_ErrorTerminated);
209 if (!do_admin_init(jcr)) {
210 admin_cleanup(jcr, JS_ErrorTerminated);
216 if (!do_mac_init(jcr)) { /* migration, archive, copy */
217 mac_cleanup(jcr, JS_ErrorTerminated);
221 Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
222 set_jcr_job_status(jcr, JS_ErrorTerminated);
226 if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
227 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
230 if (job_canceled(jcr)) {
231 update_job_end_record(jcr);
233 } else if (jcr->job->MaxStartDelay != 0 && jcr->job->MaxStartDelay <
234 (utime_t)(jcr->start_time - jcr->sched_time)) {
235 Jmsg(jcr, M_FATAL, 0, _("Job canceled because max start delay time exceeded.\n"));
236 set_jcr_job_status(jcr, JS_Canceled);
237 update_job_end_record(jcr);
242 if (jcr->job->RunBeforeJob) {
243 POOLMEM *before = get_pool_memory(PM_FNAME);
246 char line[MAXSTRING];
248 before = edit_job_codes(jcr, before, jcr->job->RunBeforeJob, "");
249 bpipe = open_bpipe(before, 0, "r");
250 free_pool_memory(before);
251 while (fgets(line, sizeof(line), bpipe->rfd)) {
252 Jmsg(jcr, M_INFO, 0, _("RunBefore: %s"), line);
254 status = close_bpipe(bpipe);
257 Jmsg(jcr, M_FATAL, 0, _("RunBeforeJob error: ERR=%s\n"), be.strerror(status));
258 set_jcr_job_status(jcr, JS_FatalError);
259 update_job_end_record(jcr);
263 switch (jcr->JobType) {
265 if (do_backup(jcr)) {
268 backup_cleanup(jcr, JS_ErrorTerminated);
272 if (do_verify(jcr)) {
275 verify_cleanup(jcr, JS_ErrorTerminated);
279 if (do_restore(jcr)) {
282 restore_cleanup(jcr, JS_ErrorTerminated);
289 admin_cleanup(jcr, JS_ErrorTerminated);
295 if (do_mac(jcr)) { /* migration, archive, copy */
298 mac_cleanup(jcr, JS_ErrorTerminated);
302 Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
305 if ((jcr->job->RunAfterJob && jcr->JobStatus == JS_Terminated) ||
306 (jcr->job->RunAfterFailedJob && jcr->JobStatus != JS_Terminated)) {
307 POOLMEM *after = get_pool_memory(PM_FNAME);
310 char line[MAXSTRING];
312 if (jcr->JobStatus == JS_Terminated) {
313 after = edit_job_codes(jcr, after, jcr->job->RunAfterJob, "");
315 after = edit_job_codes(jcr, after, jcr->job->RunAfterFailedJob, "");
317 bpipe = open_bpipe(after, 0, "r");
318 free_pool_memory(after);
319 while (fgets(line, sizeof(line), bpipe->rfd)) {
320 Jmsg(jcr, M_INFO, 0, _("RunAfter: %s"), line);
322 status = close_bpipe(bpipe);
324 * Note, if we get an error here, do not mark the
325 * job in error, simply report the error condition.
329 if (jcr->JobStatus == JS_Terminated) {
330 Jmsg(jcr, M_WARNING, 0, _("RunAfterJob error: ERR=%s\n"), be.strerror(status));
332 Jmsg(jcr, M_FATAL, 0, _("RunAfterFailedJob error: ERR=%s\n"), be.strerror(status));
336 /* Send off any queued messages */
337 if (jcr->msg_queue->size() > 0) {
338 dequeue_messages(jcr);
342 generate_daemon_event(jcr, "JobEnd");
343 Dmsg1(50, "======== End Job stat=%c ==========\n", jcr->JobStatus);
344 sm_check(__FILE__, __LINE__, true);
350 * Cancel a job -- typically called by the UA (Console program), but may also
351 * be called by the job watchdog.
353 * Returns: 1 if cancel appears to be successful
354 * 0 on failure. Message sent to ua->jcr.
356 int cancel_job(UAContext *ua, JCR *jcr)
360 switch (jcr->JobStatus) {
363 case JS_WaitClientRes:
364 case JS_WaitStoreRes:
365 case JS_WaitPriority:
367 case JS_WaitStartTime:
368 set_jcr_job_status(jcr, JS_Canceled);
369 bsendmsg(ua, _("JobId %d, Job %s marked to be canceled.\n"),
370 jcr->JobId, jcr->Job);
371 jobq_remove(&job_queue, jcr); /* attempt to remove it from queue */
375 set_jcr_job_status(jcr, JS_Canceled);
377 /* Cancel File daemon */
378 if (jcr->file_bsock) {
379 ua->jcr->client = jcr->client;
380 if (!connect_to_file_daemon(ua->jcr, 10, FDConnectTimeout, 1)) {
381 bsendmsg(ua, _("Failed to connect to File daemon.\n"));
384 Dmsg0(200, "Connected to file daemon\n");
385 fd = ua->jcr->file_bsock;
386 bnet_fsend(fd, "cancel Job=%s\n", jcr->Job);
387 while (bnet_recv(fd) >= 0) {
388 bsendmsg(ua, "%s", fd->msg);
390 bnet_sig(fd, BNET_TERMINATE);
392 ua->jcr->file_bsock = NULL;
395 /* Cancel Storage daemon */
396 if (jcr->store_bsock) {
397 if (!ua->jcr->storage) {
398 copy_storage(ua->jcr, jcr);
400 set_storage(ua->jcr, jcr->store);
402 if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
403 bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
406 Dmsg0(200, "Connected to storage daemon\n");
407 sd = ua->jcr->store_bsock;
408 bnet_fsend(sd, "cancel Job=%s\n", jcr->Job);
409 while (bnet_recv(sd) >= 0) {
410 bsendmsg(ua, "%s", sd->msg);
412 bnet_sig(sd, BNET_TERMINATE);
414 ua->jcr->store_bsock = NULL;
422 static void job_monitor_destructor(watchdog_t *self)
424 JCR *control_jcr = (JCR *) self->data;
426 free_jcr(control_jcr);
429 static void job_monitor_watchdog(watchdog_t *self)
431 JCR *control_jcr, *jcr;
433 control_jcr = (JCR *)self->data;
435 Dmsg1(800, "job_monitor_watchdog %p called\n", self);
442 if (jcr->JobId == 0) {
443 Dmsg2(800, "Skipping JCR %p (%s) with JobId 0\n",
445 /* Keep reference counts correct */
446 free_locked_jcr(jcr);
450 /* check MaxWaitTime */
451 cancel = job_check_maxwaittime(control_jcr, jcr);
453 /* check MaxRunTime */
454 cancel |= job_check_maxruntime(control_jcr, jcr);
457 Dmsg3(800, "Cancelling JCR %p jobid %d (%s)\n",
458 jcr, jcr->JobId, jcr->Job);
460 UAContext *ua = new_ua_context(jcr);
461 ua->jcr = control_jcr;
465 Dmsg1(800, "Have cancelled JCR %p\n", jcr);
468 /* Keep reference counts correct */
469 free_locked_jcr(jcr);
475 * Check if the maxwaittime has expired and it is possible
478 static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr)
481 bool ok_to_cancel = false;
484 if (job->MaxWaitTime == 0 && job->FullMaxWaitTime == 0 &&
485 job->IncMaxWaitTime == 0 && job->DiffMaxWaitTime == 0) {
488 if (jcr->JobLevel == L_FULL && job->FullMaxWaitTime != 0 &&
489 (watchdog_time - jcr->start_time) >= job->FullMaxWaitTime) {
491 } else if (jcr->JobLevel == L_DIFFERENTIAL && job->DiffMaxWaitTime != 0 &&
492 (watchdog_time - jcr->start_time) >= job->DiffMaxWaitTime) {
494 } else if (jcr->JobLevel == L_INCREMENTAL && job->IncMaxWaitTime != 0 &&
495 (watchdog_time - jcr->start_time) >= job->IncMaxWaitTime) {
497 } else if (job->MaxWaitTime != 0 &&
498 (watchdog_time - jcr->start_time) >= job->MaxWaitTime) {
504 Dmsg3(800, "Job %d (%s): MaxWaitTime of %d seconds exceeded, "
506 jcr->JobId, jcr->Job, job->MaxWaitTime);
507 switch (jcr->JobStatus) {
512 case JS_WaitStoreRes:
513 case JS_WaitClientRes:
515 case JS_WaitPriority:
517 case JS_WaitStartTime:
519 Dmsg0(200, "JCR blocked in #1\n");
522 Dmsg0(800, "JCR running, checking SD status\n");
523 switch (jcr->SDJobStatus) {
528 Dmsg0(800, "JCR blocked in #2\n");
531 Dmsg0(800, "JCR not blocked in #2\n");
536 case JS_ErrorTerminated:
539 Dmsg0(800, "JCR already dead in #3\n");
542 Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
545 Dmsg3(800, "MaxWaitTime result: %scancel JCR %p (%s)\n",
546 cancel ? "" : "do not ", jcr, jcr->job);
552 * Check if maxruntime has expired and if the job can be
555 static bool job_check_maxruntime(JCR *control_jcr, JCR *jcr)
559 if (jcr->job->MaxRunTime == 0) {
562 if ((watchdog_time - jcr->start_time) < jcr->job->MaxRunTime) {
563 Dmsg3(200, "Job %p (%s) with MaxRunTime %d not expired\n",
564 jcr, jcr->Job, jcr->job->MaxRunTime);
568 switch (jcr->JobStatus) {
574 case JS_WaitStoreRes:
575 case JS_WaitClientRes:
577 case JS_WaitPriority:
579 case JS_WaitStartTime:
584 case JS_ErrorTerminated:
590 Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
594 Dmsg3(200, "MaxRunTime result: %scancel JCR %p (%s)\n",
595 cancel ? "" : "do not ", jcr, jcr->job);
602 * Get or create a Client record for this Job
604 bool get_or_create_client_record(JCR *jcr)
608 memset(&cr, 0, sizeof(cr));
609 bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name));
610 cr.AutoPrune = jcr->client->AutoPrune;
611 cr.FileRetention = jcr->client->FileRetention;
612 cr.JobRetention = jcr->client->JobRetention;
613 if (!jcr->client_name) {
614 jcr->client_name = get_pool_memory(PM_NAME);
616 pm_strcpy(jcr->client_name, jcr->client->hdr.name);
617 if (!db_create_client_record(jcr, jcr->db, &cr)) {
618 Jmsg(jcr, M_FATAL, 0, _("Could not create Client record. ERR=%s\n"),
619 db_strerror(jcr->db));
622 jcr->jr.ClientId = cr.ClientId;
624 if (!jcr->client_uname) {
625 jcr->client_uname = get_pool_memory(PM_NAME);
627 pm_strcpy(jcr->client_uname, cr.Uname);
629 Dmsg2(100, "Created Client %s record %d\n", jcr->client->hdr.name,
634 bool get_or_create_fileset_record(JCR *jcr, FILESET_DBR *fsr)
637 * Get or Create FileSet record
639 memset(fsr, 0, sizeof(FILESET_DBR));
640 bstrncpy(fsr->FileSet, jcr->fileset->hdr.name, sizeof(fsr->FileSet));
641 if (jcr->fileset->have_MD5) {
642 struct MD5Context md5c;
643 unsigned char signature[16];
644 memcpy(&md5c, &jcr->fileset->md5c, sizeof(md5c));
645 MD5Final(signature, &md5c);
646 bin_to_base64(fsr->MD5, (char *)signature, 16); /* encode 16 bytes */
647 bstrncpy(jcr->fileset->MD5, fsr->MD5, sizeof(jcr->fileset->MD5));
649 Jmsg(jcr, M_WARNING, 0, _("FileSet MD5 signature not found.\n"));
651 if (!jcr->fileset->ignore_fs_changes ||
652 !db_get_fileset_record(jcr, jcr->db, fsr)) {
653 if (!db_create_fileset_record(jcr, jcr->db, fsr)) {
654 Jmsg(jcr, M_ERROR, 0, _("Could not create FileSet \"%s\" record. ERR=%s\n"),
655 fsr->FileSet, db_strerror(jcr->db));
659 jcr->jr.FileSetId = fsr->FileSetId;
661 if (fsr->created && jcr != NULL) {
662 Jmsg(jcr, M_INFO, 0, _("Created new FileSet record \"%s\" %s\n"),
663 fsr->FileSet, fsr->cCreateTime);
666 Dmsg2(119, "Created FileSet %s record %u\n", jcr->fileset->hdr.name,
671 void init_jcr_job_record(JCR *jcr)
673 jcr->jr.SchedTime = jcr->sched_time;
674 jcr->jr.StartTime = jcr->start_time;
675 jcr->jr.EndTime = 0; /* perhaps rescheduled, clear it */
676 jcr->jr.JobType = jcr->JobType;
677 jcr->jr.JobLevel = jcr->JobLevel;
678 jcr->jr.JobStatus = jcr->JobStatus;
679 jcr->jr.JobId = jcr->JobId;
680 bstrncpy(jcr->jr.Name, jcr->job->hdr.name, sizeof(jcr->jr.Name));
681 bstrncpy(jcr->jr.Job, jcr->Job, sizeof(jcr->jr.Job));
685 * Write status and such in DB
687 void update_job_end_record(JCR *jcr)
689 jcr->jr.EndTime = time(NULL);
690 jcr->end_time = jcr->jr.EndTime;
691 jcr->jr.JobId = jcr->JobId;
692 jcr->jr.JobStatus = jcr->JobStatus;
693 jcr->jr.JobFiles = jcr->JobFiles;
694 jcr->jr.JobBytes = jcr->JobBytes;
695 jcr->jr.VolSessionId = jcr->VolSessionId;
696 jcr->jr.VolSessionTime = jcr->VolSessionTime;
697 if (!db_update_job_end_record(jcr, jcr->db, &jcr->jr)) {
698 Jmsg(jcr, M_WARNING, 0, _("Error updating job record. %s"),
699 db_strerror(jcr->db));
704 * Takes base_name and appends (unique) current
705 * date and time to form unique job name.
707 * Returns: unique job name in jcr->Job
708 * date/time in jcr->start_time
710 void create_unique_job_name(JCR *jcr, const char *base_name)
712 /* Job start mutex */
713 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
714 static time_t last_start_time = 0;
717 char dt[MAX_TIME_LENGTH];
718 char name[MAX_NAME_LENGTH];
721 /* Guarantee unique start time -- maximum one per second, and
722 * thus unique Job Name
724 P(mutex); /* lock creation of jobs */
726 while (now == last_start_time) {
727 bmicrosleep(0, 500000);
730 last_start_time = now;
731 V(mutex); /* allow creation of jobs */
732 jcr->start_time = now;
733 /* Form Unique JobName */
734 localtime_r(&now, &tm);
735 /* Use only characters that are permitted in Windows filenames */
736 strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm);
737 bstrncpy(name, base_name, sizeof(name));
738 name[sizeof(name)-22] = 0; /* truncate if too long */
739 bsnprintf(jcr->Job, sizeof(jcr->Job), "%s.%s", name, dt); /* add date & time */
740 /* Convert spaces into underscores */
741 for (p=jcr->Job; *p; p++) {
748 /* Called directly from job rescheduling */
749 void dird_free_jcr_pointers(JCR *jcr)
751 if (jcr->sd_auth_key) {
752 free(jcr->sd_auth_key);
753 jcr->sd_auth_key = NULL;
759 if (jcr->file_bsock) {
760 Dmsg0(200, "Close File bsock\n");
761 bnet_close(jcr->file_bsock);
762 jcr->file_bsock = NULL;
764 if (jcr->store_bsock) {
765 Dmsg0(200, "Close Store bsock\n");
766 bnet_close(jcr->store_bsock);
767 jcr->store_bsock = NULL;
770 Dmsg0(200, "Free JCR fname\n");
771 free_pool_memory(jcr->fname);
775 Dmsg0(200, "Free JCR stime\n");
776 free_pool_memory(jcr->stime);
779 if (jcr->RestoreBootstrap) {
780 free(jcr->RestoreBootstrap);
781 jcr->RestoreBootstrap = NULL;
783 if (jcr->client_uname) {
784 free_pool_memory(jcr->client_uname);
785 jcr->client_uname = NULL;
787 if (jcr->term_wait_inited) {
788 pthread_cond_destroy(&jcr->term_wait);
789 jcr->term_wait_inited = false;
794 * Free the Job Control Record if no one is still using it.
795 * Called from main free_jcr() routine in src/lib/jcr.c so
796 * that we can do our Director specific cleanup of the jcr.
798 void dird_free_jcr(JCR *jcr)
800 Dmsg0(200, "Start dird free_jcr\n");
802 dird_free_jcr_pointers(jcr);
804 /* Delete lists setup to hold storage pointers */
808 jcr->job_end_push.destroy();
809 Dmsg0(200, "End dird free_jcr\n");
813 * Set some defaults in the JCR necessary to
814 * run. These items are pulled from the job
815 * definition as defaults, but can be overridden
816 * later either by the Run record in the Schedule resource,
817 * or by the Console program.
819 void set_jcr_defaults(JCR *jcr, JOB *job)
823 jcr->JobType = job->JobType;
824 switch (jcr->JobType) {
827 jcr->JobLevel = L_NONE;
830 jcr->JobLevel = job->JobLevel;
833 jcr->JobPriority = job->Priority;
834 /* Copy storage definitions -- deleted in dir_free_jcr above */
839 jcr->storage = New(alist(10, not_owned_by_alist));
840 foreach_alist(st, job->storage) {
841 jcr->storage->append(st);
845 jcr->store = (STORE *)jcr->storage->first();
847 jcr->client = job->client;
848 if (!jcr->client_name) {
849 jcr->client_name = get_pool_memory(PM_NAME);
851 pm_strcpy(jcr->client_name, jcr->client->hdr.name);
852 jcr->pool = job->pool;
853 jcr->full_pool = job->full_pool;
854 jcr->inc_pool = job->inc_pool;
855 jcr->dif_pool = job->dif_pool;
856 jcr->catalog = job->client->catalog;
857 jcr->fileset = job->fileset;
858 jcr->messages = job->messages;
859 jcr->spool_data = job->spool_data;
860 jcr->write_part_after_job = job->write_part_after_job;
861 if (jcr->RestoreBootstrap) {
862 free(jcr->RestoreBootstrap);
863 jcr->RestoreBootstrap = NULL;
865 /* This can be overridden by Console program */
866 if (job->RestoreBootstrap) {
867 jcr->RestoreBootstrap = bstrdup(job->RestoreBootstrap);
869 /* This can be overridden by Console program */
870 jcr->verify_job = job->verify_job;
871 /* If no default level given, set one */
872 if (jcr->JobLevel == 0) {
873 switch (jcr->JobType) {
875 jcr->JobLevel = L_VERIFY_CATALOG;
878 jcr->JobLevel = L_INCREMENTAL;
882 jcr->JobLevel = L_NONE;
891 * copy the storage definitions from an old JCR to a new one
893 void copy_storage(JCR *new_jcr, JCR *old_jcr)
895 if (old_jcr->storage) {
897 if (old_jcr->storage) {
898 delete old_jcr->storage;
900 new_jcr->storage = New(alist(10, not_owned_by_alist));
901 foreach_alist(st, old_jcr->storage) {
902 new_jcr->storage->append(st);
905 if (old_jcr->store) {
906 new_jcr->store = old_jcr->store;
907 } else if (new_jcr->storage) {
908 new_jcr->store = (STORE *)new_jcr->storage->first();
912 /* Set storage override */
913 void set_storage(JCR *jcr, STORE *store)
918 foreach_alist(storage, jcr->storage) {
919 if (store == storage) {
923 /* Store not in list, so add it */
924 jcr->storage->prepend(store);