2 * Bacula File Daemon Job processing
4 * Kern Sibbald, October MM
10 Copyright (C) 2000-2004 Kern Sibbald and John Walker
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 extern char my_name[];
33 extern CLIENT *me; /* our client resource */
35 /* Imported functions */
36 extern int status_cmd(JCR *jcr);
37 extern int qstatus_cmd(JCR *jcr);
39 /* Forward referenced functions */
40 static int backup_cmd(JCR *jcr);
41 static int bootstrap_cmd(JCR *jcr);
42 static int cancel_cmd(JCR *jcr);
43 static int setdebug_cmd(JCR *jcr);
44 static int estimate_cmd(JCR *jcr);
45 static int exclude_cmd(JCR *jcr);
46 static int hello_cmd(JCR *jcr);
47 static int job_cmd(JCR *jcr);
48 static int include_cmd(JCR *jcr);
49 static int fileset_cmd(JCR *jcr);
50 static int level_cmd(JCR *jcr);
51 static int verify_cmd(JCR *jcr);
52 static int restore_cmd(JCR *jcr);
53 static int storage_cmd(JCR *jcr);
54 static int session_cmd(JCR *jcr);
55 static int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd);
56 static void filed_free_jcr(JCR *jcr);
57 static int open_sd_read_session(JCR *jcr);
58 static int send_bootstrap_file(JCR *jcr);
59 static int runbefore_cmd(JCR *jcr);
60 static int runafter_cmd(JCR *jcr);
61 static int run_cmd(JCR *jcr, char *cmd, const char *name);
62 static void set_options(findFOPTS *fo, const char *opts);
65 /* Exported functions */
70 int monitoraccess; /* specify if monitors have access to this function */
74 * The following are the recognized commands from the Director.
76 static struct s_cmds cmds[] = {
77 {"backup", backup_cmd, 0},
78 {"cancel", cancel_cmd, 0},
79 {"setdebug=", setdebug_cmd, 0},
80 {"estimate", estimate_cmd, 0},
81 {"exclude", exclude_cmd, 0},
82 {"Hello", hello_cmd, 1},
83 {"include", include_cmd, 0},
84 {"fileset", fileset_cmd, 0},
85 {"JobId=", job_cmd, 0},
86 {"level = ", level_cmd, 0},
87 {"restore", restore_cmd, 0},
88 {"session", session_cmd, 0},
89 {"status", status_cmd, 1},
90 {".status", qstatus_cmd, 1},
91 {"storage ", storage_cmd, 0},
92 {"verify", verify_cmd, 0},
93 {"bootstrap", bootstrap_cmd, 0},
94 {"RunBeforeJob", runbefore_cmd, 0},
95 {"RunAfterJob", runafter_cmd, 0},
96 {NULL, NULL} /* list terminator */
99 /* Commands received from director that need scanning */
100 static char jobcmd[] = "JobId=%d Job=%127s SDid=%d SDtime=%d Authorization=%100s";
101 static char storaddr[] = "storage address=%s port=%d ssl=%d\n";
102 static char sessioncmd[] = "session %127s %ld %ld %ld %ld %ld %ld\n";
103 static char restorecmd[] = "restore replace=%c prelinks=%d where=%s\n";
104 static char restorecmd1[] = "restore replace=%c prelinks=%d where=\n";
105 static char verifycmd[] = "verify level=%30s\n";
106 static char estimatecmd[] = "estimate listing=%d\n";
107 static char runbefore[] = "RunBeforeJob %s\n";
108 static char runafter[] = "RunAfterJob %s\n";
110 /* Responses sent to Director */
111 static char errmsg[] = "2999 Invalid command\n";
112 static char no_auth[] = "2998 No Authorization\n";
113 static char illegal_cmd[] = "2997 Illegal command for a Director with Monitor directive enabled\n";
114 static char OKinc[] = "2000 OK include\n";
115 static char OKest[] = "2000 OK estimate files=%u bytes=%s\n";
116 static char OKexc[] = "2000 OK exclude\n";
117 static char OKlevel[] = "2000 OK level\n";
118 static char OKbackup[] = "2000 OK backup\n";
119 static char OKbootstrap[] = "2000 OK bootstrap\n";
120 static char OKverify[] = "2000 OK verify\n";
121 static char OKrestore[] = "2000 OK restore\n";
122 static char OKsession[] = "2000 OK session\n";
123 static char OKstore[] = "2000 OK storage\n";
124 static char OKjob[] = "2000 OK Job %s,%s,%s";
125 static char OKsetdebug[] = "2000 OK setdebug=%d\n";
126 static char BADjob[] = "2901 Bad Job\n";
127 static char EndJob[] = "2800 End Job TermCode=%d JobFiles=%u ReadBytes=%s JobBytes=%s Errors=%u\n";
128 static char OKRunBefore[] = "2000 OK RunBefore\n";
129 static char OKRunAfter[] = "2000 OK RunAfter\n";
131 /* Responses received from Storage Daemon */
132 static char OK_end[] = "3000 OK end\n";
133 static char OK_close[] = "3000 OK close Status = %d\n";
134 static char OK_open[] = "3000 OK open ticket = %d\n";
135 static char OK_data[] = "3000 OK data\n";
136 static char OK_append[] = "3000 OK append data\n";
137 static char OKSDbootstrap[] = "3000 OK bootstrap\n";
140 /* Commands sent to Storage Daemon */
141 static char append_open[] = "append open session\n";
142 static char append_data[] = "append data %d\n";
143 static char append_end[] = "append end session %d\n";
144 static char append_close[] = "append close session %d\n";
145 static char read_open[] = "read open session = %s %ld %ld %ld %ld %ld %ld\n";
146 static char read_data[] = "read data %d\n";
147 static char read_close[] = "read close session %d\n";
150 * Accept requests from a Director
152 * NOTE! We are running as a separate thread
154 * Send output one line
155 * at a time followed by a zero length transmission.
157 * Return when the connection is terminated or there
160 * Basic task here is:
161 * Authenticate Director (during Hello command).
162 * Accept commands one at a time from the Director
166 void *handle_client_request(void *dirp)
171 BSOCK *dir = (BSOCK *)dirp;
173 jcr = new_jcr(sizeof(JCR), filed_free_jcr); /* create JCR */
174 jcr->dir_bsock = dir;
175 jcr->ff = init_find_files();
176 jcr->start_time = time(NULL);
177 jcr->last_fname = get_pool_memory(PM_FNAME);
178 jcr->last_fname[0] = 0;
179 jcr->client_name = get_memory(strlen(my_name) + 1);
180 pm_strcpy(jcr->client_name, my_name);
182 enable_backup_privileges(NULL, 1 /* ignore_errors */);
184 /**********FIXME******* add command handler error code */
186 for (quit=false; !quit;) {
189 if (bnet_recv(dir) < 0) {
190 break; /* connection terminated */
192 dir->msg[dir->msglen] = 0;
193 Dmsg1(100, "<dird: %s", dir->msg);
195 for (i=0; cmds[i].cmd; i++) {
196 if (strncmp(cmds[i].cmd, dir->msg, strlen(cmds[i].cmd)) == 0) {
197 found = true; /* indicate command found */
198 if (!jcr->authenticated && cmds[i].func != hello_cmd) {
199 bnet_fsend(dir, no_auth);
200 bnet_sig(dir, BNET_EOD);
203 if ((jcr->authenticated) && (!cmds[i].monitoraccess) && (jcr->director->monitor)) {
204 Dmsg1(100, "Command %s illegal.\n", cmds[i].cmd);
205 bnet_fsend(dir, illegal_cmd);
206 bnet_sig(dir, BNET_EOD);
209 Dmsg1(100, "Executing %s command.\n", cmds[i].cmd);
210 if (!cmds[i].func(jcr)) { /* do command */
211 quit = true; /* error or fully terminated, get out */
212 Dmsg0(20, "Quit command loop due to command error or Job done.\n");
217 if (!found) { /* command not found */
218 bnet_fsend(dir, errmsg);
224 /* Inform Storage daemon that we are done */
225 if (jcr->store_bsock) {
226 bnet_sig(jcr->store_bsock, BNET_TERMINATE);
229 if (jcr->RunAfterJob && !job_canceled(jcr)) {
230 run_cmd(jcr, jcr->RunAfterJob, "ClientRunAfterJob");
232 dequeue_messages(jcr); /* send any queued messages */
234 /* Inform Director that we are done */
235 bnet_sig(dir, BNET_TERMINATE);
237 /* Clean up fileset */
238 FF_PKT *ff = (FF_PKT *)jcr->ff;
239 findFILESET *fileset = ff->fileset;
242 /* Delete FileSet Include lists */
243 for (i=0; i<fileset->include_list.size(); i++) {
244 findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
245 for (j=0; j<incexe->opts_list.size(); j++) {
246 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
247 for (k=0; k<fo->regex.size(); k++) {
248 regfree((regex_t *)fo->regex.get(k));
260 incexe->opts_list.destroy();
261 incexe->name_list.destroy();
263 fileset->include_list.destroy();
265 /* Delete FileSet Exclude lists */
266 for (i=0; i<fileset->exclude_list.size(); i++) {
267 findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
268 for (j=0; j<incexe->opts_list.size(); j++) {
269 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
274 incexe->opts_list.destroy();
275 incexe->name_list.destroy();
277 fileset->exclude_list.destroy();
280 Dmsg0(100, "Calling term_find_files\n");
281 term_find_files((FF_PKT *)jcr->ff);
282 Dmsg0(100, "Done with term_find_files\n");
283 free_jcr(jcr); /* destroy JCR record */
284 Dmsg0(100, "Done with free_jcr\n");
289 * Hello from Director he must identify himself and provide his
292 static int hello_cmd(JCR *jcr)
294 Dmsg0(120, "Calling Authenticate\n");
295 if (!authenticate_director(jcr)) {
298 Dmsg0(120, "OK Authenticate\n");
299 jcr->authenticated = true;
306 static int cancel_cmd(JCR *jcr)
308 BSOCK *dir = jcr->dir_bsock;
309 char Job[MAX_NAME_LENGTH];
312 if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
313 if (!(cjcr=get_jcr_by_full_name(Job))) {
314 bnet_fsend(dir, "2901 Job %s not found.\n", Job);
316 if (cjcr->store_bsock) {
318 cjcr->store_bsock->timed_out = 1;
319 cjcr->store_bsock->terminated = 1;
321 * #if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
323 #if !defined(HAVE_CYGWIN)
324 pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL);
328 set_jcr_job_status(cjcr, JS_Canceled);
330 bnet_fsend(dir, _("2001 Job %s marked to be canceled.\n"), Job);
333 bnet_fsend(dir, _("2902 Error scanning cancel command.\n"));
335 bnet_sig(dir, BNET_EOD);
341 * Set debug level as requested by the Director
344 static int setdebug_cmd(JCR *jcr)
346 BSOCK *dir = jcr->dir_bsock;
347 int level, trace_flag;
349 Dmsg1(110, "setdebug_cmd: %s", dir->msg);
350 if (sscanf(dir->msg, "setdebug=%d trace=%d", &level, &trace_flag) != 2 || level < 0) {
351 pm_strcpy(jcr->errmsg, dir->msg);
352 bnet_fsend(dir, "2991 Bad setdebug command: %s\n", jcr->errmsg);
356 set_trace(trace_flag);
357 return bnet_fsend(dir, OKsetdebug, level);
361 static int estimate_cmd(JCR *jcr)
363 BSOCK *dir = jcr->dir_bsock;
366 if (sscanf(dir->msg, estimatecmd, &jcr->listing) != 1) {
367 pm_strcpy(jcr->errmsg, dir->msg);
368 Jmsg(jcr, M_FATAL, 0, _("Bad estimate command: %s"), jcr->errmsg);
369 bnet_fsend(dir, "2992 Bad estimate command.\n");
373 bnet_fsend(dir, OKest, jcr->num_files_examined,
374 edit_uint64_with_commas(jcr->JobBytes, ed2));
375 bnet_sig(dir, BNET_EOD);
380 * Get JobId and Storage Daemon Authorization key from Director
382 static int job_cmd(JCR *jcr)
384 BSOCK *dir = jcr->dir_bsock;
385 POOLMEM *sd_auth_key;
387 sd_auth_key = get_memory(dir->msglen);
388 if (sscanf(dir->msg, jobcmd, &jcr->JobId, jcr->Job,
389 &jcr->VolSessionId, &jcr->VolSessionTime,
391 pm_strcpy(jcr->errmsg, dir->msg);
392 Jmsg(jcr, M_FATAL, 0, _("Bad Job Command: %s"), jcr->errmsg);
393 bnet_fsend(dir, BADjob);
394 free_pool_memory(sd_auth_key);
397 jcr->sd_auth_key = bstrdup(sd_auth_key);
398 free_pool_memory(sd_auth_key);
399 Dmsg2(120, "JobId=%d Auth=%s\n", jcr->JobId, jcr->sd_auth_key);
400 return bnet_fsend(dir, OKjob, HOST_OS, DISTNAME, DISTVER);
403 static int runbefore_cmd(JCR *jcr)
406 BSOCK *dir = jcr->dir_bsock;
407 POOLMEM *cmd = get_memory(dir->msglen+1);
409 Dmsg1(100, "runbefore_cmd: %s", dir->msg);
410 if (sscanf(dir->msg, runbefore, cmd) != 1) {
411 pm_strcpy(jcr->errmsg, dir->msg);
412 Jmsg1(jcr, M_FATAL, 0, _("Bad RunBeforeJob command: %s\n"), jcr->errmsg);
413 bnet_fsend(dir, "2905 Bad RunBeforeJob command.\n");
419 /* Run the command now */
420 stat = run_cmd(jcr, cmd, "ClientRunBeforeJob");
423 bnet_fsend(dir, OKRunBefore);
426 bnet_fsend(dir, "2905 Bad RunBeforeJob command.\n");
431 static int runafter_cmd(JCR *jcr)
433 BSOCK *dir = jcr->dir_bsock;
434 POOLMEM *msg = get_memory(dir->msglen+1);
436 Dmsg1(100, "runafter_cmd: %s", dir->msg);
437 if (sscanf(dir->msg, runafter, msg) != 1) {
438 pm_strcpy(jcr->errmsg, dir->msg);
439 Jmsg1(jcr, M_FATAL, 0, _("Bad RunAfter command: %s\n"), jcr->errmsg);
440 bnet_fsend(dir, "2905 Bad RunAfterJob command.\n");
445 if (jcr->RunAfterJob) {
446 free_pool_memory(jcr->RunAfterJob);
448 jcr->RunAfterJob = get_pool_memory(PM_FNAME);
449 pm_strcpy(jcr->RunAfterJob, msg);
450 free_pool_memory(msg);
451 return bnet_fsend(dir, OKRunAfter);
454 static int run_cmd(JCR *jcr, char *cmd, const char *name)
456 POOLMEM *ecmd = get_pool_memory(PM_FNAME);
459 char line[MAXSTRING];
461 ecmd = edit_job_codes(jcr, ecmd, cmd, "");
462 bpipe = open_bpipe(ecmd, 0, "r");
463 free_pool_memory(ecmd);
465 Jmsg(jcr, M_FATAL, 0, _("%s could not execute\n"), name);
466 set_jcr_job_status(jcr, JS_FatalError);
469 while (fgets(line, sizeof(line), bpipe->rfd)) {
470 Jmsg(jcr, M_INFO, 0, _("%s: %s"), name, line);
472 status = close_bpipe(bpipe);
474 Jmsg(jcr, M_FATAL, 0, _("%s returned non-zero status=%d\n"), name,
476 set_jcr_job_status(jcr, JS_FatalError);
486 static void add_fname_to_list(JCR *jcr, char *fname, int list)
496 /* Skip leading options -- currently ignored */
497 for (p=fname; *p && *p != ' '; p++)
499 /* Skip spaces, and q points to first space */
500 for (q=NULL; *p && *p == ' '; p++) {
508 p++; /* skip over | */
509 fn = get_pool_memory(PM_FNAME);
510 fn = edit_job_codes(jcr, fn, p, "");
511 bpipe = open_bpipe(fn, 0, "r");
512 free_pool_memory(fn);
514 Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
518 /* Copy File options */
519 if (list == INC_LIST) {
520 *q = 0; /* terminate options */
523 optlen = strlen(buf);
527 while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) {
528 strip_trailing_junk(buf);
529 if (list == INC_LIST) {
530 add_fname_to_include_list((FF_PKT *)jcr->ff, 1, buf);
532 add_fname_to_exclude_list((FF_PKT *)jcr->ff, buf);
535 if ((stat=close_bpipe(bpipe)) != 0) {
536 Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
537 p, stat, strerror(errno));
542 p++; /* skip over < */
543 if ((ffd = fopen(p, "r")) == NULL) {
545 Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
546 list==INC_LIST?"included":"excluded", p, be.strerror());
549 /* Copy File options */
550 if (list == INC_LIST) {
551 *q = 0; /* terminate options */
554 optlen = strlen(buf);
558 while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) {
559 strip_trailing_junk(buf);
560 if (list == INC_LIST) {
561 add_fname_to_include_list((FF_PKT *)jcr->ff, 1, buf);
563 add_fname_to_exclude_list((FF_PKT *)jcr->ff, buf);
569 if (list == INC_LIST) {
570 add_fname_to_include_list((FF_PKT *)jcr->ff, 1, fname);
572 add_fname_to_exclude_list((FF_PKT *)jcr->ff, p);
580 * Get list of files/directories to include from Director
583 static int include_cmd(JCR *jcr)
585 BSOCK *dir = jcr->dir_bsock;
587 while (bnet_recv(dir) >= 0) {
588 dir->msg[dir->msglen] = 0;
589 strip_trailing_junk(dir->msg);
590 Dmsg1(010, "include file: %s\n", dir->msg);
591 add_fname_to_list(jcr, dir->msg, INC_LIST);
594 return bnet_fsend(dir, OKinc);
597 static bool init_fileset(JCR *jcr)
600 findFILESET *fileset;
605 ff = (FF_PKT *)jcr->ff;
609 fileset = (findFILESET *)malloc(sizeof(findFILESET));
610 memset(fileset, 0, sizeof(findFILESET));
611 ff->fileset = fileset;
612 fileset->state = state_none;
613 fileset->include_list.init(1, true);
614 fileset->exclude_list.init(1, true);
618 static findFOPTS *start_options(FF_PKT *ff)
620 int state = ff->fileset->state;
621 findINCEXE *incexe = ff->fileset->incexe;
623 if (state != state_options) {
624 ff->fileset->state = state_options;
625 findFOPTS *fo = (findFOPTS *)malloc(sizeof(findFOPTS));
626 memset(fo, 0, sizeof(findFOPTS));
627 fo->regex.init(1, true);
628 fo->wild.init(1, true);
629 fo->base.init(1, true);
630 incexe->current_opts = fo;
631 incexe->opts_list.append(fo);
633 return incexe->current_opts;
638 * Add fname to include/exclude fileset list. First check for
639 * | and < and if necessary perform command.
641 static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *fileset)
653 p++; /* skip over | */
654 fn = get_pool_memory(PM_FNAME);
655 fn = edit_job_codes(jcr, fn, p, "");
656 bpipe = open_bpipe(fn, 0, "r");
657 free_pool_memory(fn);
659 Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
663 while (fgets(buf, sizeof(buf), bpipe->rfd)) {
664 strip_trailing_junk(buf);
665 fileset->incexe->name_list.append(bstrdup(buf));
667 if ((stat=close_bpipe(bpipe)) != 0) {
668 Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
669 p, stat, strerror(errno));
674 p++; /* skip over < */
675 if ((ffd = fopen(p, "r")) == NULL) {
677 Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"),
681 while (fgets(buf, sizeof(buf), ffd)) {
682 strip_trailing_junk(buf);
683 fileset->incexe->name_list.append(bstrdup(buf));
688 fileset->incexe->name_list.append(bstrdup(fname));
694 static void add_fileset(JCR *jcr, const char *item)
696 FF_PKT *ff = (FF_PKT *)jcr->ff;
697 findFILESET *fileset = ff->fileset;
698 int state = fileset->state;
699 findFOPTS *current_opts;
701 Dmsg1(100, "%s\n", item);
703 if (item[1] == ' ') { /* If string follows */
704 item += 2; /* point to string */
707 if (state == state_error) {
713 fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
714 memset(fileset->incexe, 0, sizeof(findINCEXE));
715 fileset->incexe->opts_list.init(1, true);
716 fileset->incexe->name_list.init(1, true);
717 fileset->include_list.append(fileset->incexe);
721 fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
722 memset(fileset->incexe, 0, sizeof(findINCEXE));
723 fileset->incexe->opts_list.init(1, true);
724 fileset->incexe->name_list.init(1, true);
725 fileset->exclude_list.append(fileset->incexe);
731 /* File item to either include/include list */
732 state = state_include;
733 add_file_to_fileset(jcr, item, fileset);
736 current_opts = start_options(ff);
740 preg = (regex_t *)malloc(sizeof(regex_t));
741 rc = regcomp(preg, item, REG_EXTENDED);
743 regerror(rc, preg, prbuf, sizeof(prbuf));
746 Jmsg(jcr, M_FATAL, 0, "REGEX %s compile error. ERR=%s\n", item, prbuf);
750 current_opts->regex.append(preg);
751 state = state_options;
754 current_opts = start_options(ff);
755 current_opts->base.append(bstrdup(item));
756 state = state_options;
759 current_opts = start_options(ff);
760 current_opts->wild.append(bstrdup(item));
761 state = state_options;
764 current_opts = start_options(ff);
765 set_options(current_opts, item);
766 state = state_options;
769 current_opts = start_options(ff);
770 current_opts->reader = bstrdup(item);
771 state = state_options;
774 current_opts = start_options(ff);
775 current_opts->writer = bstrdup(item);
776 state = state_options;
779 Jmsg(jcr, M_FATAL, 0, "Invalid FileSet command: %s\n", item);
783 ff->fileset->state = state;
786 static bool term_fileset(JCR *jcr)
788 FF_PKT *ff = (FF_PKT *)jcr->ff;
789 findFILESET *fileset = ff->fileset;
792 for (i=0; i<fileset->include_list.size(); i++) {
793 findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
795 for (j=0; j<incexe->opts_list.size(); j++) {
796 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
797 for (k=0; k<fo->regex.size(); k++) {
798 Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
800 for (k=0; k<fo->wild.size(); k++) {
801 Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
803 for (k=0; k<fo->base.size(); k++) {
804 Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
807 Dmsg1(400, "D %s\n", fo->reader);
810 Dmsg1(400, "T %s\n", fo->writer);
813 for (j=0; j<incexe->name_list.size(); j++) {
814 Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
817 for (i=0; i<fileset->exclude_list.size(); i++) {
818 findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
820 for (j=0; j<incexe->opts_list.size(); j++) {
821 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
822 for (k=0; k<fo->regex.size(); k++) {
823 Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
825 for (k=0; k<fo->wild.size(); k++) {
826 Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
828 for (k=0; k<fo->base.size(); k++) {
829 Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
832 for (j=0; j<incexe->name_list.size(); j++) {
833 Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
836 return ff->fileset->state != state_error;
841 * As an optimization, we should do this during
842 * "compile" time in filed/job.c, and keep only a bit mask
843 * and the Verify options.
845 static void set_options(findFOPTS *fo, const char *opts)
850 for (p=opts; *p; p++) {
852 case 'a': /* alway replace */
853 case '0': /* no option */
856 fo->flags |= FO_EXCLUDE;
859 fo->flags |= FO_MULTIFS;
861 case 'h': /* no recursion */
862 fo->flags |= FO_NO_RECURSION;
868 fo->flags |= FO_NOREPLACE;
870 case 'p': /* use portable data format */
871 fo->flags |= FO_PORTABLE;
873 case 'r': /* read fifo */
874 fo->flags |= FO_READFIFO;
877 fo->flags |= FO_SHA1;
880 fo->flags |= FO_SPARSE;
883 fo->flags |= FO_MTIMEONLY;
886 fo->flags |= FO_KEEPATIME;
891 case 'V': /* verify options */
892 /* Copy Verify Options */
893 for (j=0; *p && *p != ':'; p++) {
894 fo->VerifyOpts[j] = *p;
895 if (j < (int)sizeof(fo->VerifyOpts) - 1) {
899 fo->VerifyOpts[j] = 0;
902 fo->flags |= FO_IF_NEWER;
904 case 'Z': /* gzip compression */
905 fo->flags |= FO_GZIP;
906 fo->GZIP_level = *++p - '0';
907 Dmsg1(200, "Compression level=%d\n", fo->GZIP_level);
910 Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *p);
918 * Director is passing his Fileset
920 static int fileset_cmd(JCR *jcr)
922 BSOCK *dir = jcr->dir_bsock;
924 if (!init_fileset(jcr)) {
927 while (bnet_recv(dir) >= 0) {
928 strip_trailing_junk(dir->msg);
929 Dmsg1(400, "Fileset: %s\n", dir->msg);
930 add_fileset(jcr, dir->msg);
932 if (!term_fileset(jcr)) {
935 return bnet_fsend(dir, OKinc);
940 * Get list of files to exclude from Director
943 static int exclude_cmd(JCR *jcr)
945 BSOCK *dir = jcr->dir_bsock;
947 while (bnet_recv(dir) >= 0) {
948 dir->msg[dir->msglen] = 0;
949 strip_trailing_junk(dir->msg);
950 add_fname_to_list(jcr, dir->msg, EXC_LIST);
951 Dmsg1(110, "<dird: exclude file %s\n", dir->msg);
954 return bnet_fsend(dir, OKexc);
958 static int bootstrap_cmd(JCR *jcr)
960 BSOCK *dir = jcr->dir_bsock;
961 POOLMEM *fname = get_pool_memory(PM_FNAME);
964 if (jcr->RestoreBootstrap) {
965 unlink(jcr->RestoreBootstrap);
966 free_pool_memory(jcr->RestoreBootstrap);
968 Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
970 Dmsg1(400, "bootstrap=%s\n", fname);
971 jcr->RestoreBootstrap = fname;
972 bs = fopen(fname, "a+"); /* create file */
976 * Suck up what he is sending to us so that he will then
977 * read our error message.
979 while (bnet_recv(dir) >= 0)
982 Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"),
983 jcr->RestoreBootstrap, be.strerror());
984 free_pool_memory(jcr->RestoreBootstrap);
985 jcr->RestoreBootstrap = NULL;
986 set_jcr_job_status(jcr, JS_ErrorTerminated);
990 while (bnet_recv(dir) >= 0) {
991 Dmsg1(200, "filed<dird: bootstrap file %s\n", dir->msg);
996 return bnet_fsend(dir, OKbootstrap);
1001 * Get backup level from Director
1004 static int level_cmd(JCR *jcr)
1006 BSOCK *dir = jcr->dir_bsock;
1007 POOLMEM *level, *buf = NULL;
1012 level = get_memory(dir->msglen+1);
1013 Dmsg1(110, "level_cmd: %s", dir->msg);
1014 if (sscanf(dir->msg, "level = %s ", level) != 1) {
1017 /* Base backup requested? */
1018 if (strcmp(level, "base") == 0) {
1019 jcr->JobLevel = L_BASE;
1020 /* Full backup requested? */
1021 } else if (strcmp(level, "full") == 0) {
1022 jcr->JobLevel = L_FULL;
1024 * Backup requested since <date> <time>
1025 * This form is also used for incremental and differential
1026 * This code is deprecated. See since_utime for new code.
1028 } else if (strcmp(level, "since") == 0) {
1029 jcr->JobLevel = L_SINCE;
1030 if (sscanf(dir->msg, "level = since %d-%d-%d %d:%d:%d mtime_only=%d",
1031 &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
1032 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &mtime_only) != 7) {
1037 tm.tm_wday = tm.tm_yday = 0;
1039 mtime = mktime(&tm);
1040 Dmsg2(100, "Got since time: %s mtime_only=%d\n", ctime(&mtime), mtime_only);
1041 jcr->incremental = 1; /* set incremental or decremental backup */
1042 jcr->mtime = mtime; /* set since time */
1044 * We get his UTC since time, then sync the clocks and correct it
1045 * to agree with our clock.
1047 } else if (strcmp(level, "since_utime") == 0) {
1048 buf = get_memory(dir->msglen+1);
1049 utime_t since_time, adj;
1050 btime_t his_time, bt_start, rt=0, bt_adj=0;
1051 jcr->JobLevel = L_SINCE;
1052 if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
1053 buf, &mtime_only) != 2) {
1056 since_time = str_to_uint64(buf); /* this is the since time */
1057 char ed1[50], ed2[50];
1059 * Sync clocks by polling him for the time. We take
1060 * 10 samples of his time throwing out the first two.
1062 for (int i=0; i<10; i++) {
1063 bt_start = get_current_btime();
1064 bnet_sig(dir, BNET_BTIME); /* poll for time */
1065 if (bnet_recv(dir) <= 0) { /* get response */
1068 if (sscanf(dir->msg, "btime %s", buf) != 1) {
1071 if (i < 2) { /* toss first two results */
1074 his_time = str_to_uint64(buf);
1075 rt = get_current_btime() - bt_start; /* compute round trip time */
1076 bt_adj -= his_time - bt_start - rt/2;
1077 Dmsg2(200, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
1080 bt_adj = bt_adj / 8; /* compute average time */
1081 Dmsg2(100, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
1082 adj = btime_to_utime(bt_adj);
1083 since_time += adj; /* adjust for clock difference */
1085 Jmsg(jcr, M_INFO, 0, _("Since time adjusted by %d seconds.\n"), adj);
1087 bnet_sig(dir, BNET_EOD);
1089 Dmsg2(100, "adj = %d since_time=%d\n", (int)adj, (int)since_time);
1090 jcr->incremental = 1; /* set incremental or decremental backup */
1091 jcr->mtime = (time_t)since_time; /* set since time */
1093 Jmsg1(jcr, M_FATAL, 0, "Unknown backup level: %s\n", level);
1101 return bnet_fsend(dir, OKlevel);
1104 pm_strcpy(jcr->errmsg, dir->msg);
1105 Jmsg1(jcr, M_FATAL, 0, _("Bad level command: %s\n"), jcr->errmsg);
1114 * Get session parameters from Director -- this is for a Restore command
1116 static int session_cmd(JCR *jcr)
1118 BSOCK *dir = jcr->dir_bsock;
1120 Dmsg1(100, "SessionCmd: %s", dir->msg);
1121 if (sscanf(dir->msg, sessioncmd, jcr->VolumeName,
1122 &jcr->VolSessionId, &jcr->VolSessionTime,
1123 &jcr->StartFile, &jcr->EndFile,
1124 &jcr->StartBlock, &jcr->EndBlock) != 7) {
1125 pm_strcpy(jcr->errmsg, dir->msg);
1126 Jmsg(jcr, M_FATAL, 0, "Bad session command: %s", jcr->errmsg);
1130 return bnet_fsend(dir, OKsession);
1134 * Get address of storage daemon from Director
1137 static int storage_cmd(JCR *jcr)
1139 int stored_port; /* storage daemon port */
1140 int enable_ssl; /* enable ssl to sd */
1141 BSOCK *dir = jcr->dir_bsock;
1142 BSOCK *sd; /* storage daemon bsock */
1144 Dmsg1(100, "StorageCmd: %s", dir->msg);
1145 if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port, &enable_ssl) != 3) {
1146 pm_strcpy(jcr->errmsg, dir->msg);
1147 Jmsg(jcr, M_FATAL, 0, _("Bad storage command: %s"), jcr->errmsg);
1150 Dmsg3(110, "Open storage: %s:%d ssl=%d\n", jcr->stored_addr, stored_port, enable_ssl);
1151 /* Open command communications with Storage daemon */
1152 /* Try to connect for 1 hour at 10 second intervals */
1153 sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"),
1154 jcr->stored_addr, NULL, stored_port, 1);
1156 Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
1157 jcr->stored_addr, stored_port);
1158 Dmsg2(100, "Failed to connect to Storage daemon: %s:%d\n",
1159 jcr->stored_addr, stored_port);
1162 Dmsg0(110, "Connection OK to SD.\n");
1164 jcr->store_bsock = sd;
1166 bnet_fsend(sd, "Hello Start Job %s\n", jcr->Job);
1167 if (!authenticate_storagedaemon(jcr)) {
1168 Jmsg(jcr, M_FATAL, 0, _("Failed to authenticate Storage daemon.\n"));
1171 Dmsg0(110, "Authenticated with SD.\n");
1173 /* Send OK to Director */
1174 return bnet_fsend(dir, OKstore);
1179 * Do a backup. For now, we handle only Full and Incremental.
1181 static int backup_cmd(JCR *jcr)
1183 BSOCK *dir = jcr->dir_bsock;
1184 BSOCK *sd = jcr->store_bsock;
1187 char ed1[50], ed2[50];
1189 set_jcr_job_status(jcr, JS_Blocked);
1190 jcr->JobType = JT_BACKUP;
1191 Dmsg1(100, "begin backup ff=%p\n", (FF_PKT *)jcr->ff);
1194 Jmsg(jcr, M_FATAL, 0, _("Cannot contact Storage daemon\n"));
1198 bnet_fsend(dir, OKbackup);
1199 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1202 * Send Append Open Session to Storage daemon
1204 bnet_fsend(sd, append_open);
1205 Dmsg1(110, ">stored: %s", sd->msg);
1207 * Expect to receive back the Ticket number
1209 if (bget_msg(sd) >= 0) {
1210 Dmsg1(110, "<stored: %s", sd->msg);
1211 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
1212 Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg);
1215 Dmsg1(110, "Got Ticket=%d\n", jcr->Ticket);
1217 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to open command\n"));
1222 * Send Append data command to Storage daemon
1224 bnet_fsend(sd, append_data, jcr->Ticket);
1225 Dmsg1(110, ">stored: %s", sd->msg);
1228 * Expect to get OK data
1230 Dmsg1(110, "<stored: %s", sd->msg);
1231 if (!response(jcr, sd, OK_data, "Append Data")) {
1236 * Send Files to Storage daemon
1238 Dmsg1(110, "begin blast ff=%p\n", (FF_PKT *)jcr->ff);
1239 if (!blast_data_to_storage_daemon(jcr, NULL)) {
1240 set_jcr_job_status(jcr, JS_ErrorTerminated);
1241 bnet_suppress_error_messages(sd, 1);
1242 Dmsg0(110, "Error in blast_data.\n");
1244 set_jcr_job_status(jcr, JS_Terminated);
1245 if (jcr->JobStatus != JS_Terminated) {
1246 bnet_suppress_error_messages(sd, 1);
1247 goto cleanup; /* bail out now */
1250 * Expect to get response to append_data from Storage daemon
1252 if (!response(jcr, sd, OK_append, "Append Data")) {
1253 set_jcr_job_status(jcr, JS_ErrorTerminated);
1258 * Send Append End Data to Storage daemon
1260 bnet_fsend(sd, append_end, jcr->Ticket);
1262 if (!response(jcr, sd, OK_end, "Append End")) {
1263 set_jcr_job_status(jcr, JS_ErrorTerminated);
1268 * Send Append Close to Storage daemon
1270 bnet_fsend(sd, append_close, jcr->Ticket);
1271 while (bget_msg(sd) >= 0) { /* stop on signal or error */
1272 if (sscanf(sd->msg, OK_close, &SDJobStatus) == 1) {
1274 Dmsg2(200, "SDJobStatus = %d %c\n", SDJobStatus, (char)SDJobStatus);
1278 Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n"));
1281 if (SDJobStatus != JS_Terminated) {
1282 Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"),
1288 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1289 edit_uint64(jcr->ReadBytes, ed1),
1290 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1291 Dmsg1(110, "End FD msg: %s\n", dir->msg);
1293 return 0; /* return and stop command loop */
1297 * Do a Verify for Director
1300 static int verify_cmd(JCR *jcr)
1302 BSOCK *dir = jcr->dir_bsock;
1303 BSOCK *sd = jcr->store_bsock;
1304 char level[100], ed1[50], ed2[50];
1306 jcr->JobType = JT_VERIFY;
1307 if (sscanf(dir->msg, verifycmd, level) != 1) {
1308 bnet_fsend(dir, "2994 Bad verify command: %s\n", dir->msg);
1311 if (strcasecmp(level, "init") == 0) {
1312 jcr->JobLevel = L_VERIFY_INIT;
1313 } else if (strcasecmp(level, "catalog") == 0){
1314 jcr->JobLevel = L_VERIFY_CATALOG;
1315 } else if (strcasecmp(level, "volume") == 0){
1316 jcr->JobLevel = L_VERIFY_VOLUME_TO_CATALOG;
1317 } else if (strcasecmp(level, "data") == 0){
1318 jcr->JobLevel = L_VERIFY_DATA;
1319 } else if (strcasecmp(level, "disk_to_catalog") == 0) {
1320 jcr->JobLevel = L_VERIFY_DISK_TO_CATALOG;
1322 bnet_fsend(dir, "2994 Bad verify level: %s\n", dir->msg);
1326 bnet_fsend(dir, OKverify);
1327 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1329 switch (jcr->JobLevel) {
1331 case L_VERIFY_CATALOG:
1334 case L_VERIFY_VOLUME_TO_CATALOG:
1335 if (!open_sd_read_session(jcr)) {
1338 start_dir_heartbeat(jcr);
1339 do_verify_volume(jcr);
1340 stop_dir_heartbeat(jcr);
1342 * Send Close session command to Storage daemon
1344 bnet_fsend(sd, read_close, jcr->Ticket);
1345 Dmsg1(130, "bfiled>stored: %s", sd->msg);
1347 /* ****FIXME**** check response */
1348 bget_msg(sd); /* get OK */
1350 /* Inform Storage daemon that we are done */
1351 bnet_sig(sd, BNET_TERMINATE);
1354 case L_VERIFY_DISK_TO_CATALOG:
1358 bnet_fsend(dir, "2994 Bad verify level: %s\n", dir->msg);
1362 bnet_sig(dir, BNET_EOD);
1364 /* Send termination status back to Dir */
1365 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1366 edit_uint64(jcr->ReadBytes, ed1),
1367 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1369 /* Inform Director that we are done */
1370 bnet_sig(dir, BNET_TERMINATE);
1371 return 0; /* return and terminate command loop */
1375 * Do a Restore for Director
1378 static int restore_cmd(JCR *jcr)
1380 BSOCK *dir = jcr->dir_bsock;
1381 BSOCK *sd = jcr->store_bsock;
1385 char ed1[50], ed2[50];
1388 * Scan WHERE (base directory for restore) from command
1390 Dmsg0(150, "restore command\n");
1391 /* Pickup where string */
1392 where = get_memory(dir->msglen+1);
1395 if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, where) != 3) {
1396 if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) {
1397 pm_strcpy(jcr->errmsg, dir->msg);
1398 Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
1403 /* Turn / into nothing */
1404 if (where[0] == '/' && where[1] == 0) {
1408 Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
1409 unbash_spaces(where);
1410 jcr->where = bstrdup(where);
1411 free_pool_memory(where);
1412 jcr->replace = replace;
1413 jcr->prefix_links = prefix_links;
1415 bnet_fsend(dir, OKrestore);
1416 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1418 jcr->JobType = JT_RESTORE;
1420 set_jcr_job_status(jcr, JS_Blocked);
1421 if (!open_sd_read_session(jcr)) {
1422 set_jcr_job_status(jcr, JS_ErrorTerminated);
1426 set_jcr_job_status(jcr, JS_Running);
1429 * Do restore of files and data
1431 start_dir_heartbeat(jcr);
1433 stop_dir_heartbeat(jcr);
1435 set_jcr_job_status(jcr, JS_Terminated);
1436 if (jcr->JobStatus != JS_Terminated) {
1437 bnet_suppress_error_messages(sd, 1);
1441 * Send Close session command to Storage daemon
1443 bnet_fsend(sd, read_close, jcr->Ticket);
1444 Dmsg1(130, "bfiled>stored: %s", sd->msg);
1446 bget_msg(sd); /* get OK */
1448 /* Inform Storage daemon that we are done */
1449 bnet_sig(sd, BNET_TERMINATE);
1454 set_jcr_job_status(jcr, JS_ErrorTerminated);
1456 /* Send termination status back to Dir */
1457 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1458 edit_uint64(jcr->ReadBytes, ed1),
1459 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1461 /* Inform Director that we are done */
1462 bnet_sig(dir, BNET_TERMINATE);
1464 Dmsg0(130, "Done in job.c\n");
1465 return 0; /* return and terminate command loop */
1468 static int open_sd_read_session(JCR *jcr)
1470 BSOCK *sd = jcr->store_bsock;
1473 Jmsg(jcr, M_FATAL, 0, _("Improper calling sequence.\n"));
1476 Dmsg4(120, "VolSessId=%ld VolsessT=%ld SF=%ld EF=%ld\n",
1477 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile);
1478 Dmsg2(120, "JobId=%d vol=%s\n", jcr->JobId, "DummyVolume");
1480 * Open Read Session with Storage daemon
1482 bnet_fsend(sd, read_open, jcr->VolumeName,
1483 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile,
1484 jcr->StartBlock, jcr->EndBlock);
1485 Dmsg1(110, ">stored: %s", sd->msg);
1490 if (bget_msg(sd) >= 0) {
1491 Dmsg1(110, "bfiled<stored: %s", sd->msg);
1492 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
1493 Jmsg(jcr, M_FATAL, 0, _("Bad response to SD read open: %s\n"), sd->msg);
1496 Dmsg1(110, "bfiled: got Ticket=%d\n", jcr->Ticket);
1498 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to read open command\n"));
1502 if (!send_bootstrap_file(jcr)) {
1507 * Start read of data with Storage daemon
1509 bnet_fsend(sd, read_data, jcr->Ticket);
1510 Dmsg1(110, ">stored: %s", sd->msg);
1515 if (!response(jcr, sd, OK_data, "Read Data")) {
1522 * Destroy the Job Control Record and associated
1523 * resources (sockets).
1525 static void filed_free_jcr(JCR *jcr)
1527 if (jcr->store_bsock) {
1528 bnet_close(jcr->store_bsock);
1530 if (jcr->RestoreBootstrap) {
1531 unlink(jcr->RestoreBootstrap);
1532 free_pool_memory(jcr->RestoreBootstrap);
1533 jcr->RestoreBootstrap = NULL;
1535 if (jcr->last_fname) {
1536 free_pool_memory(jcr->last_fname);
1538 if (jcr->RunAfterJob) {
1539 free_pool_memory(jcr->RunAfterJob);
1547 * Get response from Storage daemon to a command we
1548 * sent. Check that the response is OK.
1550 * Returns: 0 on failure
1553 int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd)
1558 if (bget_msg(sd) > 0) {
1559 Dmsg0(110, sd->msg);
1560 if (strcmp(sd->msg, resp) == 0) {
1564 if (job_canceled(jcr)) {
1565 return 0; /* if canceled avoid useless error messages */
1567 if (is_bnet_error(sd)) {
1568 Jmsg2(jcr, M_FATAL, 0, _("Comm error with SD. bad response to %s. ERR=%s\n"),
1569 cmd, bnet_strerror(sd));
1571 Jmsg3(jcr, M_FATAL, 0, _("Bad response to %s command. Wanted %s, got %s\n"),
1572 cmd, resp, sd->msg);
1577 static int send_bootstrap_file(JCR *jcr)
1581 BSOCK *sd = jcr->store_bsock;
1582 const char *bootstrap = "bootstrap\n";
1585 Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
1586 if (!jcr->RestoreBootstrap) {
1589 bs = fopen(jcr->RestoreBootstrap, "r");
1592 Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
1593 jcr->RestoreBootstrap, be.strerror());
1594 set_jcr_job_status(jcr, JS_ErrorTerminated);
1597 sd->msglen = pm_strcpy(sd->msg, bootstrap);
1599 while (fgets(buf, sizeof(buf), bs)) {
1600 sd->msglen = Mmsg(sd->msg, "%s", buf);
1603 bnet_sig(sd, BNET_EOD);
1605 if (!response(jcr, sd, OKSDbootstrap, "Bootstrap")) {
1606 set_jcr_job_status(jcr, JS_ErrorTerminated);
1612 if (jcr->RestoreBootstrap) {
1613 unlink(jcr->RestoreBootstrap);
1614 free_pool_memory(jcr->RestoreBootstrap);
1615 jcr->RestoreBootstrap = NULL;