static char storaddr[] = "storage address=%s port=%d\n";
static char sessioncmd[] = "session %s %ld %ld %ld %ld %ld %ld\n";
static char restorecmd[] = "restore replace=%c where=%s\n";
+static char restorecmd1[] = "restore replace=%c where=\n";
static char verifycmd[] = "verify level=%20s\n";
/* Responses sent to Director */
jcr->ff = init_find_files();
jcr->start_time = time(NULL);
jcr->last_fname = get_pool_memory(PM_FNAME);
+ jcr->last_fname[0] = 0;
jcr->client_name = get_memory(strlen(my_name) + 1);
- strcpy(jcr->client_name, my_name);
+ pm_strcpy(&jcr->client_name, my_name);
dir->jcr = (void *)jcr;
/**********FIXME******* add command handler error code */
}
}
Dmsg0(100, "Calling term_find_files\n");
- term_find_files(jcr->ff);
+ term_find_files((FF_PKT *)jcr->ff);
Dmsg0(100, "Done with term_find_files\n");
free_jcr(jcr); /* destroy JCR record */
Dmsg0(100, "Done with free_jcr\n");
if (!(cjcr=get_jcr_by_full_name(Job))) {
bnet_fsend(dir, "2901 Job %s not found.\n", Job);
} else {
- cjcr->JobStatus = JS_Cancelled;
+ set_jcr_job_status(cjcr, JS_Cancelled);
free_jcr(cjcr);
bnet_fsend(dir, "2001 Job %s marked to be cancelled.\n", Job);
}
while (bnet_recv(dir) >= 0) {
dir->msg[dir->msglen] = 0;
strip_trailing_junk(dir->msg);
- Dmsg1(110, "filed<dird: include file %s\n", dir->msg);
- add_fname_to_include_list(jcr->ff, 1, dir->msg);
+ Dmsg1(010, "include file: %s\n", dir->msg);
+ add_fname_to_include_list((FF_PKT *)jcr->ff, 1, dir->msg);
}
return bnet_fsend(dir, OKinc);
/* Skip spaces */
for ( ; *p && *p == ' '; p++)
{ }
- add_fname_to_exclude_list(jcr->ff, p);
+ add_fname_to_exclude_list((FF_PKT *)jcr->ff, p);
Dmsg1(110, "<dird: exclude file %s\n", dir->msg);
}
jcr->RestoreBootstrap, strerror(errno));
free_pool_memory(jcr->RestoreBootstrap);
jcr->RestoreBootstrap = NULL;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
return 0;
}
int ok = 0;
int SDJobStatus;
- jcr->JobStatus = JS_Blocked;
+ set_jcr_job_status(jcr, JS_Blocked);
jcr->JobType = JT_BACKUP;
- Dmsg1(100, "begin backup ff=%p\n", jcr->ff);
+ Dmsg1(100, "begin backup ff=%p\n", (FF_PKT *)jcr->ff);
if (sd == NULL) {
Jmsg(jcr, M_FATAL, 0, _("Cannot contact Storage daemon\n"));
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
goto cleanup;
}
Dmsg1(110, "<stored: %s", sd->msg);
if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg);
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
goto cleanup;
}
Dmsg1(110, "Got Ticket=%d\n", jcr->Ticket);
} else {
Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to open command\n"));
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
goto cleanup;
}
*/
Dmsg1(110, "<stored: %s", sd->msg);
if (!response(jcr, sd, OK_data, "Append Data")) {
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
goto cleanup;
}
/*
* Send Files to Storage daemon
*/
- Dmsg1(110, "begin blast ff=%p\n", jcr->ff);
+ Dmsg1(110, "begin blast ff=%p\n", (FF_PKT *)jcr->ff);
if (!blast_data_to_storage_daemon(jcr, NULL)) {
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
+ bnet_suppress_error_messages(sd, 1);
} else {
- jcr->JobStatus = JS_Terminated;
+ set_jcr_job_status(jcr, JS_Terminated);
+ if (jcr->JobStatus != JS_Terminated) {
+ bnet_suppress_error_messages(sd, 1);
+ goto cleanup; /* bail out now */
+ }
/*
* Expect to get response to append_data from Storage daemon
*/
if (!response(jcr, sd, OK_append, "Append Data")) {
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
goto cleanup;
}
bnet_fsend(sd, append_end, jcr->Ticket);
/* Get end OK */
if (!response(jcr, sd, OK_end, "Append End")) {
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
goto cleanup;
}
}
if (!ok) {
Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n"));
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
goto cleanup;
}
if (SDJobStatus != JS_Terminated) {
Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"),
SDJobStatus);
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
}
}
*where = 0;
if (sscanf(dir->msg, restorecmd, &replace, where) != 2) {
- Jmsg(jcr, M_FATAL, 0, _("Bad replace command.\n"));
- return 0;
+ if (sscanf(dir->msg, restorecmd1, &replace) != 1) {
+ Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), dir->msg);
+ return 0;
+ }
+ *where = 0;
+ }
+ /* Turn / into nothing */
+ if (where[0] == '/' && where[1] == 0) {
+ where[0] = 0;
}
Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
Dmsg1(110, "bfiled>dird: %s", dir->msg);
jcr->JobType = JT_RESTORE;
- jcr->JobStatus = JS_Blocked;
+ set_jcr_job_status(jcr, JS_Blocked);
if (!open_sd_read_session(jcr)) {
- return 0;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
+ goto bail_out;
}
+ set_jcr_job_status(jcr, JS_Running);
+
/*
* Do restore of files and data
*/
do_restore(jcr);
+ set_jcr_job_status(jcr, JS_Terminated);
+ if (jcr->JobStatus != JS_Terminated) {
+ bnet_suppress_error_messages(sd, 1);
+ }
+
/*
* Send Close session command to Storage daemon
*/
bnet_fsend(sd, read_close, jcr->Ticket);
Dmsg1(130, "bfiled>stored: %s", sd->msg);
- /* ****FIXME**** check response */
bnet_recv(sd); /* get OK */
/* Inform Storage daemon that we are done */
bnet_sig(sd, BNET_TERMINATE);
- bnet_fsend(dir, EndRestore, jcr->JobStatus, jcr->num_files_examined, jcr->JobBytes);
+bail_out:
+ /* Send termination status back to Dir */
+ bnet_fsend(dir, EndRestore, jcr->JobStatus, jcr->num_files_examined,
+ jcr->JobBytes);
/* Inform Director that we are done */
bnet_sig(dir, BNET_TERMINATE);
Dmsg0(130, "Done in job.c\n");
- return 1;
+ return !job_cancelled(jcr);
}
static int open_sd_read_session(JCR *jcr)
if (!bs) {
Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
jcr->RestoreBootstrap, strerror(errno));
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
return 0;
}
strcpy(sd->msg, bootstrap);
bnet_sig(sd, BNET_EOD);
fclose(bs);
if (!response(jcr, sd, OKSDbootstrap, "Bootstrap")) {
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
return 0;
}
return 1;