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));
60 wd->callback = job_monitor_watchdog;
61 wd->destructor = job_monitor_destructor;
64 wd->data = new_control_jcr("*JobMonitor*", JT_SYSTEM);
65 register_watchdog(wd);
68 void term_job_server()
70 jobq_destroy(&job_queue); /* ignore any errors */
74 * Run a job -- typically called by the scheduler, but may also
75 * be called by the UA (Console program).
77 * Returns: 0 on failure
81 JobId_t run_job(JCR *jcr)
87 sm_check(__FILE__, __LINE__, true);
88 init_msg(jcr, jcr->messages);
90 /* Initialize termination condition variable */
91 if ((errstat = pthread_cond_init(&jcr->term_wait, NULL)) != 0) {
93 Jmsg1(jcr, M_FATAL, 0, _("Unable to init job cond variable: ERR=%s\n"), be.strerror(errstat));
96 jcr->term_wait_inited = true;
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 generate_event(jcr, "StartJob");
236 if (jcr->job->RunBeforeJob) {
237 POOLMEM *before = get_pool_memory(PM_FNAME);
240 char line[MAXSTRING];
242 before = edit_job_codes(jcr, before, jcr->job->RunBeforeJob, "");
243 bpipe = open_bpipe(before, 0, "r");
244 free_pool_memory(before);
245 while (fgets(line, sizeof(line), bpipe->rfd)) {
246 Jmsg(jcr, M_INFO, 0, _("RunBefore: %s"), line);
248 status = close_bpipe(bpipe);
251 Jmsg(jcr, M_FATAL, 0, _("RunBeforeJob error: ERR=%s\n"), be.strerror(status));
252 set_jcr_job_status(jcr, JS_FatalError);
253 update_job_end_record(jcr);
257 switch (jcr->JobType) {
259 if (do_backup(jcr)) {
262 backup_cleanup(jcr, JS_ErrorTerminated);
266 if (do_verify(jcr)) {
269 verify_cleanup(jcr, JS_ErrorTerminated);
273 if (do_restore(jcr)) {
276 restore_cleanup(jcr, JS_ErrorTerminated);
283 admin_cleanup(jcr, JS_ErrorTerminated);
289 if (do_mac(jcr)) { /* migration, archive, copy */
292 mac_cleanup(jcr, JS_ErrorTerminated);
296 Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
299 if ((jcr->job->RunAfterJob && jcr->JobStatus == JS_Terminated) ||
300 (jcr->job->RunAfterFailedJob && jcr->JobStatus != JS_Terminated)) {
301 POOLMEM *after = get_pool_memory(PM_FNAME);
304 char line[MAXSTRING];
306 if (jcr->JobStatus == JS_Terminated) {
307 after = edit_job_codes(jcr, after, jcr->job->RunAfterJob, "");
309 after = edit_job_codes(jcr, after, jcr->job->RunAfterFailedJob, "");
311 bpipe = open_bpipe(after, 0, "r");
312 free_pool_memory(after);
313 while (fgets(line, sizeof(line), bpipe->rfd)) {
314 Jmsg(jcr, M_INFO, 0, _("RunAfter: %s"), line);
316 status = close_bpipe(bpipe);
318 * Note, if we get an error here, do not mark the
319 * job in error, simply report the error condition.
323 if (jcr->JobStatus == JS_Terminated) {
324 Jmsg(jcr, M_WARNING, 0, _("RunAfterJob error: ERR=%s\n"), be.strerror(status));
326 Jmsg(jcr, M_FATAL, 0, _("RunAfterFailedJob error: ERR=%s\n"), be.strerror(status));
330 generate_event(jcr, "EndJob");
331 /* Send off any queued messages */
332 if (jcr->msg_queue->size() > 0) {
333 dequeue_messages(jcr);
340 Dmsg1(50, "======== End Job stat=%c ==========\n", jcr->JobStatus);
341 sm_check(__FILE__, __LINE__, true);
347 * Cancel a job -- typically called by the UA (Console program), but may also
348 * be called by the job watchdog.
350 * Returns: 1 if cancel appears to be successful
351 * 0 on failure. Message sent to ua->jcr.
353 int cancel_job(UAContext *ua, JCR *jcr)
357 switch (jcr->JobStatus) {
360 case JS_WaitClientRes:
361 case JS_WaitStoreRes:
362 case JS_WaitPriority:
364 case JS_WaitStartTime:
365 set_jcr_job_status(jcr, JS_Canceled);
366 bsendmsg(ua, _("JobId %d, Job %s marked to be canceled.\n"),
367 jcr->JobId, jcr->Job);
368 jobq_remove(&job_queue, jcr); /* attempt to remove it from queue */
372 set_jcr_job_status(jcr, JS_Canceled);
374 /* Cancel File daemon */
375 if (jcr->file_bsock) {
376 ua->jcr->client = jcr->client;
377 if (!connect_to_file_daemon(ua->jcr, 10, FDConnectTimeout, 1)) {
378 bsendmsg(ua, _("Failed to connect to File daemon.\n"));
381 Dmsg0(200, "Connected to file daemon\n");
382 fd = ua->jcr->file_bsock;
383 bnet_fsend(fd, "cancel Job=%s\n", jcr->Job);
384 while (bnet_recv(fd) >= 0) {
385 bsendmsg(ua, "%s", fd->msg);
387 bnet_sig(fd, BNET_TERMINATE);
389 ua->jcr->file_bsock = NULL;
392 /* Cancel Storage daemon */
393 if (jcr->store_bsock) {
394 if (!ua->jcr->storage) {
395 copy_storage(ua->jcr, jcr);
397 set_storage(ua->jcr, jcr->store);
399 if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
400 bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
403 Dmsg0(200, "Connected to storage daemon\n");
404 sd = ua->jcr->store_bsock;
405 bnet_fsend(sd, "cancel Job=%s\n", jcr->Job);
406 while (bnet_recv(sd) >= 0) {
407 bsendmsg(ua, "%s", sd->msg);
409 bnet_sig(sd, BNET_TERMINATE);
411 ua->jcr->store_bsock = NULL;
419 static void job_monitor_destructor(watchdog_t *self)
421 JCR *control_jcr = (JCR *) self->data;
423 free_jcr(control_jcr);
426 static void job_monitor_watchdog(watchdog_t *self)
428 JCR *control_jcr, *jcr;
430 control_jcr = (JCR *)self->data;
432 Dmsg1(800, "job_monitor_watchdog %p called\n", self);
439 if (jcr->JobId == 0) {
440 Dmsg2(800, "Skipping JCR %p (%s) with JobId 0\n",
442 /* Keep reference counts correct */
443 free_locked_jcr(jcr);
447 /* check MaxWaitTime */
448 cancel = job_check_maxwaittime(control_jcr, jcr);
450 /* check MaxRunTime */
451 cancel |= job_check_maxruntime(control_jcr, jcr);
454 Dmsg3(800, "Cancelling JCR %p jobid %d (%s)\n",
455 jcr, jcr->JobId, jcr->Job);
457 UAContext *ua = new_ua_context(jcr);
458 ua->jcr = control_jcr;
462 Dmsg1(800, "Have cancelled JCR %p\n", jcr);
465 /* Keep reference counts correct */
466 free_locked_jcr(jcr);
472 * Check if the maxwaittime has expired and it is possible
475 static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr)
478 bool ok_to_cancel = false;
481 if (job->MaxWaitTime == 0 && job->FullMaxWaitTime == 0 &&
482 job->IncMaxWaitTime == 0 && job->DiffMaxWaitTime == 0) {
485 if (jcr->JobLevel == L_FULL && job->FullMaxWaitTime != 0 &&
486 (watchdog_time - jcr->start_time) >= job->FullMaxWaitTime) {
488 } else if (jcr->JobLevel == L_DIFFERENTIAL && job->DiffMaxWaitTime != 0 &&
489 (watchdog_time - jcr->start_time) >= job->DiffMaxWaitTime) {
491 } else if (jcr->JobLevel == L_INCREMENTAL && job->IncMaxWaitTime != 0 &&
492 (watchdog_time - jcr->start_time) >= job->IncMaxWaitTime) {
494 } else if (job->MaxWaitTime != 0 &&
495 (watchdog_time - jcr->start_time) >= job->MaxWaitTime) {
501 Dmsg3(800, "Job %d (%s): MaxWaitTime of %d seconds exceeded, "
503 jcr->JobId, jcr->Job, job->MaxWaitTime);
504 switch (jcr->JobStatus) {
509 case JS_WaitStoreRes:
510 case JS_WaitClientRes:
512 case JS_WaitPriority:
514 case JS_WaitStartTime:
516 Dmsg0(200, "JCR blocked in #1\n");
519 Dmsg0(800, "JCR running, checking SD status\n");
520 switch (jcr->SDJobStatus) {
525 Dmsg0(800, "JCR blocked in #2\n");
528 Dmsg0(800, "JCR not blocked in #2\n");
533 case JS_ErrorTerminated:
536 Dmsg0(800, "JCR already dead in #3\n");
539 Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
542 Dmsg3(800, "MaxWaitTime result: %scancel JCR %p (%s)\n",
543 cancel ? "" : "do not ", jcr, jcr->job);
549 * Check if maxruntime has expired and if the job can be
552 static bool job_check_maxruntime(JCR *control_jcr, JCR *jcr)
556 if (jcr->job->MaxRunTime == 0) {
559 if ((watchdog_time - jcr->start_time) < jcr->job->MaxRunTime) {
560 Dmsg3(200, "Job %p (%s) with MaxRunTime %d not expired\n",
561 jcr, jcr->Job, jcr->job->MaxRunTime);
565 switch (jcr->JobStatus) {
571 case JS_WaitStoreRes:
572 case JS_WaitClientRes:
574 case JS_WaitPriority:
576 case JS_WaitStartTime:
581 case JS_ErrorTerminated:
587 Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
591 Dmsg3(200, "MaxRunTime result: %scancel JCR %p (%s)\n",
592 cancel ? "" : "do not ", jcr, jcr->job);
599 * Get or create a Client record for this Job
601 bool get_or_create_client_record(JCR *jcr)
605 memset(&cr, 0, sizeof(cr));
606 bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name));
607 cr.AutoPrune = jcr->client->AutoPrune;
608 cr.FileRetention = jcr->client->FileRetention;
609 cr.JobRetention = jcr->client->JobRetention;
610 if (!jcr->client_name) {
611 jcr->client_name = get_pool_memory(PM_NAME);
613 pm_strcpy(jcr->client_name, jcr->client->hdr.name);
614 if (!db_create_client_record(jcr, jcr->db, &cr)) {
615 Jmsg(jcr, M_FATAL, 0, _("Could not create Client record. ERR=%s\n"),
616 db_strerror(jcr->db));
619 jcr->jr.ClientId = cr.ClientId;
621 if (!jcr->client_uname) {
622 jcr->client_uname = get_pool_memory(PM_NAME);
624 pm_strcpy(jcr->client_uname, cr.Uname);
626 Dmsg2(100, "Created Client %s record %d\n", jcr->client->hdr.name,
631 bool get_or_create_fileset_record(JCR *jcr, FILESET_DBR *fsr)
634 * Get or Create FileSet record
636 memset(fsr, 0, sizeof(FILESET_DBR));
637 bstrncpy(fsr->FileSet, jcr->fileset->hdr.name, sizeof(fsr->FileSet));
638 if (jcr->fileset->have_MD5) {
639 struct MD5Context md5c;
640 unsigned char signature[16];
641 memcpy(&md5c, &jcr->fileset->md5c, sizeof(md5c));
642 MD5Final(signature, &md5c);
643 bin_to_base64(fsr->MD5, (char *)signature, 16); /* encode 16 bytes */
644 bstrncpy(jcr->fileset->MD5, fsr->MD5, sizeof(jcr->fileset->MD5));
646 Jmsg(jcr, M_WARNING, 0, _("FileSet MD5 signature not found.\n"));
648 if (!jcr->fileset->ignore_fs_changes ||
649 !db_get_fileset_record(jcr, jcr->db, fsr)) {
650 if (!db_create_fileset_record(jcr, jcr->db, fsr)) {
651 Jmsg(jcr, M_ERROR, 0, _("Could not create FileSet \"%s\" record. ERR=%s\n"),
652 fsr->FileSet, db_strerror(jcr->db));
656 jcr->jr.FileSetId = fsr->FileSetId;
658 Jmsg(jcr, M_INFO, 0, _("Created new FileSet record \"%s\" %s\n"),
659 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++) {
744 * Free the Job Control Record if no one is still using it.
745 * Called from main free_jcr() routine in src/lib/jcr.c so
746 * that we can do our Director specific cleanup of the jcr.
748 void dird_free_jcr(JCR *jcr)
750 Dmsg0(200, "Start dird free_jcr\n");
752 if (jcr->sd_auth_key) {
753 free(jcr->sd_auth_key);
754 jcr->sd_auth_key = NULL;
760 if (jcr->file_bsock) {
761 Dmsg0(200, "Close File bsock\n");
762 bnet_close(jcr->file_bsock);
763 jcr->file_bsock = NULL;
765 if (jcr->store_bsock) {
766 Dmsg0(200, "Close Store bsock\n");
767 bnet_close(jcr->store_bsock);
768 jcr->store_bsock = NULL;
771 Dmsg0(200, "Free JCR fname\n");
772 free_pool_memory(jcr->fname);
776 Dmsg0(200, "Free JCR stime\n");
777 free_pool_memory(jcr->stime);
780 if (jcr->RestoreBootstrap) {
781 free(jcr->RestoreBootstrap);
782 jcr->RestoreBootstrap = NULL;
784 if (jcr->client_uname) {
785 free_pool_memory(jcr->client_uname);
786 jcr->client_uname = NULL;
788 if (jcr->term_wait_inited) {
789 pthread_cond_destroy(&jcr->term_wait);
791 /* Delete lists setup to hold storage pointers */
795 jcr->job_end_push.destroy();
796 Dmsg0(200, "End dird free_jcr\n");
800 * Set some defaults in the JCR necessary to
801 * run. These items are pulled from the job
802 * definition as defaults, but can be overridden
803 * later either by the Run record in the Schedule resource,
804 * or by the Console program.
806 void set_jcr_defaults(JCR *jcr, JOB *job)
810 jcr->JobType = job->JobType;
811 switch (jcr->JobType) {
814 jcr->JobLevel = L_NONE;
817 jcr->JobLevel = job->JobLevel;
820 jcr->JobPriority = job->Priority;
821 /* Copy storage definitions -- deleted in dir_free_jcr above */
826 jcr->storage = New(alist(10, not_owned_by_alist));
827 foreach_alist(st, job->storage) {
828 jcr->storage->append(st);
832 jcr->store = (STORE *)jcr->storage->first();
834 jcr->client = job->client;
835 if (!jcr->client_name) {
836 jcr->client_name = get_pool_memory(PM_NAME);
838 pm_strcpy(jcr->client_name, jcr->client->hdr.name);
839 jcr->pool = job->pool;
840 jcr->full_pool = job->full_pool;
841 jcr->inc_pool = job->inc_pool;
842 jcr->dif_pool = job->dif_pool;
843 jcr->catalog = job->client->catalog;
844 jcr->fileset = job->fileset;
845 jcr->messages = job->messages;
846 jcr->spool_data = job->spool_data;
847 jcr->write_part_after_job = job->write_part_after_job;
848 if (jcr->RestoreBootstrap) {
849 free(jcr->RestoreBootstrap);
850 jcr->RestoreBootstrap = NULL;
852 /* This can be overridden by Console program */
853 if (job->RestoreBootstrap) {
854 jcr->RestoreBootstrap = bstrdup(job->RestoreBootstrap);
856 /* This can be overridden by Console program */
857 jcr->verify_job = job->verify_job;
858 /* If no default level given, set one */
859 if (jcr->JobLevel == 0) {
860 switch (jcr->JobType) {
862 jcr->JobLevel = L_VERIFY_CATALOG;
865 jcr->JobLevel = L_INCREMENTAL;
869 jcr->JobLevel = L_NONE;
878 * copy the storage definitions from an old JCR to a new one
880 void copy_storage(JCR *new_jcr, JCR *old_jcr)
882 if (old_jcr->storage) {
884 if (old_jcr->storage) {
885 delete old_jcr->storage;
887 new_jcr->storage = New(alist(10, not_owned_by_alist));
888 foreach_alist(st, old_jcr->storage) {
889 new_jcr->storage->append(st);
892 if (old_jcr->store) {
893 new_jcr->store = old_jcr->store;
894 } else if (new_jcr->storage) {
895 new_jcr->store = (STORE *)new_jcr->storage->first();
899 /* Set storage override */
900 void set_storage(JCR *jcr, STORE *store)
905 foreach_alist(storage, jcr->storage) {
906 if (store == storage) {
910 /* Store not in list, so add it */
911 jcr->storage->prepend(store);