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");
155 free_memory(jcr->fname);
164 * This is the engine called by jobq.c:jobq_add() when we were pulled
165 * from the work queue.
166 * At this point, we are running in our own thread and all
167 * necessary resources are allocated -- see jobq.c
169 static void *job_thread(void *arg)
171 JCR *jcr = (JCR *)arg;
173 jcr->my_thread_id = pthread_self();
174 pthread_detach(jcr->my_thread_id);
175 sm_check(__FILE__, __LINE__, true);
177 Dmsg0(200, "=====Start Job=========\n");
178 jcr->start_time = time(NULL); /* set the real start time */
179 jcr->jr.StartTime = jcr->start_time;
181 if (jcr->job->MaxStartDelay != 0 && jcr->job->MaxStartDelay <
182 (utime_t)(jcr->start_time - jcr->sched_time)) {
183 Jmsg(jcr, M_FATAL, 0, _("Job canceled because max start delay time exceeded.\n"));
184 set_jcr_job_status(jcr, JS_Canceled);
188 * Note, we continue, even if the job is canceled above. This
189 * will permit proper setting of the job start record and
190 * the error (cancel) will be picked up below.
193 generate_job_event(jcr, "JobInit");
194 set_jcr_job_status(jcr, JS_Running); /* this will be set only if no error */
197 jcr->fname = get_pool_memory(PM_FNAME);
201 * Now, do pre-run stuff, like setting job level (Inc/diff, ...)
202 * this allows us to setup a proper job start record for restarting
203 * in case of later errors.
205 switch (jcr->JobType) {
207 if (!do_backup_init(jcr)) {
208 backup_cleanup(jcr, JS_ErrorTerminated);
212 if (!do_verify_init(jcr)) {
213 verify_cleanup(jcr, JS_ErrorTerminated);
217 if (!do_restore_init(jcr)) {
218 restore_cleanup(jcr, JS_ErrorTerminated);
222 if (!do_admin_init(jcr)) {
223 admin_cleanup(jcr, JS_ErrorTerminated);
229 if (!do_mac_init(jcr)) { /* migration, archive, copy */
230 mac_cleanup(jcr, JS_ErrorTerminated);
234 Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
235 set_jcr_job_status(jcr, JS_ErrorTerminated);
239 if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
240 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
243 if (job_canceled(jcr)) {
244 update_job_end_record(jcr);
249 if (jcr->job->RunBeforeJob) {
250 POOLMEM *before = get_pool_memory(PM_FNAME);
253 char line[MAXSTRING];
255 before = edit_job_codes(jcr, before, jcr->job->RunBeforeJob, "");
256 bpipe = open_bpipe(before, 0, "r");
257 free_pool_memory(before);
258 while (fgets(line, sizeof(line), bpipe->rfd)) {
259 Jmsg(jcr, M_INFO, 0, _("RunBefore: %s"), line);
261 status = close_bpipe(bpipe);
264 Jmsg(jcr, M_FATAL, 0, _("RunBeforeJob error: ERR=%s\n"), be.strerror(status));
265 set_jcr_job_status(jcr, JS_FatalError);
266 update_job_end_record(jcr);
271 generate_job_event(jcr, "JobRun");
273 switch (jcr->JobType) {
275 if (do_backup(jcr)) {
278 backup_cleanup(jcr, JS_ErrorTerminated);
282 if (do_verify(jcr)) {
285 verify_cleanup(jcr, JS_ErrorTerminated);
289 if (do_restore(jcr)) {
292 restore_cleanup(jcr, JS_ErrorTerminated);
299 admin_cleanup(jcr, JS_ErrorTerminated);
305 if (do_mac(jcr)) { /* migration, archive, copy */
308 mac_cleanup(jcr, JS_ErrorTerminated);
312 Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
315 if ((jcr->job->RunAfterJob && jcr->JobStatus == JS_Terminated) ||
316 (jcr->job->RunAfterFailedJob && jcr->JobStatus != JS_Terminated)) {
317 POOLMEM *after = get_pool_memory(PM_FNAME);
320 char line[MAXSTRING];
322 if (jcr->JobStatus == JS_Terminated) {
323 after = edit_job_codes(jcr, after, jcr->job->RunAfterJob, "");
325 after = edit_job_codes(jcr, after, jcr->job->RunAfterFailedJob, "");
327 bpipe = open_bpipe(after, 0, "r");
328 free_pool_memory(after);
329 while (fgets(line, sizeof(line), bpipe->rfd)) {
330 Jmsg(jcr, M_INFO, 0, _("RunAfter: %s"), line);
332 status = close_bpipe(bpipe);
334 * Note, if we get an error here, do not mark the
335 * job in error, simply report the error condition.
339 if (jcr->JobStatus == JS_Terminated) {
340 Jmsg(jcr, M_WARNING, 0, _("RunAfterJob error: ERR=%s\n"), be.strerror(status));
342 Jmsg(jcr, M_FATAL, 0, _("RunAfterFailedJob error: ERR=%s\n"), be.strerror(status));
346 /* Send off any queued messages */
347 if (jcr->msg_queue->size() > 0) {
348 dequeue_messages(jcr);
353 generate_daemon_event(jcr, "JobEnd");
354 Dmsg1(50, "======== End Job stat=%c ==========\n", jcr->JobStatus);
355 sm_check(__FILE__, __LINE__, true);
361 * Cancel a job -- typically called by the UA (Console program), but may also
362 * be called by the job watchdog.
364 * Returns: 1 if cancel appears to be successful
365 * 0 on failure. Message sent to ua->jcr.
367 int cancel_job(UAContext *ua, JCR *jcr)
371 set_jcr_job_status(jcr, JS_Canceled);
373 switch (jcr->JobStatus) {
376 case JS_WaitClientRes:
377 case JS_WaitStoreRes:
378 case JS_WaitPriority:
380 case JS_WaitStartTime:
381 bsendmsg(ua, _("JobId %d, Job %s marked to be canceled.\n"),
382 jcr->JobId, jcr->Job);
383 jobq_remove(&job_queue, jcr); /* attempt to remove it from queue */
388 /* Cancel File daemon */
389 if (jcr->file_bsock) {
390 ua->jcr->client = jcr->client;
391 if (!connect_to_file_daemon(ua->jcr, 10, FDConnectTimeout, 1)) {
392 bsendmsg(ua, _("Failed to connect to File daemon.\n"));
395 Dmsg0(200, "Connected to file daemon\n");
396 fd = ua->jcr->file_bsock;
397 bnet_fsend(fd, "cancel Job=%s\n", jcr->Job);
398 while (bnet_recv(fd) >= 0) {
399 bsendmsg(ua, "%s", fd->msg);
401 bnet_sig(fd, BNET_TERMINATE);
403 ua->jcr->file_bsock = NULL;
406 /* Cancel Storage daemon */
407 if (jcr->store_bsock) {
408 if (!ua->jcr->storage) {
409 copy_storage(ua->jcr, jcr);
411 set_storage(ua->jcr, jcr->store);
413 if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
414 bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
417 Dmsg0(200, "Connected to storage daemon\n");
418 sd = ua->jcr->store_bsock;
419 bnet_fsend(sd, "cancel Job=%s\n", jcr->Job);
420 while (bnet_recv(sd) >= 0) {
421 bsendmsg(ua, "%s", sd->msg);
423 bnet_sig(sd, BNET_TERMINATE);
425 ua->jcr->store_bsock = NULL;
433 static void job_monitor_destructor(watchdog_t *self)
435 JCR *control_jcr = (JCR *) self->data;
437 free_jcr(control_jcr);
440 static void job_monitor_watchdog(watchdog_t *self)
442 JCR *control_jcr, *jcr;
444 control_jcr = (JCR *)self->data;
446 Dmsg1(800, "job_monitor_watchdog %p called\n", self);
453 if (jcr->JobId == 0) {
454 Dmsg2(800, "Skipping JCR %p (%s) with JobId 0\n",
456 /* Keep reference counts correct */
457 free_locked_jcr(jcr);
461 /* check MaxWaitTime */
462 cancel = job_check_maxwaittime(control_jcr, jcr);
464 /* check MaxRunTime */
465 cancel |= job_check_maxruntime(control_jcr, jcr);
468 Dmsg3(800, "Cancelling JCR %p jobid %d (%s)\n",
469 jcr, jcr->JobId, jcr->Job);
471 UAContext *ua = new_ua_context(jcr);
472 ua->jcr = control_jcr;
476 Dmsg1(800, "Have cancelled JCR %p\n", jcr);
479 /* Keep reference counts correct */
480 free_locked_jcr(jcr);
486 * Check if the maxwaittime has expired and it is possible
489 static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr)
492 bool ok_to_cancel = false;
495 if (job->MaxWaitTime == 0 && job->FullMaxWaitTime == 0 &&
496 job->IncMaxWaitTime == 0 && job->DiffMaxWaitTime == 0) {
499 if (jcr->JobLevel == L_FULL && job->FullMaxWaitTime != 0 &&
500 (watchdog_time - jcr->start_time) >= job->FullMaxWaitTime) {
502 } else if (jcr->JobLevel == L_DIFFERENTIAL && job->DiffMaxWaitTime != 0 &&
503 (watchdog_time - jcr->start_time) >= job->DiffMaxWaitTime) {
505 } else if (jcr->JobLevel == L_INCREMENTAL && job->IncMaxWaitTime != 0 &&
506 (watchdog_time - jcr->start_time) >= job->IncMaxWaitTime) {
508 } else if (job->MaxWaitTime != 0 &&
509 (watchdog_time - jcr->start_time) >= job->MaxWaitTime) {
515 Dmsg3(800, "Job %d (%s): MaxWaitTime of %d seconds exceeded, "
517 jcr->JobId, jcr->Job, job->MaxWaitTime);
518 switch (jcr->JobStatus) {
523 case JS_WaitStoreRes:
524 case JS_WaitClientRes:
526 case JS_WaitPriority:
528 case JS_WaitStartTime:
530 Dmsg0(200, "JCR blocked in #1\n");
533 Dmsg0(800, "JCR running, checking SD status\n");
534 switch (jcr->SDJobStatus) {
539 Dmsg0(800, "JCR blocked in #2\n");
542 Dmsg0(800, "JCR not blocked in #2\n");
547 case JS_ErrorTerminated:
550 Dmsg0(800, "JCR already dead in #3\n");
553 Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
556 Dmsg3(800, "MaxWaitTime result: %scancel JCR %p (%s)\n",
557 cancel ? "" : "do not ", jcr, jcr->job);
563 * Check if maxruntime has expired and if the job can be
566 static bool job_check_maxruntime(JCR *control_jcr, JCR *jcr)
570 if (jcr->job->MaxRunTime == 0) {
573 if ((watchdog_time - jcr->start_time) < jcr->job->MaxRunTime) {
574 Dmsg3(200, "Job %p (%s) with MaxRunTime %d not expired\n",
575 jcr, jcr->Job, jcr->job->MaxRunTime);
579 switch (jcr->JobStatus) {
585 case JS_WaitStoreRes:
586 case JS_WaitClientRes:
588 case JS_WaitPriority:
590 case JS_WaitStartTime:
595 case JS_ErrorTerminated:
601 Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
605 Dmsg3(200, "MaxRunTime result: %scancel JCR %p (%s)\n",
606 cancel ? "" : "do not ", jcr, jcr->job);
613 * Get or create a Client record for this Job
615 bool get_or_create_client_record(JCR *jcr)
619 memset(&cr, 0, sizeof(cr));
620 bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name));
621 cr.AutoPrune = jcr->client->AutoPrune;
622 cr.FileRetention = jcr->client->FileRetention;
623 cr.JobRetention = jcr->client->JobRetention;
624 if (!jcr->client_name) {
625 jcr->client_name = get_pool_memory(PM_NAME);
627 pm_strcpy(jcr->client_name, jcr->client->hdr.name);
628 if (!db_create_client_record(jcr, jcr->db, &cr)) {
629 Jmsg(jcr, M_FATAL, 0, _("Could not create Client record. ERR=%s\n"),
630 db_strerror(jcr->db));
633 jcr->jr.ClientId = cr.ClientId;
635 if (!jcr->client_uname) {
636 jcr->client_uname = get_pool_memory(PM_NAME);
638 pm_strcpy(jcr->client_uname, cr.Uname);
640 Dmsg2(100, "Created Client %s record %d\n", jcr->client->hdr.name,
645 bool get_or_create_fileset_record(JCR *jcr, FILESET_DBR *fsr)
648 * Get or Create FileSet record
650 memset(fsr, 0, sizeof(FILESET_DBR));
651 bstrncpy(fsr->FileSet, jcr->fileset->hdr.name, sizeof(fsr->FileSet));
652 if (jcr->fileset->have_MD5) {
653 struct MD5Context md5c;
654 unsigned char signature[16];
655 memcpy(&md5c, &jcr->fileset->md5c, sizeof(md5c));
656 MD5Final(signature, &md5c);
657 bin_to_base64(fsr->MD5, (char *)signature, 16); /* encode 16 bytes */
658 bstrncpy(jcr->fileset->MD5, fsr->MD5, sizeof(jcr->fileset->MD5));
660 Jmsg(jcr, M_WARNING, 0, _("FileSet MD5 signature not found.\n"));
662 if (!jcr->fileset->ignore_fs_changes ||
663 !db_get_fileset_record(jcr, jcr->db, fsr)) {
664 if (!db_create_fileset_record(jcr, jcr->db, fsr)) {
665 Jmsg(jcr, M_ERROR, 0, _("Could not create FileSet \"%s\" record. ERR=%s\n"),
666 fsr->FileSet, db_strerror(jcr->db));
670 jcr->jr.FileSetId = fsr->FileSetId;
672 if (fsr->created && jcr != NULL) {
673 Jmsg(jcr, M_INFO, 0, _("Created new FileSet record \"%s\" %s\n"),
674 fsr->FileSet, fsr->cCreateTime);
677 Dmsg2(119, "Created FileSet %s record %u\n", jcr->fileset->hdr.name,
682 void init_jcr_job_record(JCR *jcr)
684 jcr->jr.SchedTime = jcr->sched_time;
685 jcr->jr.StartTime = jcr->start_time;
686 jcr->jr.EndTime = 0; /* perhaps rescheduled, clear it */
687 jcr->jr.JobType = jcr->JobType;
688 jcr->jr.JobLevel = jcr->JobLevel;
689 jcr->jr.JobStatus = jcr->JobStatus;
690 jcr->jr.JobId = jcr->JobId;
691 bstrncpy(jcr->jr.Name, jcr->job->hdr.name, sizeof(jcr->jr.Name));
692 bstrncpy(jcr->jr.Job, jcr->Job, sizeof(jcr->jr.Job));
696 * Write status and such in DB
698 void update_job_end_record(JCR *jcr)
700 jcr->jr.EndTime = time(NULL);
701 jcr->end_time = jcr->jr.EndTime;
702 jcr->jr.JobId = jcr->JobId;
703 jcr->jr.JobStatus = jcr->JobStatus;
704 jcr->jr.JobFiles = jcr->JobFiles;
705 jcr->jr.JobBytes = jcr->JobBytes;
706 jcr->jr.VolSessionId = jcr->VolSessionId;
707 jcr->jr.VolSessionTime = jcr->VolSessionTime;
708 if (!db_update_job_end_record(jcr, jcr->db, &jcr->jr)) {
709 Jmsg(jcr, M_WARNING, 0, _("Error updating job record. %s"),
710 db_strerror(jcr->db));
715 * Takes base_name and appends (unique) current
716 * date and time to form unique job name.
718 * Returns: unique job name in jcr->Job
719 * date/time in jcr->start_time
721 void create_unique_job_name(JCR *jcr, const char *base_name)
723 /* Job start mutex */
724 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
725 static time_t last_start_time = 0;
728 char dt[MAX_TIME_LENGTH];
729 char name[MAX_NAME_LENGTH];
732 /* Guarantee unique start time -- maximum one per second, and
733 * thus unique Job Name
735 P(mutex); /* lock creation of jobs */
737 while (now == last_start_time) {
738 bmicrosleep(0, 500000);
741 last_start_time = now;
742 V(mutex); /* allow creation of jobs */
743 jcr->start_time = now;
744 /* Form Unique JobName */
745 localtime_r(&now, &tm);
746 /* Use only characters that are permitted in Windows filenames */
747 strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm);
748 bstrncpy(name, base_name, sizeof(name));
749 name[sizeof(name)-22] = 0; /* truncate if too long */
750 bsnprintf(jcr->Job, sizeof(jcr->Job), "%s.%s", name, dt); /* add date & time */
751 /* Convert spaces into underscores */
752 for (p=jcr->Job; *p; p++) {
759 /* Called directly from job rescheduling */
760 void dird_free_jcr_pointers(JCR *jcr)
762 if (jcr->sd_auth_key) {
763 free(jcr->sd_auth_key);
764 jcr->sd_auth_key = NULL;
770 if (jcr->file_bsock) {
771 Dmsg0(200, "Close File bsock\n");
772 bnet_close(jcr->file_bsock);
773 jcr->file_bsock = NULL;
775 if (jcr->store_bsock) {
776 Dmsg0(200, "Close Store bsock\n");
777 bnet_close(jcr->store_bsock);
778 jcr->store_bsock = NULL;
781 Dmsg0(200, "Free JCR fname\n");
782 free_pool_memory(jcr->fname);
786 Dmsg0(200, "Free JCR stime\n");
787 free_pool_memory(jcr->stime);
790 if (jcr->RestoreBootstrap) {
791 free(jcr->RestoreBootstrap);
792 jcr->RestoreBootstrap = NULL;
794 if (jcr->client_uname) {
795 free_pool_memory(jcr->client_uname);
796 jcr->client_uname = NULL;
798 if (jcr->term_wait_inited) {
799 pthread_cond_destroy(&jcr->term_wait);
800 jcr->term_wait_inited = false;
805 * Free the Job Control Record if no one is still using it.
806 * Called from main free_jcr() routine in src/lib/jcr.c so
807 * that we can do our Director specific cleanup of the jcr.
809 void dird_free_jcr(JCR *jcr)
811 Dmsg0(200, "Start dird free_jcr\n");
813 dird_free_jcr_pointers(jcr);
815 /* Delete lists setup to hold storage pointers */
819 jcr->job_end_push.destroy();
820 Dmsg0(200, "End dird free_jcr\n");
824 * Set some defaults in the JCR necessary to
825 * run. These items are pulled from the job
826 * definition as defaults, but can be overridden
827 * later either by the Run record in the Schedule resource,
828 * or by the Console program.
830 void set_jcr_defaults(JCR *jcr, JOB *job)
834 jcr->JobType = job->JobType;
835 switch (jcr->JobType) {
838 jcr->JobLevel = L_NONE;
841 jcr->JobLevel = job->JobLevel;
844 jcr->JobPriority = job->Priority;
845 /* Copy storage definitions -- deleted in dir_free_jcr above */
850 jcr->storage = New(alist(10, not_owned_by_alist));
851 foreach_alist(st, job->storage) {
852 jcr->storage->append(st);
856 jcr->store = (STORE *)jcr->storage->first();
858 jcr->client = job->client;
859 if (!jcr->client_name) {
860 jcr->client_name = get_pool_memory(PM_NAME);
862 pm_strcpy(jcr->client_name, jcr->client->hdr.name);
863 jcr->pool = job->pool;
864 jcr->full_pool = job->full_pool;
865 jcr->inc_pool = job->inc_pool;
866 jcr->dif_pool = job->dif_pool;
867 jcr->catalog = job->client->catalog;
868 jcr->fileset = job->fileset;
869 jcr->messages = job->messages;
870 jcr->spool_data = job->spool_data;
871 jcr->write_part_after_job = job->write_part_after_job;
872 if (jcr->RestoreBootstrap) {
873 free(jcr->RestoreBootstrap);
874 jcr->RestoreBootstrap = NULL;
876 /* This can be overridden by Console program */
877 if (job->RestoreBootstrap) {
878 jcr->RestoreBootstrap = bstrdup(job->RestoreBootstrap);
880 /* This can be overridden by Console program */
881 jcr->verify_job = job->verify_job;
882 /* If no default level given, set one */
883 if (jcr->JobLevel == 0) {
884 switch (jcr->JobType) {
886 jcr->JobLevel = L_VERIFY_CATALOG;
889 jcr->JobLevel = L_INCREMENTAL;
893 jcr->JobLevel = L_NONE;
902 * copy the storage definitions from an old JCR to a new one
904 void copy_storage(JCR *new_jcr, JCR *old_jcr)
906 if (old_jcr->storage) {
908 if (old_jcr->storage) {
909 delete old_jcr->storage;
911 new_jcr->storage = New(alist(10, not_owned_by_alist));
912 foreach_alist(st, old_jcr->storage) {
913 new_jcr->storage->append(st);
916 if (old_jcr->store) {
917 new_jcr->store = old_jcr->store;
918 } else if (new_jcr->storage) {
919 new_jcr->store = (STORE *)new_jcr->storage->first();
923 /* Set storage override */
924 void set_storage(JCR *jcr, STORE *store)
929 foreach_alist(storage, jcr->storage) {
930 if (store == storage) {
934 /* Store not in list, so add it */
935 jcr->storage->prepend(store);