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");
233 /* Inform Director that we are done */
234 bnet_sig(dir, BNET_TERMINATE);
236 /* Clean up fileset */
237 FF_PKT *ff = (FF_PKT *)jcr->ff;
238 findFILESET *fileset = ff->fileset;
241 /* Delete FileSet Include lists */
242 for (i=0; i<fileset->include_list.size(); i++) {
243 findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
244 for (j=0; j<incexe->opts_list.size(); j++) {
245 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
246 for (k=0; k<fo->regex.size(); k++) {
247 regfree((regex_t *)fo->regex.get(k));
259 incexe->opts_list.destroy();
260 incexe->name_list.destroy();
262 fileset->include_list.destroy();
264 /* Delete FileSet Exclude lists */
265 for (i=0; i<fileset->exclude_list.size(); i++) {
266 findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
267 for (j=0; j<incexe->opts_list.size(); j++) {
268 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
273 incexe->opts_list.destroy();
274 incexe->name_list.destroy();
276 fileset->exclude_list.destroy();
279 Dmsg0(100, "Calling term_find_files\n");
280 term_find_files((FF_PKT *)jcr->ff);
281 Dmsg0(100, "Done with term_find_files\n");
282 free_jcr(jcr); /* destroy JCR record */
283 Dmsg0(100, "Done with free_jcr\n");
288 * Hello from Director he must identify himself and provide his
291 static int hello_cmd(JCR *jcr)
293 Dmsg0(120, "Calling Authenticate\n");
294 if (!authenticate_director(jcr)) {
297 Dmsg0(120, "OK Authenticate\n");
298 jcr->authenticated = true;
305 static int cancel_cmd(JCR *jcr)
307 BSOCK *dir = jcr->dir_bsock;
308 char Job[MAX_NAME_LENGTH];
311 if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
312 if (!(cjcr=get_jcr_by_full_name(Job))) {
313 bnet_fsend(dir, "2901 Job %s not found.\n", Job);
315 if (cjcr->store_bsock) {
317 cjcr->store_bsock->timed_out = 1;
318 cjcr->store_bsock->terminated = 1;
320 * #if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
322 #if !defined(HAVE_CYGWIN)
323 pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL);
327 set_jcr_job_status(cjcr, JS_Canceled);
329 bnet_fsend(dir, _("2001 Job %s marked to be canceled.\n"), Job);
332 bnet_fsend(dir, _("2902 Error scanning cancel command.\n"));
334 bnet_sig(dir, BNET_EOD);
340 * Set debug level as requested by the Director
343 static int setdebug_cmd(JCR *jcr)
345 BSOCK *dir = jcr->dir_bsock;
346 int level, trace_flag;
348 Dmsg1(110, "setdebug_cmd: %s", dir->msg);
349 if (sscanf(dir->msg, "setdebug=%d trace=%d", &level, &trace_flag) != 2 || level < 0) {
350 pm_strcpy(&jcr->errmsg, dir->msg);
351 bnet_fsend(dir, "2991 Bad setdebug command: %s\n", jcr->errmsg);
355 set_trace(trace_flag);
356 return bnet_fsend(dir, OKsetdebug, level);
360 static int estimate_cmd(JCR *jcr)
362 BSOCK *dir = jcr->dir_bsock;
365 if (sscanf(dir->msg, estimatecmd, &jcr->listing) != 1) {
366 pm_strcpy(&jcr->errmsg, dir->msg);
367 Jmsg(jcr, M_FATAL, 0, _("Bad estimate command: %s"), jcr->errmsg);
368 bnet_fsend(dir, "2992 Bad estimate command.\n");
372 bnet_fsend(dir, OKest, jcr->num_files_examined,
373 edit_uint64_with_commas(jcr->JobBytes, ed2));
374 bnet_sig(dir, BNET_EOD);
379 * Get JobId and Storage Daemon Authorization key from Director
381 static int job_cmd(JCR *jcr)
383 BSOCK *dir = jcr->dir_bsock;
384 POOLMEM *sd_auth_key;
386 sd_auth_key = get_memory(dir->msglen);
387 if (sscanf(dir->msg, jobcmd, &jcr->JobId, jcr->Job,
388 &jcr->VolSessionId, &jcr->VolSessionTime,
390 pm_strcpy(&jcr->errmsg, dir->msg);
391 Jmsg(jcr, M_FATAL, 0, _("Bad Job Command: %s"), jcr->errmsg);
392 bnet_fsend(dir, BADjob);
393 free_pool_memory(sd_auth_key);
396 jcr->sd_auth_key = bstrdup(sd_auth_key);
397 free_pool_memory(sd_auth_key);
398 Dmsg2(120, "JobId=%d Auth=%s\n", jcr->JobId, jcr->sd_auth_key);
399 return bnet_fsend(dir, OKjob, HOST_OS, DISTNAME, DISTVER);
402 static int runbefore_cmd(JCR *jcr)
405 BSOCK *dir = jcr->dir_bsock;
406 POOLMEM *cmd = get_memory(dir->msglen+1);
408 Dmsg1(100, "runbefore_cmd: %s", dir->msg);
409 if (sscanf(dir->msg, runbefore, cmd) != 1) {
410 pm_strcpy(&jcr->errmsg, dir->msg);
411 Jmsg1(jcr, M_FATAL, 0, _("Bad RunBeforeJob command: %s\n"), jcr->errmsg);
412 bnet_fsend(dir, "2905 Bad RunBeforeJob command.\n");
418 /* Run the command now */
419 stat = run_cmd(jcr, cmd, "ClientRunBeforeJob");
422 bnet_fsend(dir, OKRunBefore);
425 bnet_fsend(dir, "2905 Bad RunBeforeJob command.\n");
430 static int runafter_cmd(JCR *jcr)
432 BSOCK *dir = jcr->dir_bsock;
433 POOLMEM *msg = get_memory(dir->msglen+1);
435 Dmsg1(100, "runafter_cmd: %s", dir->msg);
436 if (sscanf(dir->msg, runafter, msg) != 1) {
437 pm_strcpy(&jcr->errmsg, dir->msg);
438 Jmsg1(jcr, M_FATAL, 0, _("Bad RunAfter command: %s\n"), jcr->errmsg);
439 bnet_fsend(dir, "2905 Bad RunAfterJob command.\n");
444 if (jcr->RunAfterJob) {
445 free_pool_memory(jcr->RunAfterJob);
447 jcr->RunAfterJob = get_pool_memory(PM_FNAME);
448 pm_strcpy(&jcr->RunAfterJob, msg);
449 free_pool_memory(msg);
450 return bnet_fsend(dir, OKRunAfter);
453 static int run_cmd(JCR *jcr, char *cmd, const char *name)
455 POOLMEM *ecmd = get_pool_memory(PM_FNAME);
458 char line[MAXSTRING];
460 ecmd = edit_job_codes(jcr, ecmd, cmd, "");
461 bpipe = open_bpipe(ecmd, 0, "r");
462 free_pool_memory(ecmd);
464 Jmsg(jcr, M_FATAL, 0, _("%s could not execute\n"), name);
465 set_jcr_job_status(jcr, JS_FatalError);
468 while (fgets(line, sizeof(line), bpipe->rfd)) {
469 Jmsg(jcr, M_INFO, 0, _("%s: %s"), name, line);
471 status = close_bpipe(bpipe);
473 Jmsg(jcr, M_FATAL, 0, _("%s returned non-zero status=%d\n"), name,
475 set_jcr_job_status(jcr, JS_FatalError);
485 static void add_fname_to_list(JCR *jcr, char *fname, int list)
495 /* Skip leading options -- currently ignored */
496 for (p=fname; *p && *p != ' '; p++)
498 /* Skip spaces, and q points to first space */
499 for (q=NULL; *p && *p == ' '; p++) {
507 p++; /* skip over | */
508 fn = get_pool_memory(PM_FNAME);
509 fn = edit_job_codes(jcr, fn, p, "");
510 bpipe = open_bpipe(fn, 0, "r");
511 free_pool_memory(fn);
513 Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
517 /* Copy File options */
518 if (list == INC_LIST) {
519 *q = 0; /* terminate options */
522 optlen = strlen(buf);
526 while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) {
527 strip_trailing_junk(buf);
528 if (list == INC_LIST) {
529 add_fname_to_include_list((FF_PKT *)jcr->ff, 1, buf);
531 add_fname_to_exclude_list((FF_PKT *)jcr->ff, buf);
534 if ((stat=close_bpipe(bpipe)) != 0) {
535 Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
536 p, stat, strerror(errno));
541 p++; /* skip over < */
542 if ((ffd = fopen(p, "r")) == NULL) {
544 Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
545 list==INC_LIST?"included":"excluded", p, be.strerror());
548 /* Copy File options */
549 if (list == INC_LIST) {
550 *q = 0; /* terminate options */
553 optlen = strlen(buf);
557 while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) {
558 strip_trailing_junk(buf);
559 if (list == INC_LIST) {
560 add_fname_to_include_list((FF_PKT *)jcr->ff, 1, buf);
562 add_fname_to_exclude_list((FF_PKT *)jcr->ff, buf);
568 if (list == INC_LIST) {
569 add_fname_to_include_list((FF_PKT *)jcr->ff, 1, fname);
571 add_fname_to_exclude_list((FF_PKT *)jcr->ff, p);
579 * Get list of files/directories to include from Director
582 static int include_cmd(JCR *jcr)
584 BSOCK *dir = jcr->dir_bsock;
586 while (bnet_recv(dir) >= 0) {
587 dir->msg[dir->msglen] = 0;
588 strip_trailing_junk(dir->msg);
589 Dmsg1(010, "include file: %s\n", dir->msg);
590 add_fname_to_list(jcr, dir->msg, INC_LIST);
593 return bnet_fsend(dir, OKinc);
596 static bool init_fileset(JCR *jcr)
599 findFILESET *fileset;
604 ff = (FF_PKT *)jcr->ff;
608 fileset = (findFILESET *)malloc(sizeof(findFILESET));
609 memset(fileset, 0, sizeof(findFILESET));
610 ff->fileset = fileset;
611 fileset->state = state_none;
612 fileset->include_list.init(1, true);
613 fileset->exclude_list.init(1, true);
617 static findFOPTS *start_options(FF_PKT *ff)
619 int state = ff->fileset->state;
620 findINCEXE *incexe = ff->fileset->incexe;
622 if (state != state_options) {
623 ff->fileset->state = state_options;
624 findFOPTS *fo = (findFOPTS *)malloc(sizeof(findFOPTS));
625 memset(fo, 0, sizeof(findFOPTS));
626 fo->regex.init(1, true);
627 fo->wild.init(1, true);
628 fo->base.init(1, true);
629 incexe->current_opts = fo;
630 incexe->opts_list.append(fo);
632 return incexe->current_opts;
637 * Add fname to include/exclude fileset list. First check for
638 * | and < and if necessary perform command.
640 static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *fileset)
652 p++; /* skip over | */
653 fn = get_pool_memory(PM_FNAME);
654 fn = edit_job_codes(jcr, fn, p, "");
655 bpipe = open_bpipe(fn, 0, "r");
656 free_pool_memory(fn);
658 Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
662 while (fgets(buf, sizeof(buf), bpipe->rfd)) {
663 strip_trailing_junk(buf);
664 fileset->incexe->name_list.append(bstrdup(buf));
666 if ((stat=close_bpipe(bpipe)) != 0) {
667 Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
668 p, stat, strerror(errno));
673 p++; /* skip over < */
674 if ((ffd = fopen(p, "r")) == NULL) {
676 Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"),
680 while (fgets(buf, sizeof(buf), ffd)) {
681 strip_trailing_junk(buf);
682 fileset->incexe->name_list.append(bstrdup(buf));
687 fileset->incexe->name_list.append(bstrdup(fname));
693 static void add_fileset(JCR *jcr, const char *item)
695 FF_PKT *ff = (FF_PKT *)jcr->ff;
696 findFILESET *fileset = ff->fileset;
697 int state = fileset->state;
698 findFOPTS *current_opts;
700 Dmsg1(100, "%s\n", item);
702 if (item[1] == ' ') { /* If string follows */
703 item += 2; /* point to string */
706 if (state == state_error) {
712 fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
713 memset(fileset->incexe, 0, sizeof(findINCEXE));
714 fileset->incexe->opts_list.init(1, true);
715 fileset->incexe->name_list.init(1, true);
716 fileset->include_list.append(fileset->incexe);
720 fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
721 memset(fileset->incexe, 0, sizeof(findINCEXE));
722 fileset->incexe->opts_list.init(1, true);
723 fileset->incexe->name_list.init(1, true);
724 fileset->exclude_list.append(fileset->incexe);
730 /* File item to either include/include list */
731 state = state_include;
732 add_file_to_fileset(jcr, item, fileset);
735 current_opts = start_options(ff);
739 preg = (regex_t *)malloc(sizeof(regex_t));
740 rc = regcomp(preg, item, REG_EXTENDED);
742 regerror(rc, preg, prbuf, sizeof(prbuf));
745 Jmsg(jcr, M_FATAL, 0, "REGEX %s compile error. ERR=%s\n", item, prbuf);
749 current_opts->regex.append(preg);
750 state = state_options;
753 current_opts = start_options(ff);
754 current_opts->base.append(bstrdup(item));
755 state = state_options;
758 current_opts = start_options(ff);
759 current_opts->wild.append(bstrdup(item));
760 state = state_options;
763 current_opts = start_options(ff);
764 set_options(current_opts, item);
765 state = state_options;
768 current_opts = start_options(ff);
769 current_opts->reader = bstrdup(item);
770 state = state_options;
773 current_opts = start_options(ff);
774 current_opts->writer = bstrdup(item);
775 state = state_options;
778 Jmsg(jcr, M_FATAL, 0, "Invalid FileSet command: %s\n", item);
782 ff->fileset->state = state;
785 static bool term_fileset(JCR *jcr)
787 FF_PKT *ff = (FF_PKT *)jcr->ff;
788 findFILESET *fileset = ff->fileset;
791 for (i=0; i<fileset->include_list.size(); i++) {
792 findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
794 for (j=0; j<incexe->opts_list.size(); j++) {
795 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
796 for (k=0; k<fo->regex.size(); k++) {
797 Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
799 for (k=0; k<fo->wild.size(); k++) {
800 Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
802 for (k=0; k<fo->base.size(); k++) {
803 Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
806 Dmsg1(400, "D %s\n", fo->reader);
809 Dmsg1(400, "T %s\n", fo->writer);
812 for (j=0; j<incexe->name_list.size(); j++) {
813 Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
816 for (i=0; i<fileset->exclude_list.size(); i++) {
817 findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
819 for (j=0; j<incexe->opts_list.size(); j++) {
820 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
821 for (k=0; k<fo->regex.size(); k++) {
822 Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
824 for (k=0; k<fo->wild.size(); k++) {
825 Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
827 for (k=0; k<fo->base.size(); k++) {
828 Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
831 for (j=0; j<incexe->name_list.size(); j++) {
832 Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
835 return ff->fileset->state != state_error;
840 * As an optimization, we should do this during
841 * "compile" time in filed/job.c, and keep only a bit mask
842 * and the Verify options.
844 static void set_options(findFOPTS *fo, const char *opts)
849 for (p=opts; *p; p++) {
851 case 'a': /* alway replace */
852 case '0': /* no option */
855 fo->flags |= FO_EXCLUDE;
858 fo->flags |= FO_MULTIFS;
860 case 'h': /* no recursion */
861 fo->flags |= FO_NO_RECURSION;
867 fo->flags |= FO_NOREPLACE;
869 case 'p': /* use portable data format */
870 fo->flags |= FO_PORTABLE;
872 case 'r': /* read fifo */
873 fo->flags |= FO_READFIFO;
876 fo->flags |= FO_SHA1;
879 fo->flags |= FO_SPARSE;
882 fo->flags |= FO_MTIMEONLY;
885 fo->flags |= FO_KEEPATIME;
887 case 'V': /* verify options */
888 /* Copy Verify Options */
889 for (j=0; *p && *p != ':'; p++) {
890 fo->VerifyOpts[j] = *p;
891 if (j < (int)sizeof(fo->VerifyOpts) - 1) {
895 fo->VerifyOpts[j] = 0;
898 fo->flags |= FO_IF_NEWER;
900 case 'Z': /* gzip compression */
901 fo->flags |= FO_GZIP;
902 fo->GZIP_level = *++p - '0';
903 Dmsg1(200, "Compression level=%d\n", fo->GZIP_level);
906 Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *p);
914 * Director is passing his Fileset
916 static int fileset_cmd(JCR *jcr)
918 BSOCK *dir = jcr->dir_bsock;
920 if (!init_fileset(jcr)) {
923 while (bnet_recv(dir) >= 0) {
924 strip_trailing_junk(dir->msg);
925 Dmsg1(400, "Fileset: %s\n", dir->msg);
926 add_fileset(jcr, dir->msg);
928 if (!term_fileset(jcr)) {
931 return bnet_fsend(dir, OKinc);
936 * Get list of files to exclude from Director
939 static int exclude_cmd(JCR *jcr)
941 BSOCK *dir = jcr->dir_bsock;
943 while (bnet_recv(dir) >= 0) {
944 dir->msg[dir->msglen] = 0;
945 strip_trailing_junk(dir->msg);
946 add_fname_to_list(jcr, dir->msg, EXC_LIST);
947 Dmsg1(110, "<dird: exclude file %s\n", dir->msg);
950 return bnet_fsend(dir, OKexc);
954 static int bootstrap_cmd(JCR *jcr)
956 BSOCK *dir = jcr->dir_bsock;
957 POOLMEM *fname = get_pool_memory(PM_FNAME);
960 if (jcr->RestoreBootstrap) {
961 unlink(jcr->RestoreBootstrap);
962 free_pool_memory(jcr->RestoreBootstrap);
964 Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
966 Dmsg1(400, "bootstrap=%s\n", fname);
967 jcr->RestoreBootstrap = fname;
968 bs = fopen(fname, "a+"); /* create file */
972 * Suck up what he is sending to us so that he will then
973 * read our error message.
975 while (bnet_recv(dir) >= 0)
978 Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"),
979 jcr->RestoreBootstrap, be.strerror());
980 free_pool_memory(jcr->RestoreBootstrap);
981 jcr->RestoreBootstrap = NULL;
982 set_jcr_job_status(jcr, JS_ErrorTerminated);
986 while (bnet_recv(dir) >= 0) {
987 Dmsg1(200, "filed<dird: bootstrap file %s\n", dir->msg);
992 return bnet_fsend(dir, OKbootstrap);
997 * Get backup level from Director
1000 static int level_cmd(JCR *jcr)
1002 BSOCK *dir = jcr->dir_bsock;
1003 POOLMEM *level, *buf = NULL;
1008 level = get_memory(dir->msglen+1);
1009 Dmsg1(110, "level_cmd: %s", dir->msg);
1010 if (sscanf(dir->msg, "level = %s ", level) != 1) {
1013 /* Base backup requested? */
1014 if (strcmp(level, "base") == 0) {
1015 jcr->JobLevel = L_BASE;
1016 /* Full backup requested? */
1017 } else if (strcmp(level, "full") == 0) {
1018 jcr->JobLevel = L_FULL;
1020 * Backup requested since <date> <time>
1021 * This form is also used for incremental and differential
1022 * This code is deprecated. See since_utime for new code.
1024 } else if (strcmp(level, "since") == 0) {
1025 jcr->JobLevel = L_SINCE;
1026 if (sscanf(dir->msg, "level = since %d-%d-%d %d:%d:%d mtime_only=%d",
1027 &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
1028 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &mtime_only) != 7) {
1033 tm.tm_wday = tm.tm_yday = 0;
1035 mtime = mktime(&tm);
1036 Dmsg2(100, "Got since time: %s mtime_only=%d\n", ctime(&mtime), mtime_only);
1037 jcr->incremental = 1; /* set incremental or decremental backup */
1038 jcr->mtime = mtime; /* set since time */
1040 * We get his UTC since time, then sync the clocks and correct it
1041 * to agree with our clock.
1043 } else if (strcmp(level, "since_utime") == 0) {
1044 buf = get_memory(dir->msglen+1);
1045 utime_t since_time, adj;
1046 btime_t his_time, bt_start, rt=0, bt_adj=0;
1047 jcr->JobLevel = L_SINCE;
1048 if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
1049 buf, &mtime_only) != 2) {
1052 since_time = str_to_uint64(buf); /* this is the since time */
1053 char ed1[50], ed2[50];
1055 * Sync clocks by polling him for the time. We take
1056 * 10 samples of his time throwing out the first two.
1058 for (int i=0; i<10; i++) {
1059 bt_start = get_current_btime();
1060 bnet_sig(dir, BNET_BTIME); /* poll for time */
1061 if (bnet_recv(dir) <= 0) { /* get response */
1064 if (sscanf(dir->msg, "btime %s", buf) != 1) {
1067 if (i < 2) { /* toss first two results */
1070 his_time = str_to_uint64(buf);
1071 rt = get_current_btime() - bt_start; /* compute round trip time */
1072 bt_adj -= his_time - bt_start - rt/2;
1073 Dmsg2(200, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
1076 bt_adj = bt_adj / 8; /* compute average time */
1077 Dmsg2(100, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
1078 adj = btime_to_utime(bt_adj);
1079 since_time += adj; /* adjust for clock difference */
1081 Jmsg(jcr, M_INFO, 0, _("Since time adjusted by %d seconds.\n"), adj);
1083 bnet_sig(dir, BNET_EOD);
1085 Dmsg2(100, "adj = %d since_time=%d\n", (int)adj, (int)since_time);
1086 jcr->incremental = 1; /* set incremental or decremental backup */
1087 jcr->mtime = (time_t)since_time; /* set since time */
1089 Jmsg1(jcr, M_FATAL, 0, "Unknown backup level: %s\n", level);
1097 return bnet_fsend(dir, OKlevel);
1100 pm_strcpy(&jcr->errmsg, dir->msg);
1101 Jmsg1(jcr, M_FATAL, 0, _("Bad level command: %s\n"), jcr->errmsg);
1110 * Get session parameters from Director -- this is for a Restore command
1112 static int session_cmd(JCR *jcr)
1114 BSOCK *dir = jcr->dir_bsock;
1116 Dmsg1(100, "SessionCmd: %s", dir->msg);
1117 if (sscanf(dir->msg, sessioncmd, jcr->VolumeName,
1118 &jcr->VolSessionId, &jcr->VolSessionTime,
1119 &jcr->StartFile, &jcr->EndFile,
1120 &jcr->StartBlock, &jcr->EndBlock) != 7) {
1121 pm_strcpy(&jcr->errmsg, dir->msg);
1122 Jmsg(jcr, M_FATAL, 0, "Bad session command: %s", jcr->errmsg);
1126 return bnet_fsend(dir, OKsession);
1130 * Get address of storage daemon from Director
1133 static int storage_cmd(JCR *jcr)
1135 int stored_port; /* storage daemon port */
1136 int enable_ssl; /* enable ssl to sd */
1137 BSOCK *dir = jcr->dir_bsock;
1138 BSOCK *sd; /* storage daemon bsock */
1140 Dmsg1(100, "StorageCmd: %s", dir->msg);
1141 if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port, &enable_ssl) != 3) {
1142 pm_strcpy(&jcr->errmsg, dir->msg);
1143 Jmsg(jcr, M_FATAL, 0, _("Bad storage command: %s"), jcr->errmsg);
1146 Dmsg3(110, "Open storage: %s:%d ssl=%d\n", jcr->stored_addr, stored_port, enable_ssl);
1147 /* Open command communications with Storage daemon */
1148 /* Try to connect for 1 hour at 10 second intervals */
1149 sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"),
1150 jcr->stored_addr, NULL, stored_port, 1);
1152 Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
1153 jcr->stored_addr, stored_port);
1154 Dmsg2(100, "Failed to connect to Storage daemon: %s:%d\n",
1155 jcr->stored_addr, stored_port);
1158 Dmsg0(110, "Connection OK to SD.\n");
1160 jcr->store_bsock = sd;
1162 bnet_fsend(sd, "Hello Start Job %s\n", jcr->Job);
1163 if (!authenticate_storagedaemon(jcr)) {
1164 Jmsg(jcr, M_FATAL, 0, _("Failed to authenticate Storage daemon.\n"));
1167 Dmsg0(110, "Authenticated with SD.\n");
1169 /* Send OK to Director */
1170 return bnet_fsend(dir, OKstore);
1175 * Do a backup. For now, we handle only Full and Incremental.
1177 static int backup_cmd(JCR *jcr)
1179 BSOCK *dir = jcr->dir_bsock;
1180 BSOCK *sd = jcr->store_bsock;
1183 char ed1[50], ed2[50];
1185 set_jcr_job_status(jcr, JS_Blocked);
1186 jcr->JobType = JT_BACKUP;
1187 Dmsg1(100, "begin backup ff=%p\n", (FF_PKT *)jcr->ff);
1190 Jmsg(jcr, M_FATAL, 0, _("Cannot contact Storage daemon\n"));
1194 bnet_fsend(dir, OKbackup);
1195 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1198 * Send Append Open Session to Storage daemon
1200 bnet_fsend(sd, append_open);
1201 Dmsg1(110, ">stored: %s", sd->msg);
1203 * Expect to receive back the Ticket number
1205 if (bget_msg(sd) >= 0) {
1206 Dmsg1(110, "<stored: %s", sd->msg);
1207 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
1208 Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg);
1211 Dmsg1(110, "Got Ticket=%d\n", jcr->Ticket);
1213 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to open command\n"));
1218 * Send Append data command to Storage daemon
1220 bnet_fsend(sd, append_data, jcr->Ticket);
1221 Dmsg1(110, ">stored: %s", sd->msg);
1224 * Expect to get OK data
1226 Dmsg1(110, "<stored: %s", sd->msg);
1227 if (!response(jcr, sd, OK_data, "Append Data")) {
1232 * Send Files to Storage daemon
1234 Dmsg1(110, "begin blast ff=%p\n", (FF_PKT *)jcr->ff);
1235 if (!blast_data_to_storage_daemon(jcr, NULL)) {
1236 set_jcr_job_status(jcr, JS_ErrorTerminated);
1237 bnet_suppress_error_messages(sd, 1);
1238 Dmsg0(110, "Error in blast_data.\n");
1240 set_jcr_job_status(jcr, JS_Terminated);
1241 if (jcr->JobStatus != JS_Terminated) {
1242 bnet_suppress_error_messages(sd, 1);
1243 goto cleanup; /* bail out now */
1246 * Expect to get response to append_data from Storage daemon
1248 if (!response(jcr, sd, OK_append, "Append Data")) {
1249 set_jcr_job_status(jcr, JS_ErrorTerminated);
1254 * Send Append End Data to Storage daemon
1256 bnet_fsend(sd, append_end, jcr->Ticket);
1258 if (!response(jcr, sd, OK_end, "Append End")) {
1259 set_jcr_job_status(jcr, JS_ErrorTerminated);
1264 * Send Append Close to Storage daemon
1266 bnet_fsend(sd, append_close, jcr->Ticket);
1267 while (bget_msg(sd) >= 0) { /* stop on signal or error */
1268 if (sscanf(sd->msg, OK_close, &SDJobStatus) == 1) {
1270 Dmsg2(200, "SDJobStatus = %d %c\n", SDJobStatus, (char)SDJobStatus);
1274 Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n"));
1277 if (SDJobStatus != JS_Terminated) {
1278 Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"),
1284 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1285 edit_uint64(jcr->ReadBytes, ed1),
1286 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1287 Dmsg1(110, "End FD msg: %s\n", dir->msg);
1289 return 0; /* return and stop command loop */
1293 * Do a Verify for Director
1296 static int verify_cmd(JCR *jcr)
1298 BSOCK *dir = jcr->dir_bsock;
1299 BSOCK *sd = jcr->store_bsock;
1300 char level[100], ed1[50], ed2[50];
1302 jcr->JobType = JT_VERIFY;
1303 if (sscanf(dir->msg, verifycmd, level) != 1) {
1304 bnet_fsend(dir, "2994 Bad verify command: %s\n", dir->msg);
1307 if (strcasecmp(level, "init") == 0) {
1308 jcr->JobLevel = L_VERIFY_INIT;
1309 } else if (strcasecmp(level, "catalog") == 0){
1310 jcr->JobLevel = L_VERIFY_CATALOG;
1311 } else if (strcasecmp(level, "volume") == 0){
1312 jcr->JobLevel = L_VERIFY_VOLUME_TO_CATALOG;
1313 } else if (strcasecmp(level, "data") == 0){
1314 jcr->JobLevel = L_VERIFY_DATA;
1315 } else if (strcasecmp(level, "disk_to_catalog") == 0) {
1316 jcr->JobLevel = L_VERIFY_DISK_TO_CATALOG;
1318 bnet_fsend(dir, "2994 Bad verify level: %s\n", dir->msg);
1322 bnet_fsend(dir, OKverify);
1323 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1325 switch (jcr->JobLevel) {
1327 case L_VERIFY_CATALOG:
1330 case L_VERIFY_VOLUME_TO_CATALOG:
1331 if (!open_sd_read_session(jcr)) {
1334 start_dir_heartbeat(jcr);
1335 do_verify_volume(jcr);
1336 stop_dir_heartbeat(jcr);
1338 * Send Close session command to Storage daemon
1340 bnet_fsend(sd, read_close, jcr->Ticket);
1341 Dmsg1(130, "bfiled>stored: %s", sd->msg);
1343 /* ****FIXME**** check response */
1344 bget_msg(sd); /* get OK */
1346 /* Inform Storage daemon that we are done */
1347 bnet_sig(sd, BNET_TERMINATE);
1350 case L_VERIFY_DISK_TO_CATALOG:
1354 bnet_fsend(dir, "2994 Bad verify level: %s\n", dir->msg);
1358 bnet_sig(dir, BNET_EOD);
1360 /* Send termination status back to Dir */
1361 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1362 edit_uint64(jcr->ReadBytes, ed1),
1363 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1365 /* Inform Director that we are done */
1366 bnet_sig(dir, BNET_TERMINATE);
1367 return 0; /* return and terminate command loop */
1371 * Do a Restore for Director
1374 static int restore_cmd(JCR *jcr)
1376 BSOCK *dir = jcr->dir_bsock;
1377 BSOCK *sd = jcr->store_bsock;
1381 char ed1[50], ed2[50];
1384 * Scan WHERE (base directory for restore) from command
1386 Dmsg0(150, "restore command\n");
1387 /* Pickup where string */
1388 where = get_memory(dir->msglen+1);
1391 if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, where) != 3) {
1392 if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) {
1393 pm_strcpy(&jcr->errmsg, dir->msg);
1394 Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
1399 /* Turn / into nothing */
1400 if (where[0] == '/' && where[1] == 0) {
1404 Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
1405 unbash_spaces(where);
1406 jcr->where = bstrdup(where);
1407 free_pool_memory(where);
1408 jcr->replace = replace;
1409 jcr->prefix_links = prefix_links;
1411 bnet_fsend(dir, OKrestore);
1412 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1414 jcr->JobType = JT_RESTORE;
1416 set_jcr_job_status(jcr, JS_Blocked);
1417 if (!open_sd_read_session(jcr)) {
1418 set_jcr_job_status(jcr, JS_ErrorTerminated);
1422 set_jcr_job_status(jcr, JS_Running);
1425 * Do restore of files and data
1427 start_dir_heartbeat(jcr);
1429 stop_dir_heartbeat(jcr);
1431 set_jcr_job_status(jcr, JS_Terminated);
1432 if (jcr->JobStatus != JS_Terminated) {
1433 bnet_suppress_error_messages(sd, 1);
1437 * Send Close session command to Storage daemon
1439 bnet_fsend(sd, read_close, jcr->Ticket);
1440 Dmsg1(130, "bfiled>stored: %s", sd->msg);
1442 bget_msg(sd); /* get OK */
1444 /* Inform Storage daemon that we are done */
1445 bnet_sig(sd, BNET_TERMINATE);
1450 set_jcr_job_status(jcr, JS_ErrorTerminated);
1452 /* Send termination status back to Dir */
1453 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1454 edit_uint64(jcr->ReadBytes, ed1),
1455 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1457 /* Inform Director that we are done */
1458 bnet_sig(dir, BNET_TERMINATE);
1460 Dmsg0(130, "Done in job.c\n");
1461 return 0; /* return and terminate command loop */
1464 static int open_sd_read_session(JCR *jcr)
1466 BSOCK *sd = jcr->store_bsock;
1469 Jmsg(jcr, M_FATAL, 0, _("Improper calling sequence.\n"));
1472 Dmsg4(120, "VolSessId=%ld VolsessT=%ld SF=%ld EF=%ld\n",
1473 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile);
1474 Dmsg2(120, "JobId=%d vol=%s\n", jcr->JobId, "DummyVolume");
1476 * Open Read Session with Storage daemon
1478 bnet_fsend(sd, read_open, jcr->VolumeName,
1479 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile,
1480 jcr->StartBlock, jcr->EndBlock);
1481 Dmsg1(110, ">stored: %s", sd->msg);
1486 if (bget_msg(sd) >= 0) {
1487 Dmsg1(110, "bfiled<stored: %s", sd->msg);
1488 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
1489 Jmsg(jcr, M_FATAL, 0, _("Bad response to SD read open: %s\n"), sd->msg);
1492 Dmsg1(110, "bfiled: got Ticket=%d\n", jcr->Ticket);
1494 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to read open command\n"));
1498 if (!send_bootstrap_file(jcr)) {
1503 * Start read of data with Storage daemon
1505 bnet_fsend(sd, read_data, jcr->Ticket);
1506 Dmsg1(110, ">stored: %s", sd->msg);
1511 if (!response(jcr, sd, OK_data, "Read Data")) {
1518 * Destroy the Job Control Record and associated
1519 * resources (sockets).
1521 static void filed_free_jcr(JCR *jcr)
1523 if (jcr->store_bsock) {
1524 bnet_close(jcr->store_bsock);
1526 if (jcr->RestoreBootstrap) {
1527 unlink(jcr->RestoreBootstrap);
1528 free_pool_memory(jcr->RestoreBootstrap);
1529 jcr->RestoreBootstrap = NULL;
1531 if (jcr->last_fname) {
1532 free_pool_memory(jcr->last_fname);
1534 if (jcr->RunAfterJob) {
1535 free_pool_memory(jcr->RunAfterJob);
1543 * Get response from Storage daemon to a command we
1544 * sent. Check that the response is OK.
1546 * Returns: 0 on failure
1549 int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd)
1554 if (bget_msg(sd) > 0) {
1555 Dmsg0(110, sd->msg);
1556 if (strcmp(sd->msg, resp) == 0) {
1560 if (job_canceled(jcr)) {
1561 return 0; /* if canceled avoid useless error messages */
1563 if (is_bnet_error(sd)) {
1564 Jmsg2(jcr, M_FATAL, 0, _("Comm error with SD. bad response to %s. ERR=%s\n"),
1565 cmd, bnet_strerror(sd));
1567 Jmsg3(jcr, M_FATAL, 0, _("Bad response to %s command. Wanted %s, got %s\n"),
1568 cmd, resp, sd->msg);
1573 static int send_bootstrap_file(JCR *jcr)
1577 BSOCK *sd = jcr->store_bsock;
1578 const char *bootstrap = "bootstrap\n";
1581 Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
1582 if (!jcr->RestoreBootstrap) {
1585 bs = fopen(jcr->RestoreBootstrap, "r");
1588 Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
1589 jcr->RestoreBootstrap, be.strerror());
1590 set_jcr_job_status(jcr, JS_ErrorTerminated);
1593 pm_strcpy(&sd->msg, bootstrap);
1594 sd->msglen = strlen(sd->msg);
1596 while (fgets(buf, sizeof(buf), bs)) {
1597 sd->msglen = Mmsg(sd->msg, "%s", buf);
1600 bnet_sig(sd, BNET_EOD);
1602 if (!response(jcr, sd, OKSDbootstrap, "Bootstrap")) {
1603 set_jcr_job_status(jcr, JS_ErrorTerminated);
1609 if (jcr->RestoreBootstrap) {
1610 unlink(jcr->RestoreBootstrap);
1611 free_pool_memory(jcr->RestoreBootstrap);
1612 jcr->RestoreBootstrap = NULL;