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;
96 generate_daemon_event(jcr, "StartJob");
101 Dmsg0(50, "Open database\n");
102 jcr->db=db_init_database(jcr, jcr->catalog->db_name, jcr->catalog->db_user,
103 jcr->catalog->db_password, jcr->catalog->db_address,
104 jcr->catalog->db_port, jcr->catalog->db_socket,
105 jcr->catalog->mult_db_connections);
106 if (!jcr->db || !db_open_database(jcr, jcr->db)) {
107 Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"),
108 jcr->catalog->db_name);
110 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
114 Dmsg0(50, "DB opened\n");
119 create_unique_job_name(jcr, jcr->job->hdr.name);
120 set_jcr_job_status(jcr, JS_Created);
121 init_jcr_job_record(jcr);
122 if (!db_create_job_record(jcr, jcr->db, &jcr->jr)) {
123 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
126 JobId = jcr->JobId = jcr->jr.JobId;
128 Dmsg4(100, "Created job record JobId=%d Name=%s Type=%c Level=%c\n",
129 jcr->JobId, jcr->Job, jcr->jr.JobType, jcr->jr.JobLevel);
131 if (!get_or_create_client_record(jcr)) {
136 jcr->fname = get_pool_memory(PM_FNAME);
139 /* Now, do pre-run stuff, like setting job level (Inc/diff, ...) */
140 switch (jcr->JobType) {
142 if (!do_backup_init(jcr)) {
143 backup_cleanup(jcr, JS_ErrorTerminated);
147 if (!do_verify_init(jcr)) {
148 verify_cleanup(jcr, JS_ErrorTerminated);
152 if (!do_restore_init(jcr)) {
153 restore_cleanup(jcr, JS_ErrorTerminated);
157 if (!do_admin_init(jcr)) {
158 admin_cleanup(jcr, JS_ErrorTerminated);
164 if (!do_mac_init(jcr)) { /* migration, archive, copy */
165 mac_cleanup(jcr, JS_ErrorTerminated);
169 Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
170 set_jcr_job_status(jcr, JS_ErrorTerminated);
173 if (job_canceled(jcr)) {
177 Dmsg0(200, "Add jrc to work queue\n");
179 /* Queue the job to be run */
180 if ((stat = jobq_add(&job_queue, jcr)) != 0) {
182 Jmsg(jcr, M_FATAL, 0, _("Could not add job queue: ERR=%s\n"), be.strerror(stat));
186 Dmsg0(100, "Done run_job()\n");
193 free_memory(jcr->fname);
203 * This is the engine called by jobq.c:jobq_add() when we were pulled
204 * from the work queue.
205 * At this point, we are running in our own thread and all
206 * necessary resources are allocated -- see jobq.c
208 static void *job_thread(void *arg)
210 JCR *jcr = (JCR *)arg;
212 jcr->my_thread_id = pthread_self();
213 pthread_detach(jcr->my_thread_id);
214 sm_check(__FILE__, __LINE__, true);
217 Dmsg0(200, "=====Start Job=========\n");
218 jcr->start_time = time(NULL); /* set the real start time */
219 jcr->jr.StartTime = jcr->start_time;
220 set_jcr_job_status(jcr, JS_Running);
221 if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
222 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
225 if (job_canceled(jcr)) {
226 update_job_end_record(jcr);
227 } else if (jcr->job->MaxStartDelay != 0 && jcr->job->MaxStartDelay <
228 (utime_t)(jcr->start_time - jcr->sched_time)) {
229 Jmsg(jcr, M_FATAL, 0, _("Job canceled because max start delay time exceeded.\n"));
230 set_jcr_job_status(jcr, JS_Canceled);
231 update_job_end_record(jcr);
235 if (jcr->job->RunBeforeJob) {
236 POOLMEM *before = get_pool_memory(PM_FNAME);
239 char line[MAXSTRING];
241 before = edit_job_codes(jcr, before, jcr->job->RunBeforeJob, "");
242 bpipe = open_bpipe(before, 0, "r");
243 free_pool_memory(before);
244 while (fgets(line, sizeof(line), bpipe->rfd)) {
245 Jmsg(jcr, M_INFO, 0, _("RunBefore: %s"), line);
247 status = close_bpipe(bpipe);
250 Jmsg(jcr, M_FATAL, 0, _("RunBeforeJob error: ERR=%s\n"), be.strerror(status));
251 set_jcr_job_status(jcr, JS_FatalError);
252 update_job_end_record(jcr);
256 switch (jcr->JobType) {
258 if (do_backup(jcr)) {
261 backup_cleanup(jcr, JS_ErrorTerminated);
265 if (do_verify(jcr)) {
268 verify_cleanup(jcr, JS_ErrorTerminated);
272 if (do_restore(jcr)) {
275 restore_cleanup(jcr, JS_ErrorTerminated);
282 admin_cleanup(jcr, JS_ErrorTerminated);
288 if (do_mac(jcr)) { /* migration, archive, copy */
291 mac_cleanup(jcr, JS_ErrorTerminated);
295 Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
298 if ((jcr->job->RunAfterJob && jcr->JobStatus == JS_Terminated) ||
299 (jcr->job->RunAfterFailedJob && jcr->JobStatus != JS_Terminated)) {
300 POOLMEM *after = get_pool_memory(PM_FNAME);
303 char line[MAXSTRING];
305 if (jcr->JobStatus == JS_Terminated) {
306 after = edit_job_codes(jcr, after, jcr->job->RunAfterJob, "");
308 after = edit_job_codes(jcr, after, jcr->job->RunAfterFailedJob, "");
310 bpipe = open_bpipe(after, 0, "r");
311 free_pool_memory(after);
312 while (fgets(line, sizeof(line), bpipe->rfd)) {
313 Jmsg(jcr, M_INFO, 0, _("RunAfter: %s"), line);
315 status = close_bpipe(bpipe);
317 * Note, if we get an error here, do not mark the
318 * job in error, simply report the error condition.
322 if (jcr->JobStatus == JS_Terminated) {
323 Jmsg(jcr, M_WARNING, 0, _("RunAfterJob error: ERR=%s\n"), be.strerror(status));
325 Jmsg(jcr, M_FATAL, 0, _("RunAfterFailedJob error: ERR=%s\n"), be.strerror(status));
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 if (fsr->created && jcr != NULL) {
657 Jmsg(jcr, M_INFO, 0, _("Created new FileSet record \"%s\" %s\n"),
658 fsr->FileSet, fsr->cCreateTime);
661 Dmsg2(119, "Created FileSet %s record %u\n", jcr->fileset->hdr.name,
666 void init_jcr_job_record(JCR *jcr)
668 jcr->jr.SchedTime = jcr->sched_time;
669 jcr->jr.StartTime = jcr->start_time;
670 jcr->jr.EndTime = 0; /* perhaps rescheduled, clear it */
671 jcr->jr.JobType = jcr->JobType;
672 jcr->jr.JobLevel = jcr->JobLevel;
673 jcr->jr.JobStatus = jcr->JobStatus;
674 jcr->jr.JobId = jcr->JobId;
675 bstrncpy(jcr->jr.Name, jcr->job->hdr.name, sizeof(jcr->jr.Name));
676 bstrncpy(jcr->jr.Job, jcr->Job, sizeof(jcr->jr.Job));
680 * Write status and such in DB
682 void update_job_end_record(JCR *jcr)
684 jcr->jr.EndTime = time(NULL);
685 jcr->end_time = jcr->jr.EndTime;
686 jcr->jr.JobId = jcr->JobId;
687 jcr->jr.JobStatus = jcr->JobStatus;
688 jcr->jr.JobFiles = jcr->JobFiles;
689 jcr->jr.JobBytes = jcr->JobBytes;
690 jcr->jr.VolSessionId = jcr->VolSessionId;
691 jcr->jr.VolSessionTime = jcr->VolSessionTime;
692 if (!db_update_job_end_record(jcr, jcr->db, &jcr->jr)) {
693 Jmsg(jcr, M_WARNING, 0, _("Error updating job record. %s"),
694 db_strerror(jcr->db));
699 * Takes base_name and appends (unique) current
700 * date and time to form unique job name.
702 * Returns: unique job name in jcr->Job
703 * date/time in jcr->start_time
705 void create_unique_job_name(JCR *jcr, const char *base_name)
707 /* Job start mutex */
708 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
709 static time_t last_start_time = 0;
712 char dt[MAX_TIME_LENGTH];
713 char name[MAX_NAME_LENGTH];
716 /* Guarantee unique start time -- maximum one per second, and
717 * thus unique Job Name
719 P(mutex); /* lock creation of jobs */
721 while (now == last_start_time) {
722 bmicrosleep(0, 500000);
725 last_start_time = now;
726 V(mutex); /* allow creation of jobs */
727 jcr->start_time = now;
728 /* Form Unique JobName */
729 localtime_r(&now, &tm);
730 /* Use only characters that are permitted in Windows filenames */
731 strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm);
732 bstrncpy(name, base_name, sizeof(name));
733 name[sizeof(name)-22] = 0; /* truncate if too long */
734 bsnprintf(jcr->Job, sizeof(jcr->Job), "%s.%s", name, dt); /* add date & time */
735 /* Convert spaces into underscores */
736 for (p=jcr->Job; *p; p++) {
743 /* Called directly from job rescheduling */
744 void dird_free_jcr_pointers(JCR *jcr)
746 if (jcr->sd_auth_key) {
747 free(jcr->sd_auth_key);
748 jcr->sd_auth_key = NULL;
754 if (jcr->file_bsock) {
755 Dmsg0(200, "Close File bsock\n");
756 bnet_close(jcr->file_bsock);
757 jcr->file_bsock = NULL;
759 if (jcr->store_bsock) {
760 Dmsg0(200, "Close Store bsock\n");
761 bnet_close(jcr->store_bsock);
762 jcr->store_bsock = NULL;
765 Dmsg0(200, "Free JCR fname\n");
766 free_pool_memory(jcr->fname);
770 Dmsg0(200, "Free JCR stime\n");
771 free_pool_memory(jcr->stime);
774 if (jcr->RestoreBootstrap) {
775 free(jcr->RestoreBootstrap);
776 jcr->RestoreBootstrap = NULL;
778 if (jcr->client_uname) {
779 free_pool_memory(jcr->client_uname);
780 jcr->client_uname = NULL;
782 if (jcr->term_wait_inited) {
783 pthread_cond_destroy(&jcr->term_wait);
784 jcr->term_wait_inited = false;
789 * Free the Job Control Record if no one is still using it.
790 * Called from main free_jcr() routine in src/lib/jcr.c so
791 * that we can do our Director specific cleanup of the jcr.
793 void dird_free_jcr(JCR *jcr)
795 Dmsg0(200, "Start dird free_jcr\n");
797 dird_free_jcr_pointers(jcr);
799 /* Delete lists setup to hold storage pointers */
803 jcr->job_end_push.destroy();
804 Dmsg0(200, "End dird free_jcr\n");
808 * Set some defaults in the JCR necessary to
809 * run. These items are pulled from the job
810 * definition as defaults, but can be overridden
811 * later either by the Run record in the Schedule resource,
812 * or by the Console program.
814 void set_jcr_defaults(JCR *jcr, JOB *job)
818 jcr->JobType = job->JobType;
819 switch (jcr->JobType) {
822 jcr->JobLevel = L_NONE;
825 jcr->JobLevel = job->JobLevel;
828 jcr->JobPriority = job->Priority;
829 /* Copy storage definitions -- deleted in dir_free_jcr above */
834 jcr->storage = New(alist(10, not_owned_by_alist));
835 foreach_alist(st, job->storage) {
836 jcr->storage->append(st);
840 jcr->store = (STORE *)jcr->storage->first();
842 jcr->client = job->client;
843 if (!jcr->client_name) {
844 jcr->client_name = get_pool_memory(PM_NAME);
846 pm_strcpy(jcr->client_name, jcr->client->hdr.name);
847 jcr->pool = job->pool;
848 jcr->full_pool = job->full_pool;
849 jcr->inc_pool = job->inc_pool;
850 jcr->dif_pool = job->dif_pool;
851 jcr->catalog = job->client->catalog;
852 jcr->fileset = job->fileset;
853 jcr->messages = job->messages;
854 jcr->spool_data = job->spool_data;
855 jcr->write_part_after_job = job->write_part_after_job;
856 if (jcr->RestoreBootstrap) {
857 free(jcr->RestoreBootstrap);
858 jcr->RestoreBootstrap = NULL;
860 /* This can be overridden by Console program */
861 if (job->RestoreBootstrap) {
862 jcr->RestoreBootstrap = bstrdup(job->RestoreBootstrap);
864 /* This can be overridden by Console program */
865 jcr->verify_job = job->verify_job;
866 /* If no default level given, set one */
867 if (jcr->JobLevel == 0) {
868 switch (jcr->JobType) {
870 jcr->JobLevel = L_VERIFY_CATALOG;
873 jcr->JobLevel = L_INCREMENTAL;
877 jcr->JobLevel = L_NONE;
886 * copy the storage definitions from an old JCR to a new one
888 void copy_storage(JCR *new_jcr, JCR *old_jcr)
890 if (old_jcr->storage) {
892 if (old_jcr->storage) {
893 delete old_jcr->storage;
895 new_jcr->storage = New(alist(10, not_owned_by_alist));
896 foreach_alist(st, old_jcr->storage) {
897 new_jcr->storage->append(st);
900 if (old_jcr->store) {
901 new_jcr->store = old_jcr->store;
902 } else if (new_jcr->storage) {
903 new_jcr->store = (STORE *)new_jcr->storage->first();
907 /* Set storage override */
908 void set_storage(JCR *jcr, STORE *store)
913 foreach_alist(storage, jcr->storage) {
914 if (store == storage) {
918 /* Store not in list, so add it */
919 jcr->storage->prepend(store);