2 * Bacula File Daemon Job processing
4 * Kern Sibbald, October MM
10 Copyright (C) 2000-2005 Kern Sibbald
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 version 2 as amended with additional clauses defined in the
15 file LICENSE in the main source directory.
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
20 the file LICENSE for additional details.
28 static pthread_mutex_t vss_mutex = PTHREAD_MUTEX_INITIALIZER;
31 extern char my_name[];
32 extern CLIENT *me; /* our client resource */
34 int enable_vss = 0; /* set to use vss */
36 /* Imported functions */
37 extern int status_cmd(JCR *jcr);
38 extern int qstatus_cmd(JCR *jcr);
40 /* Forward referenced functions */
41 static int backup_cmd(JCR *jcr);
42 static int bootstrap_cmd(JCR *jcr);
43 static int cancel_cmd(JCR *jcr);
44 static int setdebug_cmd(JCR *jcr);
45 static int estimate_cmd(JCR *jcr);
46 static int hello_cmd(JCR *jcr);
47 static int job_cmd(JCR *jcr);
48 static int fileset_cmd(JCR *jcr);
49 static int level_cmd(JCR *jcr);
50 static int verify_cmd(JCR *jcr);
51 static int restore_cmd(JCR *jcr);
52 static int storage_cmd(JCR *jcr);
53 static int session_cmd(JCR *jcr);
54 static int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd);
55 static void filed_free_jcr(JCR *jcr);
56 static int open_sd_read_session(JCR *jcr);
57 static int send_bootstrap_file(JCR *jcr);
58 static int runbefore_cmd(JCR *jcr);
59 static int runafter_cmd(JCR *jcr);
60 static bool run_cmd(JCR *jcr, char *cmd, const char *name);
61 static void set_options(findFOPTS *fo, const char *opts);
64 /* Exported functions */
69 int monitoraccess; /* specify if monitors have access to this function */
73 * The following are the recognized commands from the Director.
75 static struct s_cmds cmds[] = {
76 {"backup", backup_cmd, 0},
77 {"cancel", cancel_cmd, 0},
78 {"setdebug=", setdebug_cmd, 0},
79 {"estimate", estimate_cmd, 0},
80 {"Hello", hello_cmd, 1},
81 {"fileset", fileset_cmd, 0},
82 {"JobId=", job_cmd, 0},
83 {"level = ", level_cmd, 0},
84 {"restore", restore_cmd, 0},
85 {"session", session_cmd, 0},
86 {"status", status_cmd, 1},
87 {".status", qstatus_cmd, 1},
88 {"storage ", storage_cmd, 0},
89 {"verify", verify_cmd, 0},
90 {"bootstrap", bootstrap_cmd, 0},
91 {"RunBeforeJob", runbefore_cmd, 0},
92 {"RunAfterJob", runafter_cmd, 0},
93 {NULL, NULL} /* list terminator */
96 /* Commands received from director that need scanning */
97 static char jobcmd[] = "JobId=%d Job=%127s SDid=%d SDtime=%d Authorization=%100s";
98 static char storaddr[] = "storage address=%s port=%d ssl=%d\n";
99 static char sessioncmd[] = "session %127s %ld %ld %ld %ld %ld %ld\n";
100 static char restorecmd[] = "restore replace=%c prelinks=%d where=%s\n";
101 static char restorecmd1[] = "restore replace=%c prelinks=%d where=\n";
102 static char verifycmd[] = "verify level=%30s\n";
103 static char estimatecmd[] = "estimate listing=%d\n";
104 static char runbefore[] = "RunBeforeJob %s\n";
105 static char runafter[] = "RunAfterJob %s\n";
107 /* Responses sent to Director */
108 static char errmsg[] = "2999 Invalid command\n";
109 static char no_auth[] = "2998 No Authorization\n";
110 static char illegal_cmd[] = "2997 Illegal command for a Director with Monitor directive enabled\n";
111 static char OKinc[] = "2000 OK include\n";
112 static char OKest[] = "2000 OK estimate files=%u bytes=%s\n";
113 static char OKlevel[] = "2000 OK level\n";
114 static char OKbackup[] = "2000 OK backup\n";
115 static char OKbootstrap[] = "2000 OK bootstrap\n";
116 static char OKverify[] = "2000 OK verify\n";
117 static char OKrestore[] = "2000 OK restore\n";
118 static char OKsession[] = "2000 OK session\n";
119 static char OKstore[] = "2000 OK storage\n";
120 static char OKjob[] = "2000 OK Job %s,%s,%s";
121 static char OKsetdebug[] = "2000 OK setdebug=%d\n";
122 static char BADjob[] = "2901 Bad Job\n";
123 static char EndJob[] = "2800 End Job TermCode=%d JobFiles=%u ReadBytes=%s JobBytes=%s Errors=%u\n";
124 static char OKRunBefore[] = "2000 OK RunBefore\n";
125 static char OKRunAfter[] = "2000 OK RunAfter\n";
127 /* Responses received from Storage Daemon */
128 static char OK_end[] = "3000 OK end\n";
129 static char OK_close[] = "3000 OK close Status = %d\n";
130 static char OK_open[] = "3000 OK open ticket = %d\n";
131 static char OK_data[] = "3000 OK data\n";
132 static char OK_append[] = "3000 OK append data\n";
133 static char OKSDbootstrap[] = "3000 OK bootstrap\n";
136 /* Commands sent to Storage Daemon */
137 static char append_open[] = "append open session\n";
138 static char append_data[] = "append data %d\n";
139 static char append_end[] = "append end session %d\n";
140 static char append_close[] = "append close session %d\n";
141 static char read_open[] = "read open session = %s %ld %ld %ld %ld %ld %ld\n";
142 static char read_data[] = "read data %d\n";
143 static char read_close[] = "read close session %d\n";
146 * Accept requests from a Director
148 * NOTE! We are running as a separate thread
150 * Send output one line
151 * at a time followed by a zero length transmission.
153 * Return when the connection is terminated or there
156 * Basic task here is:
157 * Authenticate Director (during Hello command).
158 * Accept commands one at a time from the Director
162 void *handle_client_request(void *dirp)
167 BSOCK *dir = (BSOCK *)dirp;
169 jcr = new_jcr(sizeof(JCR), filed_free_jcr); /* create JCR */
170 jcr->dir_bsock = dir;
171 jcr->ff = init_find_files();
172 jcr->start_time = time(NULL);
173 jcr->last_fname = get_pool_memory(PM_FNAME);
174 jcr->last_fname[0] = 0;
175 jcr->client_name = get_memory(strlen(my_name) + 1);
176 pm_strcpy(jcr->client_name, my_name);
178 enable_backup_privileges(NULL, 1 /* ignore_errors */);
180 /**********FIXME******* add command handler error code */
182 for (quit=false; !quit;) {
185 if (bnet_recv(dir) < 0) {
186 break; /* connection terminated */
188 dir->msg[dir->msglen] = 0;
189 Dmsg1(100, "<dird: %s", dir->msg);
191 for (i=0; cmds[i].cmd; i++) {
192 if (strncmp(cmds[i].cmd, dir->msg, strlen(cmds[i].cmd)) == 0) {
193 found = true; /* indicate command found */
194 if (!jcr->authenticated && cmds[i].func != hello_cmd) {
195 bnet_fsend(dir, no_auth);
196 bnet_sig(dir, BNET_EOD);
199 if ((jcr->authenticated) && (!cmds[i].monitoraccess) && (jcr->director->monitor)) {
200 Dmsg1(100, "Command %s illegal.\n", cmds[i].cmd);
201 bnet_fsend(dir, illegal_cmd);
202 bnet_sig(dir, BNET_EOD);
205 Dmsg1(100, "Executing %s command.\n", cmds[i].cmd);
206 if (!cmds[i].func(jcr)) { /* do command */
207 quit = true; /* error or fully terminated, get out */
208 Dmsg1(20, "Quit command loop. Canceled=%d\n", job_canceled(jcr));
213 if (!found) { /* command not found */
214 bnet_fsend(dir, errmsg);
220 /* Inform Storage daemon that we are done */
221 if (jcr->store_bsock) {
222 bnet_sig(jcr->store_bsock, BNET_TERMINATE);
225 if (jcr->RunAfterJob && !job_canceled(jcr)) {
226 run_cmd(jcr, jcr->RunAfterJob, "ClientRunAfterJob");
228 generate_daemon_event(jcr, "JobEnd");
230 dequeue_messages(jcr); /* send any queued messages */
232 /* Inform Director that we are done */
233 bnet_sig(dir, BNET_TERMINATE);
235 /* Clean up fileset */
236 FF_PKT *ff = jcr->ff;
237 findFILESET *fileset = ff->fileset;
240 /* Delete FileSet Include lists */
241 for (i=0; i<fileset->include_list.size(); i++) {
242 findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
243 for (j=0; j<incexe->opts_list.size(); j++) {
244 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
245 for (k=0; k<fo->regex.size(); k++) {
246 regfree((regex_t *)fo->regex.get(k));
249 fo->regexdir.destroy();
250 fo->regexfile.destroy();
252 fo->wilddir.destroy();
253 fo->wildfile.destroy();
255 fo->fstype.destroy();
263 incexe->opts_list.destroy();
264 incexe->name_list.destroy();
266 fileset->include_list.destroy();
268 /* Delete FileSet Exclude lists */
269 for (i=0; i<fileset->exclude_list.size(); i++) {
270 findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
271 for (j=0; j<incexe->opts_list.size(); j++) {
272 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
274 fo->regexdir.destroy();
275 fo->regexfile.destroy();
277 fo->wilddir.destroy();
278 fo->wildfile.destroy();
280 fo->fstype.destroy();
282 incexe->opts_list.destroy();
283 incexe->name_list.destroy();
285 fileset->exclude_list.destroy();
289 Dmsg0(100, "Calling term_find_files\n");
290 term_find_files(jcr->ff);
292 Dmsg0(100, "Done with term_find_files\n");
293 free_jcr(jcr); /* destroy JCR record */
294 Dmsg0(100, "Done with free_jcr\n");
299 * Hello from Director he must identify himself and provide his
302 static int hello_cmd(JCR *jcr)
304 Dmsg0(120, "Calling Authenticate\n");
305 if (!authenticate_director(jcr)) {
308 Dmsg0(120, "OK Authenticate\n");
309 jcr->authenticated = true;
316 static int cancel_cmd(JCR *jcr)
318 BSOCK *dir = jcr->dir_bsock;
319 char Job[MAX_NAME_LENGTH];
322 if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
323 if (!(cjcr=get_jcr_by_full_name(Job))) {
324 bnet_fsend(dir, _("2901 Job %s not found.\n"), Job);
326 if (cjcr->store_bsock) {
328 cjcr->store_bsock->timed_out = 1;
329 cjcr->store_bsock->terminated = 1;
331 * #if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
333 #if !defined(HAVE_CYGWIN)
334 pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL);
338 set_jcr_job_status(cjcr, JS_Canceled);
340 bnet_fsend(dir, _("2001 Job %s marked to be canceled.\n"), Job);
343 bnet_fsend(dir, _("2902 Error scanning cancel command.\n"));
345 bnet_sig(dir, BNET_EOD);
351 * Set debug level as requested by the Director
354 static int setdebug_cmd(JCR *jcr)
356 BSOCK *dir = jcr->dir_bsock;
357 int level, trace_flag;
359 Dmsg1(110, "setdebug_cmd: %s", dir->msg);
360 if (sscanf(dir->msg, "setdebug=%d trace=%d", &level, &trace_flag) != 2 || level < 0) {
361 pm_strcpy(jcr->errmsg, dir->msg);
362 bnet_fsend(dir, _("2991 Bad setdebug command: %s\n"), jcr->errmsg);
366 set_trace(trace_flag);
367 return bnet_fsend(dir, OKsetdebug, level);
371 static int estimate_cmd(JCR *jcr)
373 BSOCK *dir = jcr->dir_bsock;
376 if (sscanf(dir->msg, estimatecmd, &jcr->listing) != 1) {
377 pm_strcpy(jcr->errmsg, dir->msg);
378 Jmsg(jcr, M_FATAL, 0, _("Bad estimate command: %s"), jcr->errmsg);
379 bnet_fsend(dir, _("2992 Bad estimate command.\n"));
383 bnet_fsend(dir, OKest, jcr->num_files_examined,
384 edit_uint64_with_commas(jcr->JobBytes, ed2));
385 bnet_sig(dir, BNET_EOD);
390 * Get JobId and Storage Daemon Authorization key from Director
392 static int job_cmd(JCR *jcr)
394 BSOCK *dir = jcr->dir_bsock;
395 POOLMEM *sd_auth_key;
397 sd_auth_key = get_memory(dir->msglen);
398 if (sscanf(dir->msg, jobcmd, &jcr->JobId, jcr->Job,
399 &jcr->VolSessionId, &jcr->VolSessionTime,
401 pm_strcpy(jcr->errmsg, dir->msg);
402 Jmsg(jcr, M_FATAL, 0, _("Bad Job Command: %s"), jcr->errmsg);
403 bnet_fsend(dir, BADjob);
404 free_pool_memory(sd_auth_key);
407 jcr->sd_auth_key = bstrdup(sd_auth_key);
408 free_pool_memory(sd_auth_key);
409 Dmsg2(120, "JobId=%d Auth=%s\n", jcr->JobId, jcr->sd_auth_key);
410 return bnet_fsend(dir, OKjob, HOST_OS, DISTNAME, DISTVER);
413 static int runbefore_cmd(JCR *jcr)
416 BSOCK *dir = jcr->dir_bsock;
417 POOLMEM *cmd = get_memory(dir->msglen+1);
419 Dmsg1(100, "runbefore_cmd: %s", dir->msg);
420 if (sscanf(dir->msg, runbefore, cmd) != 1) {
421 pm_strcpy(jcr->errmsg, dir->msg);
422 Jmsg1(jcr, M_FATAL, 0, _("Bad RunBeforeJob command: %s\n"), jcr->errmsg);
423 bnet_fsend(dir, _("2905 Bad RunBeforeJob command.\n"));
429 /* Run the command now */
430 ok = run_cmd(jcr, cmd, "ClientRunBeforeJob");
433 bnet_fsend(dir, OKRunBefore);
436 bnet_fsend(dir, _("2905 Bad RunBeforeJob command.\n"));
441 static int runafter_cmd(JCR *jcr)
443 BSOCK *dir = jcr->dir_bsock;
444 POOLMEM *msg = get_memory(dir->msglen+1);
446 Dmsg1(100, "runafter_cmd: %s", dir->msg);
447 if (sscanf(dir->msg, runafter, msg) != 1) {
448 pm_strcpy(jcr->errmsg, dir->msg);
449 Jmsg1(jcr, M_FATAL, 0, _("Bad RunAfter command: %s\n"), jcr->errmsg);
450 bnet_fsend(dir, _("2905 Bad RunAfterJob command.\n"));
455 if (jcr->RunAfterJob) {
456 free_pool_memory(jcr->RunAfterJob);
458 jcr->RunAfterJob = get_pool_memory(PM_FNAME);
459 pm_strcpy(jcr->RunAfterJob, msg);
460 free_pool_memory(msg);
461 return bnet_fsend(dir, OKRunAfter);
464 static bool run_cmd(JCR *jcr, char *cmd, const char *name)
466 POOLMEM *ecmd = get_pool_memory(PM_FNAME);
469 char line[MAXSTRING];
471 ecmd = edit_job_codes(jcr, ecmd, cmd, "");
472 bpipe = open_bpipe(ecmd, 0, "r");
473 free_pool_memory(ecmd);
476 Jmsg(jcr, M_FATAL, 0, _("%s could not execute. ERR=%s\n"), name,
480 while (fgets(line, sizeof(line), bpipe->rfd)) {
481 int len = strlen(line);
482 if (len > 0 && line[len-1] == '\n') {
485 Jmsg(jcr, M_INFO, 0, _("%s: %s\n"), name, line);
487 status = close_bpipe(bpipe);
490 Jmsg(jcr, M_FATAL, 0, _("%s returned non-zero status=%d. ERR=%s\n"), name,
491 status, be.strerror(status));
497 static bool init_fileset(JCR *jcr)
500 findFILESET *fileset;
509 fileset = (findFILESET *)malloc(sizeof(findFILESET));
510 memset(fileset, 0, sizeof(findFILESET));
511 ff->fileset = fileset;
512 fileset->state = state_none;
513 fileset->include_list.init(1, true);
514 fileset->exclude_list.init(1, true);
518 static findFOPTS *start_options(FF_PKT *ff)
520 int state = ff->fileset->state;
521 findINCEXE *incexe = ff->fileset->incexe;
523 if (state != state_options) {
524 ff->fileset->state = state_options;
525 findFOPTS *fo = (findFOPTS *)malloc(sizeof(findFOPTS));
526 memset(fo, 0, sizeof(findFOPTS));
527 fo->regex.init(1, true);
528 fo->regexdir.init(1, true);
529 fo->regexfile.init(1, true);
530 fo->wild.init(1, true);
531 fo->wilddir.init(1, true);
532 fo->wildfile.init(1, true);
533 fo->base.init(1, true);
534 fo->fstype.init(1, true);
535 incexe->current_opts = fo;
536 incexe->opts_list.append(fo);
538 return incexe->current_opts;
543 * Add fname to include/exclude fileset list. First check for
544 * | and < and if necessary perform command.
546 static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *fileset)
560 p++; /* skip over | */
561 fn = get_pool_memory(PM_FNAME);
562 fn = edit_job_codes(jcr, fn, p, "");
563 bpipe = open_bpipe(fn, 0, "r");
564 free_pool_memory(fn);
566 Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
570 while (fgets(buf, sizeof(buf), bpipe->rfd)) {
571 strip_trailing_junk(buf);
572 fileset->incexe->name_list.append(bstrdup(buf));
574 if ((stat=close_bpipe(bpipe)) != 0) {
575 Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
576 p, stat, strerror(errno));
581 Dmsg0(100, "Doing < include on client.\n");
582 p++; /* skip over < */
583 if ((ffd = fopen(p, "r")) == NULL) {
585 Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"),
589 while (fgets(buf, sizeof(buf), ffd)) {
590 strip_trailing_junk(buf);
591 Dmsg1(100, "%s\n", buf);
592 fileset->incexe->name_list.append(bstrdup(buf));
597 fileset->incexe->name_list.append(bstrdup(fname));
603 static void add_fileset(JCR *jcr, const char *item)
605 FF_PKT *ff = jcr->ff;
606 findFILESET *fileset = ff->fileset;
607 int state = fileset->state;
608 findFOPTS *current_opts;
610 /* Get code, optional subcode, and position item past the dividing space */
611 Dmsg1(100, "%s\n", item);
616 int subcode = ' '; /* A space is always a valid subcode */
617 if (item[0] != '\0' && item[0] != ' ') {
625 /* Skip all lines we receive after an error */
626 if (state == state_error) {
631 * The switch tests the code for validity.
632 * The subcode is always good if it is a space, otherwise we must confirm.
633 * We set state to state_error first assuming the subcode is invalid,
634 * requiring state to be set in cases below that handle subcodes.
636 if (subcode != ' ') {
642 fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
643 memset(fileset->incexe, 0, sizeof(findINCEXE));
644 fileset->incexe->opts_list.init(1, true);
645 fileset->incexe->name_list.init(1, true);
646 fileset->include_list.append(fileset->incexe);
650 fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
651 memset(fileset->incexe, 0, sizeof(findINCEXE));
652 fileset->incexe->opts_list.init(1, true);
653 fileset->incexe->name_list.init(1, true);
654 fileset->exclude_list.append(fileset->incexe);
660 /* File item to either include/include list */
661 state = state_include;
662 add_file_to_fileset(jcr, item, fileset);
665 current_opts = start_options(ff);
669 preg = (regex_t *)malloc(sizeof(regex_t));
670 if (current_opts->flags & FO_IGNORECASE) {
671 rc = regcomp(preg, item, REG_EXTENDED|REG_ICASE);
673 rc = regcomp(preg, item, REG_EXTENDED);
676 regerror(rc, preg, prbuf, sizeof(prbuf));
679 Jmsg(jcr, M_FATAL, 0, _("REGEX %s compile error. ERR=%s\n"), item, prbuf);
683 state = state_options;
684 if (subcode == ' ') {
685 current_opts->regex.append(preg);
686 } else if (subcode == 'D') {
687 current_opts->regexdir.append(preg);
688 } else if (subcode == 'F') {
689 current_opts->regexfile.append(preg);
695 current_opts = start_options(ff);
696 current_opts->base.append(bstrdup(item));
697 state = state_options;
700 current_opts = start_options(ff);
701 current_opts->fstype.append(bstrdup(item));
702 state = state_options;
705 current_opts = start_options(ff);
706 state = state_options;
707 if (subcode == ' ') {
708 current_opts->wild.append(bstrdup(item));
709 } else if (subcode == 'D') {
710 current_opts->wilddir.append(bstrdup(item));
711 } else if (subcode == 'F') {
712 current_opts->wildfile.append(bstrdup(item));
718 current_opts = start_options(ff);
719 set_options(current_opts, item);
720 state = state_options;
723 current_opts = start_options(ff);
724 current_opts->reader = bstrdup(item);
725 state = state_options;
728 current_opts = start_options(ff);
729 current_opts->writer = bstrdup(item);
730 state = state_options;
733 Jmsg(jcr, M_FATAL, 0, _("Invalid FileSet command: %s\n"), item);
737 ff->fileset->state = state;
740 static bool term_fileset(JCR *jcr)
742 FF_PKT *ff = jcr->ff;
743 findFILESET *fileset = ff->fileset;
746 for (i=0; i<fileset->include_list.size(); i++) {
747 findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
749 for (j=0; j<incexe->opts_list.size(); j++) {
750 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
751 for (k=0; k<fo->regex.size(); k++) {
752 Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
754 for (k=0; k<fo->regexdir.size(); k++) {
755 Dmsg1(400, "RD %s\n", (char *)fo->regexdir.get(k));
757 for (k=0; k<fo->regexfile.size(); k++) {
758 Dmsg1(400, "RF %s\n", (char *)fo->regexfile.get(k));
760 for (k=0; k<fo->wild.size(); k++) {
761 Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
763 for (k=0; k<fo->wilddir.size(); k++) {
764 Dmsg1(400, "WD %s\n", (char *)fo->wilddir.get(k));
766 for (k=0; k<fo->wildfile.size(); k++) {
767 Dmsg1(400, "WF %s\n", (char *)fo->wildfile.get(k));
769 for (k=0; k<fo->base.size(); k++) {
770 Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
772 for (k=0; k<fo->fstype.size(); k++) {
773 Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
776 Dmsg1(400, "D %s\n", fo->reader);
779 Dmsg1(400, "T %s\n", fo->writer);
782 for (j=0; j<incexe->name_list.size(); j++) {
783 Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
786 for (i=0; i<fileset->exclude_list.size(); i++) {
787 findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
789 for (j=0; j<incexe->opts_list.size(); j++) {
790 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
791 for (k=0; k<fo->regex.size(); k++) {
792 Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
794 for (k=0; k<fo->regexdir.size(); k++) {
795 Dmsg1(400, "RD %s\n", (char *)fo->regexdir.get(k));
797 for (k=0; k<fo->regexfile.size(); k++) {
798 Dmsg1(400, "RF %s\n", (char *)fo->regexfile.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->wilddir.size(); k++) {
804 Dmsg1(400, "WD %s\n", (char *)fo->wilddir.get(k));
806 for (k=0; k<fo->wildfile.size(); k++) {
807 Dmsg1(400, "WF %s\n", (char *)fo->wildfile.get(k));
809 for (k=0; k<fo->base.size(); k++) {
810 Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
812 for (k=0; k<fo->fstype.size(); k++) {
813 Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
816 for (j=0; j<incexe->name_list.size(); j++) {
817 Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
820 return ff->fileset->state != state_error;
825 * As an optimization, we should do this during
826 * "compile" time in filed/job.c, and keep only a bit mask
827 * and the Verify options.
829 static void set_options(findFOPTS *fo, const char *opts)
834 for (p=opts; *p; p++) {
836 case 'a': /* alway replace */
837 case '0': /* no option */
840 fo->flags |= FO_EXCLUDE;
843 fo->flags |= FO_MULTIFS;
845 case 'h': /* no recursion */
846 fo->flags |= FO_NO_RECURSION;
848 case 'H': /* no hard link handling */
849 fo->flags |= FO_NO_HARDLINK;
852 fo->flags |= FO_IGNORECASE;
858 fo->flags |= FO_NOREPLACE;
860 case 'p': /* use portable data format */
861 fo->flags |= FO_PORTABLE;
863 case 'R': /* Resource forks and Finder Info */
864 fo->flags |= FO_HFSPLUS;
865 case 'r': /* read fifo */
866 fo->flags |= FO_READFIFO;
869 fo->flags |= FO_SHA1;
872 fo->flags |= FO_SPARSE;
875 fo->flags |= FO_MTIMEONLY;
878 fo->flags |= FO_KEEPATIME;
883 case 'V': /* verify options */
884 /* Copy Verify Options */
885 for (j=0; *p && *p != ':'; p++) {
886 fo->VerifyOpts[j] = *p;
887 if (j < (int)sizeof(fo->VerifyOpts) - 1) {
891 fo->VerifyOpts[j] = 0;
894 fo->flags |= FO_IF_NEWER;
896 case 'Z': /* gzip compression */
897 fo->flags |= FO_GZIP;
898 fo->GZIP_level = *++p - '0';
899 Dmsg1(200, "Compression level=%d\n", fo->GZIP_level);
902 Emsg1(M_ERROR, 0, _("Unknown include/exclude option: %c\n"), *p);
910 * Director is passing his Fileset
912 static int fileset_cmd(JCR *jcr)
914 BSOCK *dir = jcr->dir_bsock;
917 sscanf(dir->msg, "fileset vss=%d", &vss);
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);
934 static void free_bootstrap(JCR *jcr)
936 if (jcr->RestoreBootstrap) {
937 unlink(jcr->RestoreBootstrap);
938 free_pool_memory(jcr->RestoreBootstrap);
939 jcr->RestoreBootstrap = NULL;
945 * The Director sends us the bootstrap file, which
946 * we will in turn pass to the SD.
948 static int bootstrap_cmd(JCR *jcr)
950 BSOCK *dir = jcr->dir_bsock;
951 POOLMEM *fname = get_pool_memory(PM_FNAME);
955 Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
957 Dmsg1(400, "bootstrap=%s\n", fname);
958 jcr->RestoreBootstrap = fname;
959 bs = fopen(fname, "a+"); /* create file */
962 Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"),
963 jcr->RestoreBootstrap, be.strerror());
965 * Suck up what he is sending to us so that he will then
966 * read our error message.
968 while (bnet_recv(dir) >= 0)
971 set_jcr_job_status(jcr, JS_ErrorTerminated);
975 while (bnet_recv(dir) >= 0) {
976 Dmsg1(200, "filed<dird: bootstrap file %s\n", dir->msg);
981 * Note, do not free the bootstrap yet -- it needs to be
984 return bnet_fsend(dir, OKbootstrap);
989 * Get backup level from Director
992 static int level_cmd(JCR *jcr)
994 BSOCK *dir = jcr->dir_bsock;
995 POOLMEM *level, *buf = NULL;
998 level = get_memory(dir->msglen+1);
999 Dmsg1(110, "level_cmd: %s", dir->msg);
1000 if (sscanf(dir->msg, "level = %s ", level) != 1) {
1003 /* Base backup requested? */
1004 if (strcmp(level, "base") == 0) {
1005 jcr->JobLevel = L_BASE;
1006 /* Full backup requested? */
1007 } else if (strcmp(level, "full") == 0) {
1008 jcr->JobLevel = L_FULL;
1009 } else if (strcmp(level, "differential") == 0) {
1010 jcr->JobLevel = L_DIFFERENTIAL;
1013 } else if (strcmp(level, "incremental") == 0) {
1014 jcr->JobLevel = L_INCREMENTAL;
1018 * We get his UTC since time, then sync the clocks and correct it
1019 * to agree with our clock.
1021 } else if (strcmp(level, "since_utime") == 0) {
1022 buf = get_memory(dir->msglen+1);
1023 utime_t since_time, adj;
1024 btime_t his_time, bt_start, rt=0, bt_adj=0;
1025 if (jcr->JobLevel == L_NONE) {
1026 jcr->JobLevel = L_SINCE; /* if no other job level set, do it now */
1028 if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
1029 buf, &mtime_only) != 2) {
1032 since_time = str_to_uint64(buf); /* this is the since time */
1033 char ed1[50], ed2[50];
1035 * Sync clocks by polling him for the time. We take
1036 * 10 samples of his time throwing out the first two.
1038 for (int i=0; i<10; i++) {
1039 bt_start = get_current_btime();
1040 bnet_sig(dir, BNET_BTIME); /* poll for time */
1041 if (bnet_recv(dir) <= 0) { /* get response */
1044 if (sscanf(dir->msg, "btime %s", buf) != 1) {
1047 if (i < 2) { /* toss first two results */
1050 his_time = str_to_uint64(buf);
1051 rt = get_current_btime() - bt_start; /* compute round trip time */
1052 bt_adj -= his_time - bt_start - rt/2;
1053 Dmsg2(200, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
1056 bt_adj = bt_adj / 8; /* compute average time */
1057 Dmsg2(100, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
1058 adj = btime_to_utime(bt_adj);
1059 since_time += adj; /* adjust for clock difference */
1061 Jmsg(jcr, M_INFO, 0, _("DIR and FD clocks differ by %d seconds, FD automatically adjusting.\n"), adj);
1063 bnet_sig(dir, BNET_EOD);
1065 Dmsg2(100, "adj = %d since_time=%d\n", (int)adj, (int)since_time);
1066 jcr->incremental = 1; /* set incremental or decremental backup */
1067 jcr->mtime = (time_t)since_time; /* set since time */
1069 Jmsg1(jcr, M_FATAL, 0, _("Unknown backup level: %s\n"), level);
1077 return bnet_fsend(dir, OKlevel);
1080 pm_strcpy(jcr->errmsg, dir->msg);
1081 Jmsg1(jcr, M_FATAL, 0, _("Bad level command: %s\n"), jcr->errmsg);
1090 * Get session parameters from Director -- this is for a Restore command
1092 static int session_cmd(JCR *jcr)
1094 BSOCK *dir = jcr->dir_bsock;
1096 Dmsg1(100, "SessionCmd: %s", dir->msg);
1097 if (sscanf(dir->msg, sessioncmd, jcr->VolumeName,
1098 &jcr->VolSessionId, &jcr->VolSessionTime,
1099 &jcr->StartFile, &jcr->EndFile,
1100 &jcr->StartBlock, &jcr->EndBlock) != 7) {
1101 pm_strcpy(jcr->errmsg, dir->msg);
1102 Jmsg(jcr, M_FATAL, 0, _("Bad session command: %s"), jcr->errmsg);
1106 return bnet_fsend(dir, OKsession);
1110 * Get address of storage daemon from Director
1113 static int storage_cmd(JCR *jcr)
1115 int stored_port; /* storage daemon port */
1116 int enable_ssl; /* enable ssl to sd */
1117 BSOCK *dir = jcr->dir_bsock;
1118 BSOCK *sd; /* storage daemon bsock */
1120 Dmsg1(100, "StorageCmd: %s", dir->msg);
1121 if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port, &enable_ssl) != 3) {
1122 pm_strcpy(jcr->errmsg, dir->msg);
1123 Jmsg(jcr, M_FATAL, 0, _("Bad storage command: %s"), jcr->errmsg);
1126 Dmsg3(110, "Open storage: %s:%d ssl=%d\n", jcr->stored_addr, stored_port, enable_ssl);
1127 /* Open command communications with Storage daemon */
1128 /* Try to connect for 1 hour at 10 second intervals */
1129 sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"),
1130 jcr->stored_addr, NULL, stored_port, 1);
1132 Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
1133 jcr->stored_addr, stored_port);
1134 Dmsg2(100, "Failed to connect to Storage daemon: %s:%d\n",
1135 jcr->stored_addr, stored_port);
1138 Dmsg0(110, "Connection OK to SD.\n");
1140 jcr->store_bsock = sd;
1142 bnet_fsend(sd, "Hello Start Job %s\n", jcr->Job);
1143 if (!authenticate_storagedaemon(jcr)) {
1144 Jmsg(jcr, M_FATAL, 0, _("Failed to authenticate Storage daemon.\n"));
1147 Dmsg0(110, "Authenticated with SD.\n");
1149 /* Send OK to Director */
1150 return bnet_fsend(dir, OKstore);
1155 * Do a backup. For now, we handle only Full and Incremental.
1157 static int backup_cmd(JCR *jcr)
1159 BSOCK *dir = jcr->dir_bsock;
1160 BSOCK *sd = jcr->store_bsock;
1163 char ed1[50], ed2[50];
1165 set_jcr_job_status(jcr, JS_Blocked);
1166 jcr->JobType = JT_BACKUP;
1167 Dmsg1(100, "begin backup ff=%p\n", jcr->ff);
1170 Jmsg(jcr, M_FATAL, 0, _("Cannot contact Storage daemon\n"));
1174 bnet_fsend(dir, OKbackup);
1175 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1178 * Send Append Open Session to Storage daemon
1180 bnet_fsend(sd, append_open);
1181 Dmsg1(110, ">stored: %s", sd->msg);
1183 * Expect to receive back the Ticket number
1185 if (bget_msg(sd) >= 0) {
1186 Dmsg1(110, "<stored: %s", sd->msg);
1187 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
1188 Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg);
1191 Dmsg1(110, "Got Ticket=%d\n", jcr->Ticket);
1193 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to open command\n"));
1198 * Send Append data command to Storage daemon
1200 bnet_fsend(sd, append_data, jcr->Ticket);
1201 Dmsg1(110, ">stored: %s", sd->msg);
1204 * Expect to get OK data
1206 Dmsg1(110, "<stored: %s", sd->msg);
1207 if (!response(jcr, sd, OK_data, "Append Data")) {
1211 generate_daemon_event(jcr, "JobStart");
1214 /* START VSS ON WIN 32 */
1215 if (g_pVSSClient && enable_vss) {
1216 /* Run only one at a time */
1218 if (g_pVSSClient->InitializeForBackup()) {
1219 /* tell vss which drives to snapshot */
1220 char szWinDriveLetters[27];
1221 if (get_win32_driveletters(jcr->ff, szWinDriveLetters)) {
1222 Jmsg(jcr, M_INFO, 0, _("Generate VSS snapshots. Driver=\"%s\", Drive(s)=\"%s\"\n"), g_pVSSClient->GetDriverName(), szWinDriveLetters);
1223 if (!g_pVSSClient->CreateSnapshots(szWinDriveLetters)) {
1225 Jmsg(jcr, M_WARNING, 0, _("Generate VSS snapshots failed. ERR=%s\n"),
1228 /* tell user if snapshot creation of a specific drive failed */
1230 for (i=0; i<strlen (szWinDriveLetters); i++) {
1231 if (islower(szWinDriveLetters[i])) {
1232 Jmsg(jcr, M_WARNING, 0, _("Generate VSS snapshot of drive \"%c:\\\" failed\n"), szWinDriveLetters[i]);
1235 /* inform user about writer states */
1236 for (i=0; i<g_pVSSClient->GetWriterCount(); i++) {
1237 int msg_type = M_INFO;
1238 if (g_pVSSClient->GetWriterState(i) < 0) {
1239 msg_type = M_WARNING;
1241 Jmsg(jcr, msg_type, 0, _("VSS Writer: %s\n"), g_pVSSClient->GetWriterInfo(i));
1245 Jmsg(jcr, M_INFO, 0, _("No drive letters found for generating VSS snapshots.\n"));
1248 Jmsg(jcr, M_WARNING, 0, _("VSS was not initialized properly. VSS support is disabled.\n"));
1254 * Send Files to Storage daemon
1256 Dmsg1(110, "begin blast ff=%p\n", (FF_PKT *)jcr->ff);
1257 if (!blast_data_to_storage_daemon(jcr, NULL)) {
1258 set_jcr_job_status(jcr, JS_ErrorTerminated);
1259 bnet_suppress_error_messages(sd, 1);
1260 bget_msg(sd); /* Read final response from append_data */
1261 Dmsg0(110, "Error in blast_data.\n");
1263 set_jcr_job_status(jcr, JS_Terminated);
1264 if (jcr->JobStatus != JS_Terminated) {
1265 bnet_suppress_error_messages(sd, 1);
1266 goto cleanup; /* bail out now */
1269 * Expect to get response to append_data from Storage daemon
1271 if (!response(jcr, sd, OK_append, "Append Data")) {
1272 set_jcr_job_status(jcr, JS_ErrorTerminated);
1277 * Send Append End Data to Storage daemon
1279 bnet_fsend(sd, append_end, jcr->Ticket);
1281 if (!response(jcr, sd, OK_end, "Append End")) {
1282 set_jcr_job_status(jcr, JS_ErrorTerminated);
1287 * Send Append Close to Storage daemon
1289 bnet_fsend(sd, append_close, jcr->Ticket);
1290 while (bget_msg(sd) >= 0) { /* stop on signal or error */
1291 if (sscanf(sd->msg, OK_close, &SDJobStatus) == 1) {
1293 Dmsg2(200, "SDJobStatus = %d %c\n", SDJobStatus, (char)SDJobStatus);
1297 Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n"));
1300 if (SDJobStatus != JS_Terminated) {
1301 Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"),
1308 /* STOP VSS ON WIN 32 */
1309 /* tell vss to close the backup session */
1310 if (g_pVSSClient && enable_vss) {
1311 g_pVSSClient->CloseBackup();
1316 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1317 edit_uint64(jcr->ReadBytes, ed1),
1318 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1319 Dmsg1(110, "End FD msg: %s\n", dir->msg);
1321 return 0; /* return and stop command loop */
1325 * Do a Verify for Director
1328 static int verify_cmd(JCR *jcr)
1330 BSOCK *dir = jcr->dir_bsock;
1331 BSOCK *sd = jcr->store_bsock;
1332 char level[100], ed1[50], ed2[50];
1334 jcr->JobType = JT_VERIFY;
1335 if (sscanf(dir->msg, verifycmd, level) != 1) {
1336 bnet_fsend(dir, _("2994 Bad verify command: %s\n"), dir->msg);
1340 if (strcasecmp(level, "init") == 0) {
1341 jcr->JobLevel = L_VERIFY_INIT;
1342 } else if (strcasecmp(level, "catalog") == 0){
1343 jcr->JobLevel = L_VERIFY_CATALOG;
1344 } else if (strcasecmp(level, "volume") == 0){
1345 jcr->JobLevel = L_VERIFY_VOLUME_TO_CATALOG;
1346 } else if (strcasecmp(level, "data") == 0){
1347 jcr->JobLevel = L_VERIFY_DATA;
1348 } else if (strcasecmp(level, "disk_to_catalog") == 0) {
1349 jcr->JobLevel = L_VERIFY_DISK_TO_CATALOG;
1351 bnet_fsend(dir, _("2994 Bad verify level: %s\n"), dir->msg);
1355 bnet_fsend(dir, OKverify);
1357 generate_daemon_event(jcr, "JobStart");
1359 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1361 switch (jcr->JobLevel) {
1363 case L_VERIFY_CATALOG:
1366 case L_VERIFY_VOLUME_TO_CATALOG:
1367 if (!open_sd_read_session(jcr)) {
1370 start_dir_heartbeat(jcr);
1371 do_verify_volume(jcr);
1372 stop_dir_heartbeat(jcr);
1374 * Send Close session command to Storage daemon
1376 bnet_fsend(sd, read_close, jcr->Ticket);
1377 Dmsg1(130, "bfiled>stored: %s", sd->msg);
1379 /* ****FIXME**** check response */
1380 bget_msg(sd); /* get OK */
1382 /* Inform Storage daemon that we are done */
1383 bnet_sig(sd, BNET_TERMINATE);
1386 case L_VERIFY_DISK_TO_CATALOG:
1390 bnet_fsend(dir, _("2994 Bad verify level: %s\n"), dir->msg);
1394 bnet_sig(dir, BNET_EOD);
1396 /* Send termination status back to Dir */
1397 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1398 edit_uint64(jcr->ReadBytes, ed1),
1399 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1401 /* Inform Director that we are done */
1402 bnet_sig(dir, BNET_TERMINATE);
1403 return 0; /* return and terminate command loop */
1407 * Do a Restore for Director
1410 static int restore_cmd(JCR *jcr)
1412 BSOCK *dir = jcr->dir_bsock;
1413 BSOCK *sd = jcr->store_bsock;
1417 char ed1[50], ed2[50];
1420 * Scan WHERE (base directory for restore) from command
1422 Dmsg0(150, "restore command\n");
1423 /* Pickup where string */
1424 where = get_memory(dir->msglen+1);
1427 if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, where) != 3) {
1428 if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) {
1429 pm_strcpy(jcr->errmsg, dir->msg);
1430 Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
1435 /* Turn / into nothing */
1436 if (where[0] == '/' && where[1] == 0) {
1440 Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
1441 unbash_spaces(where);
1442 jcr->where = bstrdup(where);
1443 free_pool_memory(where);
1444 jcr->replace = replace;
1445 jcr->prefix_links = prefix_links;
1447 bnet_fsend(dir, OKrestore);
1448 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1450 jcr->JobType = JT_RESTORE;
1452 set_jcr_job_status(jcr, JS_Blocked);
1454 if (!open_sd_read_session(jcr)) {
1455 set_jcr_job_status(jcr, JS_ErrorTerminated);
1459 set_jcr_job_status(jcr, JS_Running);
1462 * Do restore of files and data
1464 start_dir_heartbeat(jcr);
1465 generate_daemon_event(jcr, "JobStart");
1467 stop_dir_heartbeat(jcr);
1469 set_jcr_job_status(jcr, JS_Terminated);
1470 if (jcr->JobStatus != JS_Terminated) {
1471 bnet_suppress_error_messages(sd, 1);
1475 * Send Close session command to Storage daemon
1477 bnet_fsend(sd, read_close, jcr->Ticket);
1478 Dmsg1(130, "bfiled>stored: %s", sd->msg);
1480 bget_msg(sd); /* get OK */
1482 /* Inform Storage daemon that we are done */
1483 bnet_sig(sd, BNET_TERMINATE);
1488 set_jcr_job_status(jcr, JS_ErrorTerminated);
1490 /* Send termination status back to Dir */
1491 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1492 edit_uint64(jcr->ReadBytes, ed1),
1493 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1495 /* Inform Director that we are done */
1496 bnet_sig(dir, BNET_TERMINATE);
1498 Dmsg0(130, "Done in job.c\n");
1499 return 0; /* return and terminate command loop */
1502 static int open_sd_read_session(JCR *jcr)
1504 BSOCK *sd = jcr->store_bsock;
1507 Jmsg(jcr, M_FATAL, 0, _("Improper calling sequence.\n"));
1510 Dmsg4(120, "VolSessId=%ld VolsessT=%ld SF=%ld EF=%ld\n",
1511 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile);
1512 Dmsg2(120, "JobId=%d vol=%s\n", jcr->JobId, "DummyVolume");
1514 * Open Read Session with Storage daemon
1516 bnet_fsend(sd, read_open, jcr->VolumeName,
1517 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile,
1518 jcr->StartBlock, jcr->EndBlock);
1519 Dmsg1(110, ">stored: %s", sd->msg);
1524 if (bget_msg(sd) >= 0) {
1525 Dmsg1(110, "bfiled<stored: %s", sd->msg);
1526 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
1527 Jmsg(jcr, M_FATAL, 0, _("Bad response to SD read open: %s\n"), sd->msg);
1530 Dmsg1(110, "bfiled: got Ticket=%d\n", jcr->Ticket);
1532 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to read open command\n"));
1536 if (!send_bootstrap_file(jcr)) {
1541 * Start read of data with Storage daemon
1543 bnet_fsend(sd, read_data, jcr->Ticket);
1544 Dmsg1(110, ">stored: %s", sd->msg);
1549 if (!response(jcr, sd, OK_data, "Read Data")) {
1556 * Destroy the Job Control Record and associated
1557 * resources (sockets).
1559 static void filed_free_jcr(JCR *jcr)
1561 if (jcr->store_bsock) {
1562 bnet_close(jcr->store_bsock);
1564 free_bootstrap(jcr);
1565 if (jcr->last_fname) {
1566 free_pool_memory(jcr->last_fname);
1568 if (jcr->RunAfterJob) {
1569 free_pool_memory(jcr->RunAfterJob);
1577 * Get response from Storage daemon to a command we
1578 * sent. Check that the response is OK.
1580 * Returns: 0 on failure
1583 int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd)
1588 if (bget_msg(sd) > 0) {
1589 Dmsg0(110, sd->msg);
1590 if (strcmp(sd->msg, resp) == 0) {
1594 if (job_canceled(jcr)) {
1595 return 0; /* if canceled avoid useless error messages */
1597 if (is_bnet_error(sd)) {
1598 Jmsg2(jcr, M_FATAL, 0, _("Comm error with SD. bad response to %s. ERR=%s\n"),
1599 cmd, bnet_strerror(sd));
1601 Jmsg3(jcr, M_FATAL, 0, _("Bad response to %s command. Wanted %s, got %s\n"),
1602 cmd, resp, sd->msg);
1607 static int send_bootstrap_file(JCR *jcr)
1611 BSOCK *sd = jcr->store_bsock;
1612 const char *bootstrap = "bootstrap\n";
1615 Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
1616 if (!jcr->RestoreBootstrap) {
1619 bs = fopen(jcr->RestoreBootstrap, "r");
1622 Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
1623 jcr->RestoreBootstrap, be.strerror());
1624 set_jcr_job_status(jcr, JS_ErrorTerminated);
1627 sd->msglen = pm_strcpy(sd->msg, bootstrap);
1629 while (fgets(buf, sizeof(buf), bs)) {
1630 sd->msglen = Mmsg(sd->msg, "%s", buf);
1633 bnet_sig(sd, BNET_EOD);
1635 if (!response(jcr, sd, OKSDbootstrap, "Bootstrap")) {
1636 set_jcr_job_status(jcr, JS_ErrorTerminated);
1642 free_bootstrap(jcr);