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));
253 fo->fstype.destroy();
261 incexe->opts_list.destroy();
262 incexe->name_list.destroy();
264 fileset->include_list.destroy();
266 /* Delete FileSet Exclude lists */
267 for (i=0; i<fileset->exclude_list.size(); i++) {
268 findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
269 for (j=0; j<incexe->opts_list.size(); j++) {
270 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
274 fo->fstype.destroy();
276 incexe->opts_list.destroy();
277 incexe->name_list.destroy();
279 fileset->exclude_list.destroy();
282 Dmsg0(100, "Calling term_find_files\n");
283 term_find_files((FF_PKT *)jcr->ff);
284 Dmsg0(100, "Done with term_find_files\n");
285 free_jcr(jcr); /* destroy JCR record */
286 Dmsg0(100, "Done with free_jcr\n");
291 * Hello from Director he must identify himself and provide his
294 static int hello_cmd(JCR *jcr)
296 Dmsg0(120, "Calling Authenticate\n");
297 if (!authenticate_director(jcr)) {
300 Dmsg0(120, "OK Authenticate\n");
301 jcr->authenticated = true;
308 static int cancel_cmd(JCR *jcr)
310 BSOCK *dir = jcr->dir_bsock;
311 char Job[MAX_NAME_LENGTH];
314 if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
315 if (!(cjcr=get_jcr_by_full_name(Job))) {
316 bnet_fsend(dir, "2901 Job %s not found.\n", Job);
318 if (cjcr->store_bsock) {
320 cjcr->store_bsock->timed_out = 1;
321 cjcr->store_bsock->terminated = 1;
323 * #if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
325 #if !defined(HAVE_CYGWIN)
326 pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL);
330 set_jcr_job_status(cjcr, JS_Canceled);
332 bnet_fsend(dir, _("2001 Job %s marked to be canceled.\n"), Job);
335 bnet_fsend(dir, _("2902 Error scanning cancel command.\n"));
337 bnet_sig(dir, BNET_EOD);
343 * Set debug level as requested by the Director
346 static int setdebug_cmd(JCR *jcr)
348 BSOCK *dir = jcr->dir_bsock;
349 int level, trace_flag;
351 Dmsg1(110, "setdebug_cmd: %s", dir->msg);
352 if (sscanf(dir->msg, "setdebug=%d trace=%d", &level, &trace_flag) != 2 || level < 0) {
353 pm_strcpy(jcr->errmsg, dir->msg);
354 bnet_fsend(dir, "2991 Bad setdebug command: %s\n", jcr->errmsg);
358 set_trace(trace_flag);
359 return bnet_fsend(dir, OKsetdebug, level);
363 static int estimate_cmd(JCR *jcr)
365 BSOCK *dir = jcr->dir_bsock;
368 if (sscanf(dir->msg, estimatecmd, &jcr->listing) != 1) {
369 pm_strcpy(jcr->errmsg, dir->msg);
370 Jmsg(jcr, M_FATAL, 0, _("Bad estimate command: %s"), jcr->errmsg);
371 bnet_fsend(dir, "2992 Bad estimate command.\n");
375 bnet_fsend(dir, OKest, jcr->num_files_examined,
376 edit_uint64_with_commas(jcr->JobBytes, ed2));
377 bnet_sig(dir, BNET_EOD);
382 * Get JobId and Storage Daemon Authorization key from Director
384 static int job_cmd(JCR *jcr)
386 BSOCK *dir = jcr->dir_bsock;
387 POOLMEM *sd_auth_key;
389 sd_auth_key = get_memory(dir->msglen);
390 if (sscanf(dir->msg, jobcmd, &jcr->JobId, jcr->Job,
391 &jcr->VolSessionId, &jcr->VolSessionTime,
393 pm_strcpy(jcr->errmsg, dir->msg);
394 Jmsg(jcr, M_FATAL, 0, _("Bad Job Command: %s"), jcr->errmsg);
395 bnet_fsend(dir, BADjob);
396 free_pool_memory(sd_auth_key);
399 jcr->sd_auth_key = bstrdup(sd_auth_key);
400 free_pool_memory(sd_auth_key);
401 Dmsg2(120, "JobId=%d Auth=%s\n", jcr->JobId, jcr->sd_auth_key);
402 return bnet_fsend(dir, OKjob, HOST_OS, DISTNAME, DISTVER);
405 static int runbefore_cmd(JCR *jcr)
408 BSOCK *dir = jcr->dir_bsock;
409 POOLMEM *cmd = get_memory(dir->msglen+1);
411 Dmsg1(100, "runbefore_cmd: %s", dir->msg);
412 if (sscanf(dir->msg, runbefore, cmd) != 1) {
413 pm_strcpy(jcr->errmsg, dir->msg);
414 Jmsg1(jcr, M_FATAL, 0, _("Bad RunBeforeJob command: %s\n"), jcr->errmsg);
415 bnet_fsend(dir, "2905 Bad RunBeforeJob command.\n");
421 /* Run the command now */
422 stat = run_cmd(jcr, cmd, "ClientRunBeforeJob");
425 bnet_fsend(dir, OKRunBefore);
428 bnet_fsend(dir, "2905 Bad RunBeforeJob command.\n");
433 static int runafter_cmd(JCR *jcr)
435 BSOCK *dir = jcr->dir_bsock;
436 POOLMEM *msg = get_memory(dir->msglen+1);
438 Dmsg1(100, "runafter_cmd: %s", dir->msg);
439 if (sscanf(dir->msg, runafter, msg) != 1) {
440 pm_strcpy(jcr->errmsg, dir->msg);
441 Jmsg1(jcr, M_FATAL, 0, _("Bad RunAfter command: %s\n"), jcr->errmsg);
442 bnet_fsend(dir, "2905 Bad RunAfterJob command.\n");
447 if (jcr->RunAfterJob) {
448 free_pool_memory(jcr->RunAfterJob);
450 jcr->RunAfterJob = get_pool_memory(PM_FNAME);
451 pm_strcpy(jcr->RunAfterJob, msg);
452 free_pool_memory(msg);
453 return bnet_fsend(dir, OKRunAfter);
456 static int run_cmd(JCR *jcr, char *cmd, const char *name)
458 POOLMEM *ecmd = get_pool_memory(PM_FNAME);
461 char line[MAXSTRING];
463 ecmd = edit_job_codes(jcr, ecmd, cmd, "");
464 bpipe = open_bpipe(ecmd, 0, "r");
465 free_pool_memory(ecmd);
468 Jmsg(jcr, M_FATAL, 0, _("%s could not execute. ERR=%s\n"), name,
472 while (fgets(line, sizeof(line), bpipe->rfd)) {
473 int len = strlen(line);
474 if (len > 0 && line[len-1] != '\n') {
475 bstrncat(line, "\n", sizeof(line));
477 Jmsg(jcr, M_INFO, 0, _("%s: %s"), name, line);
479 status = close_bpipe(bpipe);
482 Jmsg(jcr, M_FATAL, 0, _("%s returned non-zero status=%d. ERR=%s\n"), name,
483 status, be.strerror(status));
493 static void add_fname_to_list(JCR *jcr, char *fname, int list)
503 /* Skip leading options -- currently ignored */
504 for (p=fname; *p && *p != ' '; p++)
506 /* Skip spaces, and q points to first space */
507 for (q=NULL; *p && *p == ' '; p++) {
515 p++; /* skip over | */
516 fn = get_pool_memory(PM_FNAME);
517 fn = edit_job_codes(jcr, fn, p, "");
518 bpipe = open_bpipe(fn, 0, "r");
519 free_pool_memory(fn);
521 Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
525 /* Copy File options */
526 if (list == INC_LIST) {
527 *q = 0; /* terminate options */
530 optlen = strlen(buf);
534 while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) {
535 strip_trailing_junk(buf);
536 if (list == INC_LIST) {
537 add_fname_to_include_list((FF_PKT *)jcr->ff, 1, buf);
539 add_fname_to_exclude_list((FF_PKT *)jcr->ff, buf);
542 if ((stat=close_bpipe(bpipe)) != 0) {
543 Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
544 p, stat, strerror(errno));
549 p++; /* skip over < */
550 if ((ffd = fopen(p, "r")) == NULL) {
552 Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
553 list==INC_LIST?"included":"excluded", p, be.strerror());
556 /* Copy File options */
557 if (list == INC_LIST) {
558 *q = 0; /* terminate options */
561 optlen = strlen(buf);
565 while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) {
566 strip_trailing_junk(buf);
567 if (list == INC_LIST) {
568 add_fname_to_include_list((FF_PKT *)jcr->ff, 1, buf);
570 add_fname_to_exclude_list((FF_PKT *)jcr->ff, buf);
576 if (list == INC_LIST) {
577 add_fname_to_include_list((FF_PKT *)jcr->ff, 1, fname);
579 add_fname_to_exclude_list((FF_PKT *)jcr->ff, p);
587 * Get list of files/directories to include from Director
590 static int include_cmd(JCR *jcr)
592 BSOCK *dir = jcr->dir_bsock;
594 while (bnet_recv(dir) >= 0) {
595 dir->msg[dir->msglen] = 0;
596 strip_trailing_junk(dir->msg);
597 Dmsg1(010, "include file: %s\n", dir->msg);
598 add_fname_to_list(jcr, dir->msg, INC_LIST);
601 return bnet_fsend(dir, OKinc);
604 static bool init_fileset(JCR *jcr)
607 findFILESET *fileset;
612 ff = (FF_PKT *)jcr->ff;
616 fileset = (findFILESET *)malloc(sizeof(findFILESET));
617 memset(fileset, 0, sizeof(findFILESET));
618 ff->fileset = fileset;
619 fileset->state = state_none;
620 fileset->include_list.init(1, true);
621 fileset->exclude_list.init(1, true);
625 static findFOPTS *start_options(FF_PKT *ff)
627 int state = ff->fileset->state;
628 findINCEXE *incexe = ff->fileset->incexe;
630 if (state != state_options) {
631 ff->fileset->state = state_options;
632 findFOPTS *fo = (findFOPTS *)malloc(sizeof(findFOPTS));
633 memset(fo, 0, sizeof(findFOPTS));
634 fo->regex.init(1, true);
635 fo->wild.init(1, true);
636 fo->base.init(1, true);
637 fo->fstype.init(1, true);
638 incexe->current_opts = fo;
639 incexe->opts_list.append(fo);
641 return incexe->current_opts;
646 * Add fname to include/exclude fileset list. First check for
647 * | and < and if necessary perform command.
649 static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *fileset)
661 p++; /* skip over | */
662 fn = get_pool_memory(PM_FNAME);
663 fn = edit_job_codes(jcr, fn, p, "");
664 bpipe = open_bpipe(fn, 0, "r");
665 free_pool_memory(fn);
667 Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
671 while (fgets(buf, sizeof(buf), bpipe->rfd)) {
672 strip_trailing_junk(buf);
673 fileset->incexe->name_list.append(bstrdup(buf));
675 if ((stat=close_bpipe(bpipe)) != 0) {
676 Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
677 p, stat, strerror(errno));
682 p++; /* skip over < */
683 if ((ffd = fopen(p, "r")) == NULL) {
685 Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"),
689 while (fgets(buf, sizeof(buf), ffd)) {
690 strip_trailing_junk(buf);
691 fileset->incexe->name_list.append(bstrdup(buf));
696 fileset->incexe->name_list.append(bstrdup(fname));
702 static void add_fileset(JCR *jcr, const char *item)
704 FF_PKT *ff = (FF_PKT *)jcr->ff;
705 findFILESET *fileset = ff->fileset;
706 int state = fileset->state;
707 findFOPTS *current_opts;
709 Dmsg1(100, "%s\n", item);
711 if (item[1] == ' ') { /* If string follows */
712 item += 2; /* point to string */
715 if (state == state_error) {
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->include_list.append(fileset->incexe);
729 fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
730 memset(fileset->incexe, 0, sizeof(findINCEXE));
731 fileset->incexe->opts_list.init(1, true);
732 fileset->incexe->name_list.init(1, true);
733 fileset->exclude_list.append(fileset->incexe);
739 /* File item to either include/include list */
740 state = state_include;
741 add_file_to_fileset(jcr, item, fileset);
744 current_opts = start_options(ff);
748 preg = (regex_t *)malloc(sizeof(regex_t));
749 if (current_opts->flags & FO_IGNORECASE) {
750 rc = regcomp(preg, item, REG_EXTENDED|REG_ICASE);
752 rc = regcomp(preg, item, REG_EXTENDED);
755 regerror(rc, preg, prbuf, sizeof(prbuf));
758 Jmsg(jcr, M_FATAL, 0, "REGEX %s compile error. ERR=%s\n", item, prbuf);
762 current_opts->regex.append(preg);
763 state = state_options;
766 current_opts = start_options(ff);
767 current_opts->base.append(bstrdup(item));
768 state = state_options;
771 current_opts = start_options(ff);
772 current_opts->fstype.append(bstrdup(item));
773 state = state_options;
776 current_opts = start_options(ff);
777 current_opts->wild.append(bstrdup(item));
778 state = state_options;
781 current_opts = start_options(ff);
782 set_options(current_opts, item);
783 state = state_options;
786 current_opts = start_options(ff);
787 current_opts->reader = bstrdup(item);
788 state = state_options;
791 current_opts = start_options(ff);
792 current_opts->writer = bstrdup(item);
793 state = state_options;
796 Jmsg(jcr, M_FATAL, 0, "Invalid FileSet command: %s\n", item);
800 ff->fileset->state = state;
803 static bool term_fileset(JCR *jcr)
805 FF_PKT *ff = (FF_PKT *)jcr->ff;
806 findFILESET *fileset = ff->fileset;
809 for (i=0; i<fileset->include_list.size(); i++) {
810 findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
812 for (j=0; j<incexe->opts_list.size(); j++) {
813 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
814 for (k=0; k<fo->regex.size(); k++) {
815 Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
817 for (k=0; k<fo->wild.size(); k++) {
818 Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
820 for (k=0; k<fo->base.size(); k++) {
821 Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
823 for (k=0; k<fo->fstype.size(); k++) {
824 Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
827 Dmsg1(400, "D %s\n", fo->reader);
830 Dmsg1(400, "T %s\n", fo->writer);
833 for (j=0; j<incexe->name_list.size(); j++) {
834 Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
837 for (i=0; i<fileset->exclude_list.size(); i++) {
838 findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
840 for (j=0; j<incexe->opts_list.size(); j++) {
841 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
842 for (k=0; k<fo->regex.size(); k++) {
843 Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
845 for (k=0; k<fo->wild.size(); k++) {
846 Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
848 for (k=0; k<fo->base.size(); k++) {
849 Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
851 for (k=0; k<fo->fstype.size(); k++) {
852 Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
855 for (j=0; j<incexe->name_list.size(); j++) {
856 Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
859 return ff->fileset->state != state_error;
864 * As an optimization, we should do this during
865 * "compile" time in filed/job.c, and keep only a bit mask
866 * and the Verify options.
868 static void set_options(findFOPTS *fo, const char *opts)
873 for (p=opts; *p; p++) {
875 case 'a': /* alway replace */
876 case '0': /* no option */
879 fo->flags |= FO_EXCLUDE;
882 fo->flags |= FO_MULTIFS;
884 case 'h': /* no recursion */
885 fo->flags |= FO_NO_RECURSION;
887 case 'H': /* no hard link handling */
888 fo->flags |= FO_NO_HARDLINK;
891 fo->flags |= FO_IGNORECASE;
897 fo->flags |= FO_NOREPLACE;
899 case 'p': /* use portable data format */
900 fo->flags |= FO_PORTABLE;
902 case 'R': /* Resource forks and Finder Info */
903 fo->flags |= FO_HFSPLUS;
904 case 'r': /* read fifo */
905 fo->flags |= FO_READFIFO;
908 fo->flags |= FO_SHA1;
911 fo->flags |= FO_SPARSE;
914 fo->flags |= FO_MTIMEONLY;
917 fo->flags |= FO_KEEPATIME;
922 case 'V': /* verify options */
923 /* Copy Verify Options */
924 for (j=0; *p && *p != ':'; p++) {
925 fo->VerifyOpts[j] = *p;
926 if (j < (int)sizeof(fo->VerifyOpts) - 1) {
930 fo->VerifyOpts[j] = 0;
933 fo->flags |= FO_IF_NEWER;
935 case 'Z': /* gzip compression */
936 fo->flags |= FO_GZIP;
937 fo->GZIP_level = *++p - '0';
938 Dmsg1(200, "Compression level=%d\n", fo->GZIP_level);
941 Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *p);
949 * Director is passing his Fileset
951 static int fileset_cmd(JCR *jcr)
953 BSOCK *dir = jcr->dir_bsock;
955 if (!init_fileset(jcr)) {
958 while (bnet_recv(dir) >= 0) {
959 strip_trailing_junk(dir->msg);
960 Dmsg1(400, "Fileset: %s\n", dir->msg);
961 add_fileset(jcr, dir->msg);
963 if (!term_fileset(jcr)) {
966 return bnet_fsend(dir, OKinc);
971 * Get list of files to exclude from Director
974 static int exclude_cmd(JCR *jcr)
976 BSOCK *dir = jcr->dir_bsock;
978 while (bnet_recv(dir) >= 0) {
979 dir->msg[dir->msglen] = 0;
980 strip_trailing_junk(dir->msg);
981 add_fname_to_list(jcr, dir->msg, EXC_LIST);
982 Dmsg1(110, "<dird: exclude file %s\n", dir->msg);
985 return bnet_fsend(dir, OKexc);
989 static int bootstrap_cmd(JCR *jcr)
991 BSOCK *dir = jcr->dir_bsock;
992 POOLMEM *fname = get_pool_memory(PM_FNAME);
995 if (jcr->RestoreBootstrap) {
996 unlink(jcr->RestoreBootstrap);
997 free_pool_memory(jcr->RestoreBootstrap);
999 Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
1001 Dmsg1(400, "bootstrap=%s\n", fname);
1002 jcr->RestoreBootstrap = fname;
1003 bs = fopen(fname, "a+"); /* create file */
1007 * Suck up what he is sending to us so that he will then
1008 * read our error message.
1010 while (bnet_recv(dir) >= 0)
1013 Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"),
1014 jcr->RestoreBootstrap, be.strerror());
1015 free_pool_memory(jcr->RestoreBootstrap);
1016 jcr->RestoreBootstrap = NULL;
1017 set_jcr_job_status(jcr, JS_ErrorTerminated);
1021 while (bnet_recv(dir) >= 0) {
1022 Dmsg1(200, "filed<dird: bootstrap file %s\n", dir->msg);
1023 fputs(dir->msg, bs);
1027 return bnet_fsend(dir, OKbootstrap);
1032 * Get backup level from Director
1035 static int level_cmd(JCR *jcr)
1037 BSOCK *dir = jcr->dir_bsock;
1038 POOLMEM *level, *buf = NULL;
1043 level = get_memory(dir->msglen+1);
1044 Dmsg1(110, "level_cmd: %s", dir->msg);
1045 if (sscanf(dir->msg, "level = %s ", level) != 1) {
1048 /* Base backup requested? */
1049 if (strcmp(level, "base") == 0) {
1050 jcr->JobLevel = L_BASE;
1051 /* Full backup requested? */
1052 } else if (strcmp(level, "full") == 0) {
1053 jcr->JobLevel = L_FULL;
1055 * Backup requested since <date> <time>
1056 * This form is also used for incremental and differential
1057 * This code is deprecated. See since_utime for new code.
1059 } else if (strcmp(level, "since") == 0) {
1060 jcr->JobLevel = L_SINCE;
1061 if (sscanf(dir->msg, "level = since %d-%d-%d %d:%d:%d mtime_only=%d",
1062 &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
1063 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &mtime_only) != 7) {
1068 tm.tm_wday = tm.tm_yday = 0;
1070 mtime = mktime(&tm);
1071 Dmsg2(100, "Got since time: %s mtime_only=%d\n", ctime(&mtime), mtime_only);
1072 jcr->incremental = 1; /* set incremental or decremental backup */
1073 jcr->mtime = mtime; /* set since time */
1075 * We get his UTC since time, then sync the clocks and correct it
1076 * to agree with our clock.
1078 } else if (strcmp(level, "since_utime") == 0) {
1079 buf = get_memory(dir->msglen+1);
1080 utime_t since_time, adj;
1081 btime_t his_time, bt_start, rt=0, bt_adj=0;
1082 jcr->JobLevel = L_SINCE;
1083 if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
1084 buf, &mtime_only) != 2) {
1087 since_time = str_to_uint64(buf); /* this is the since time */
1088 char ed1[50], ed2[50];
1090 * Sync clocks by polling him for the time. We take
1091 * 10 samples of his time throwing out the first two.
1093 for (int i=0; i<10; i++) {
1094 bt_start = get_current_btime();
1095 bnet_sig(dir, BNET_BTIME); /* poll for time */
1096 if (bnet_recv(dir) <= 0) { /* get response */
1099 if (sscanf(dir->msg, "btime %s", buf) != 1) {
1102 if (i < 2) { /* toss first two results */
1105 his_time = str_to_uint64(buf);
1106 rt = get_current_btime() - bt_start; /* compute round trip time */
1107 bt_adj -= his_time - bt_start - rt/2;
1108 Dmsg2(200, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
1111 bt_adj = bt_adj / 8; /* compute average time */
1112 Dmsg2(100, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
1113 adj = btime_to_utime(bt_adj);
1114 since_time += adj; /* adjust for clock difference */
1116 Jmsg(jcr, M_INFO, 0, _("Since time adjusted by %d seconds.\n"), adj);
1118 bnet_sig(dir, BNET_EOD);
1120 Dmsg2(100, "adj = %d since_time=%d\n", (int)adj, (int)since_time);
1121 jcr->incremental = 1; /* set incremental or decremental backup */
1122 jcr->mtime = (time_t)since_time; /* set since time */
1124 Jmsg1(jcr, M_FATAL, 0, "Unknown backup level: %s\n", level);
1132 return bnet_fsend(dir, OKlevel);
1135 pm_strcpy(jcr->errmsg, dir->msg);
1136 Jmsg1(jcr, M_FATAL, 0, _("Bad level command: %s\n"), jcr->errmsg);
1145 * Get session parameters from Director -- this is for a Restore command
1147 static int session_cmd(JCR *jcr)
1149 BSOCK *dir = jcr->dir_bsock;
1151 Dmsg1(100, "SessionCmd: %s", dir->msg);
1152 if (sscanf(dir->msg, sessioncmd, jcr->VolumeName,
1153 &jcr->VolSessionId, &jcr->VolSessionTime,
1154 &jcr->StartFile, &jcr->EndFile,
1155 &jcr->StartBlock, &jcr->EndBlock) != 7) {
1156 pm_strcpy(jcr->errmsg, dir->msg);
1157 Jmsg(jcr, M_FATAL, 0, "Bad session command: %s", jcr->errmsg);
1161 return bnet_fsend(dir, OKsession);
1165 * Get address of storage daemon from Director
1168 static int storage_cmd(JCR *jcr)
1170 int stored_port; /* storage daemon port */
1171 int enable_ssl; /* enable ssl to sd */
1172 BSOCK *dir = jcr->dir_bsock;
1173 BSOCK *sd; /* storage daemon bsock */
1175 Dmsg1(100, "StorageCmd: %s", dir->msg);
1176 if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port, &enable_ssl) != 3) {
1177 pm_strcpy(jcr->errmsg, dir->msg);
1178 Jmsg(jcr, M_FATAL, 0, _("Bad storage command: %s"), jcr->errmsg);
1181 Dmsg3(110, "Open storage: %s:%d ssl=%d\n", jcr->stored_addr, stored_port, enable_ssl);
1182 /* Open command communications with Storage daemon */
1183 /* Try to connect for 1 hour at 10 second intervals */
1184 sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"),
1185 jcr->stored_addr, NULL, stored_port, 1);
1187 Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
1188 jcr->stored_addr, stored_port);
1189 Dmsg2(100, "Failed to connect to Storage daemon: %s:%d\n",
1190 jcr->stored_addr, stored_port);
1193 Dmsg0(110, "Connection OK to SD.\n");
1195 jcr->store_bsock = sd;
1197 bnet_fsend(sd, "Hello Start Job %s\n", jcr->Job);
1198 if (!authenticate_storagedaemon(jcr)) {
1199 Jmsg(jcr, M_FATAL, 0, _("Failed to authenticate Storage daemon.\n"));
1202 Dmsg0(110, "Authenticated with SD.\n");
1204 /* Send OK to Director */
1205 return bnet_fsend(dir, OKstore);
1210 * Do a backup. For now, we handle only Full and Incremental.
1212 static int backup_cmd(JCR *jcr)
1214 BSOCK *dir = jcr->dir_bsock;
1215 BSOCK *sd = jcr->store_bsock;
1218 char ed1[50], ed2[50];
1220 set_jcr_job_status(jcr, JS_Blocked);
1221 jcr->JobType = JT_BACKUP;
1222 Dmsg1(100, "begin backup ff=%p\n", (FF_PKT *)jcr->ff);
1225 Jmsg(jcr, M_FATAL, 0, _("Cannot contact Storage daemon\n"));
1229 bnet_fsend(dir, OKbackup);
1230 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1233 * Send Append Open Session to Storage daemon
1235 bnet_fsend(sd, append_open);
1236 Dmsg1(110, ">stored: %s", sd->msg);
1238 * Expect to receive back the Ticket number
1240 if (bget_msg(sd) >= 0) {
1241 Dmsg1(110, "<stored: %s", sd->msg);
1242 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
1243 Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg);
1246 Dmsg1(110, "Got Ticket=%d\n", jcr->Ticket);
1248 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to open command\n"));
1253 * Send Append data command to Storage daemon
1255 bnet_fsend(sd, append_data, jcr->Ticket);
1256 Dmsg1(110, ">stored: %s", sd->msg);
1259 * Expect to get OK data
1261 Dmsg1(110, "<stored: %s", sd->msg);
1262 if (!response(jcr, sd, OK_data, "Append Data")) {
1267 * Send Files to Storage daemon
1269 Dmsg1(110, "begin blast ff=%p\n", (FF_PKT *)jcr->ff);
1270 if (!blast_data_to_storage_daemon(jcr, NULL)) {
1271 set_jcr_job_status(jcr, JS_ErrorTerminated);
1272 bnet_suppress_error_messages(sd, 1);
1273 Dmsg0(110, "Error in blast_data.\n");
1275 set_jcr_job_status(jcr, JS_Terminated);
1276 if (jcr->JobStatus != JS_Terminated) {
1277 bnet_suppress_error_messages(sd, 1);
1278 goto cleanup; /* bail out now */
1281 * Expect to get response to append_data from Storage daemon
1283 if (!response(jcr, sd, OK_append, "Append Data")) {
1284 set_jcr_job_status(jcr, JS_ErrorTerminated);
1289 * Send Append End Data to Storage daemon
1291 bnet_fsend(sd, append_end, jcr->Ticket);
1293 if (!response(jcr, sd, OK_end, "Append End")) {
1294 set_jcr_job_status(jcr, JS_ErrorTerminated);
1299 * Send Append Close to Storage daemon
1301 bnet_fsend(sd, append_close, jcr->Ticket);
1302 while (bget_msg(sd) >= 0) { /* stop on signal or error */
1303 if (sscanf(sd->msg, OK_close, &SDJobStatus) == 1) {
1305 Dmsg2(200, "SDJobStatus = %d %c\n", SDJobStatus, (char)SDJobStatus);
1309 Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n"));
1312 if (SDJobStatus != JS_Terminated) {
1313 Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"),
1319 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1320 edit_uint64(jcr->ReadBytes, ed1),
1321 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1322 Dmsg1(110, "End FD msg: %s\n", dir->msg);
1324 return 0; /* return and stop command loop */
1328 * Do a Verify for Director
1331 static int verify_cmd(JCR *jcr)
1333 BSOCK *dir = jcr->dir_bsock;
1334 BSOCK *sd = jcr->store_bsock;
1335 char level[100], ed1[50], ed2[50];
1337 jcr->JobType = JT_VERIFY;
1338 if (sscanf(dir->msg, verifycmd, level) != 1) {
1339 bnet_fsend(dir, "2994 Bad verify command: %s\n", dir->msg);
1342 if (strcasecmp(level, "init") == 0) {
1343 jcr->JobLevel = L_VERIFY_INIT;
1344 } else if (strcasecmp(level, "catalog") == 0){
1345 jcr->JobLevel = L_VERIFY_CATALOG;
1346 } else if (strcasecmp(level, "volume") == 0){
1347 jcr->JobLevel = L_VERIFY_VOLUME_TO_CATALOG;
1348 } else if (strcasecmp(level, "data") == 0){
1349 jcr->JobLevel = L_VERIFY_DATA;
1350 } else if (strcasecmp(level, "disk_to_catalog") == 0) {
1351 jcr->JobLevel = L_VERIFY_DISK_TO_CATALOG;
1353 bnet_fsend(dir, "2994 Bad verify level: %s\n", dir->msg);
1357 bnet_fsend(dir, OKverify);
1358 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1360 switch (jcr->JobLevel) {
1362 case L_VERIFY_CATALOG:
1365 case L_VERIFY_VOLUME_TO_CATALOG:
1366 if (!open_sd_read_session(jcr)) {
1369 start_dir_heartbeat(jcr);
1370 do_verify_volume(jcr);
1371 stop_dir_heartbeat(jcr);
1373 * Send Close session command to Storage daemon
1375 bnet_fsend(sd, read_close, jcr->Ticket);
1376 Dmsg1(130, "bfiled>stored: %s", sd->msg);
1378 /* ****FIXME**** check response */
1379 bget_msg(sd); /* get OK */
1381 /* Inform Storage daemon that we are done */
1382 bnet_sig(sd, BNET_TERMINATE);
1385 case L_VERIFY_DISK_TO_CATALOG:
1389 bnet_fsend(dir, "2994 Bad verify level: %s\n", dir->msg);
1393 bnet_sig(dir, BNET_EOD);
1395 /* Send termination status back to Dir */
1396 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1397 edit_uint64(jcr->ReadBytes, ed1),
1398 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1400 /* Inform Director that we are done */
1401 bnet_sig(dir, BNET_TERMINATE);
1402 return 0; /* return and terminate command loop */
1406 * Do a Restore for Director
1409 static int restore_cmd(JCR *jcr)
1411 BSOCK *dir = jcr->dir_bsock;
1412 BSOCK *sd = jcr->store_bsock;
1416 char ed1[50], ed2[50];
1419 * Scan WHERE (base directory for restore) from command
1421 Dmsg0(150, "restore command\n");
1422 /* Pickup where string */
1423 where = get_memory(dir->msglen+1);
1426 if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, where) != 3) {
1427 if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) {
1428 pm_strcpy(jcr->errmsg, dir->msg);
1429 Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
1434 /* Turn / into nothing */
1435 if (where[0] == '/' && where[1] == 0) {
1439 Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
1440 unbash_spaces(where);
1441 jcr->where = bstrdup(where);
1442 free_pool_memory(where);
1443 jcr->replace = replace;
1444 jcr->prefix_links = prefix_links;
1446 bnet_fsend(dir, OKrestore);
1447 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1449 jcr->JobType = JT_RESTORE;
1451 set_jcr_job_status(jcr, JS_Blocked);
1452 if (!open_sd_read_session(jcr)) {
1453 set_jcr_job_status(jcr, JS_ErrorTerminated);
1457 set_jcr_job_status(jcr, JS_Running);
1460 * Do restore of files and data
1462 start_dir_heartbeat(jcr);
1464 stop_dir_heartbeat(jcr);
1466 set_jcr_job_status(jcr, JS_Terminated);
1467 if (jcr->JobStatus != JS_Terminated) {
1468 bnet_suppress_error_messages(sd, 1);
1472 * Send Close session command to Storage daemon
1474 bnet_fsend(sd, read_close, jcr->Ticket);
1475 Dmsg1(130, "bfiled>stored: %s", sd->msg);
1477 bget_msg(sd); /* get OK */
1479 /* Inform Storage daemon that we are done */
1480 bnet_sig(sd, BNET_TERMINATE);
1485 set_jcr_job_status(jcr, JS_ErrorTerminated);
1487 /* Send termination status back to Dir */
1488 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1489 edit_uint64(jcr->ReadBytes, ed1),
1490 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1492 /* Inform Director that we are done */
1493 bnet_sig(dir, BNET_TERMINATE);
1495 Dmsg0(130, "Done in job.c\n");
1496 return 0; /* return and terminate command loop */
1499 static int open_sd_read_session(JCR *jcr)
1501 BSOCK *sd = jcr->store_bsock;
1504 Jmsg(jcr, M_FATAL, 0, _("Improper calling sequence.\n"));
1507 Dmsg4(120, "VolSessId=%ld VolsessT=%ld SF=%ld EF=%ld\n",
1508 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile);
1509 Dmsg2(120, "JobId=%d vol=%s\n", jcr->JobId, "DummyVolume");
1511 * Open Read Session with Storage daemon
1513 bnet_fsend(sd, read_open, jcr->VolumeName,
1514 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile,
1515 jcr->StartBlock, jcr->EndBlock);
1516 Dmsg1(110, ">stored: %s", sd->msg);
1521 if (bget_msg(sd) >= 0) {
1522 Dmsg1(110, "bfiled<stored: %s", sd->msg);
1523 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
1524 Jmsg(jcr, M_FATAL, 0, _("Bad response to SD read open: %s\n"), sd->msg);
1527 Dmsg1(110, "bfiled: got Ticket=%d\n", jcr->Ticket);
1529 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to read open command\n"));
1533 if (!send_bootstrap_file(jcr)) {
1538 * Start read of data with Storage daemon
1540 bnet_fsend(sd, read_data, jcr->Ticket);
1541 Dmsg1(110, ">stored: %s", sd->msg);
1546 if (!response(jcr, sd, OK_data, "Read Data")) {
1553 * Destroy the Job Control Record and associated
1554 * resources (sockets).
1556 static void filed_free_jcr(JCR *jcr)
1558 if (jcr->store_bsock) {
1559 bnet_close(jcr->store_bsock);
1561 if (jcr->RestoreBootstrap) {
1562 unlink(jcr->RestoreBootstrap);
1563 free_pool_memory(jcr->RestoreBootstrap);
1564 jcr->RestoreBootstrap = NULL;
1566 if (jcr->last_fname) {
1567 free_pool_memory(jcr->last_fname);
1569 if (jcr->RunAfterJob) {
1570 free_pool_memory(jcr->RunAfterJob);
1578 * Get response from Storage daemon to a command we
1579 * sent. Check that the response is OK.
1581 * Returns: 0 on failure
1584 int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd)
1589 if (bget_msg(sd) > 0) {
1590 Dmsg0(110, sd->msg);
1591 if (strcmp(sd->msg, resp) == 0) {
1595 if (job_canceled(jcr)) {
1596 return 0; /* if canceled avoid useless error messages */
1598 if (is_bnet_error(sd)) {
1599 Jmsg2(jcr, M_FATAL, 0, _("Comm error with SD. bad response to %s. ERR=%s\n"),
1600 cmd, bnet_strerror(sd));
1602 Jmsg3(jcr, M_FATAL, 0, _("Bad response to %s command. Wanted %s, got %s\n"),
1603 cmd, resp, sd->msg);
1608 static int send_bootstrap_file(JCR *jcr)
1612 BSOCK *sd = jcr->store_bsock;
1613 const char *bootstrap = "bootstrap\n";
1616 Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
1617 if (!jcr->RestoreBootstrap) {
1620 bs = fopen(jcr->RestoreBootstrap, "r");
1623 Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
1624 jcr->RestoreBootstrap, be.strerror());
1625 set_jcr_job_status(jcr, JS_ErrorTerminated);
1628 sd->msglen = pm_strcpy(sd->msg, bootstrap);
1630 while (fgets(buf, sizeof(buf), bs)) {
1631 sd->msglen = Mmsg(sd->msg, "%s", buf);
1634 bnet_sig(sd, BNET_EOD);
1636 if (!response(jcr, sd, OKSDbootstrap, "Bootstrap")) {
1637 set_jcr_job_status(jcr, JS_ErrorTerminated);
1643 if (jcr->RestoreBootstrap) {
1644 unlink(jcr->RestoreBootstrap);
1645 free_pool_memory(jcr->RestoreBootstrap);
1646 jcr->RestoreBootstrap = NULL;