From 677739f86d7a469c45ccae13a577a5a4a28b5aa6 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 15 Jul 2005 08:14:23 +0000 Subject: [PATCH] - Get VSS build scripts working with Thorsten's help. - Unlink the bootstrap file after sending it to the FD. - Remove sending include/exclude lists to the FD during a restore -- deprecated code. - Cleanup the bootstrap files in the FD. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2199 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kes-1.37 | 9 + bacula/src/dird/fd_cmds.c | 1 + bacula/src/dird/restore.c | 68 ++--- bacula/src/filed/job.c | 570 +++++++++++++++++++------------------- 4 files changed, 329 insertions(+), 319 deletions(-) diff --git a/bacula/kes-1.37 b/bacula/kes-1.37 index 17dd042045..3230194f8d 100644 --- a/bacula/kes-1.37 +++ b/bacula/kes-1.37 @@ -3,6 +3,15 @@ General: +Changes to 1.37.30: +14Jul05 +- Get VSS build scripts working with Thorsten's help. +- Unlink the bootstrap file after sending it to + the FD. +- Remove sending include/exclude lists to the FD during + a restore -- deprecated code. +- Cleanup the bootstrap files in the FD. + Changes to 1.37.29: 14Jul05 - Remove old commented out code from configure.in diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index f28e4cc1b5..5e813666a9 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -449,6 +449,7 @@ bool send_bootstrap_file(JCR *jcr) } bnet_sig(fd, BNET_EOD); fclose(bs); + unlink(jcr->RestoreBootstrap); if (!response(jcr, fd, OKbootstrap, "Bootstrap", DISPLAY_ERROR)) { set_jcr_job_status(jcr, JS_ErrorTerminated); return 0; diff --git a/bacula/src/dird/restore.c b/bacula/src/dird/restore.c index f471392ae3..9c0d1573cc 100644 --- a/bacula/src/dird/restore.c +++ b/bacula/src/dird/restore.c @@ -12,7 +12,7 @@ * Open DB * Open Message Channel with Storage daemon to tell him a job will be starting. * Open connection with File daemon and pass him commands - * to do the restore. + * to do the restore. * Update the DB according to what files where restored???? * * Version $Id$ @@ -48,15 +48,15 @@ static char OKstore[] = "2000 OK storage\n"; * Do a restore of the specified files * * Returns: 0 on failure - * 1 on success + * 1 on success */ bool do_restore(JCR *jcr) { BSOCK *fd; - JOB_DBR rjr; /* restore job record */ + JOB_DBR rjr; /* restore job record */ memset(&rjr, 0, sizeof(rjr)); - jcr->jr.JobLevel = L_FULL; /* Full restore */ + jcr->jr.JobLevel = L_FULL; /* Full restore */ if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) { Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db)); restore_cleanup(jcr, JS_ErrorTerminated); @@ -119,6 +119,7 @@ bool do_restore(JCR *jcr) fd = jcr->file_bsock; set_jcr_job_status(jcr, JS_Running); +#ifdef xxx if (!send_include_list(jcr)) { restore_cleanup(jcr, JS_ErrorTerminated); return false; @@ -128,11 +129,12 @@ bool do_restore(JCR *jcr) restore_cleanup(jcr, JS_ErrorTerminated); return false; } +#endif /* * send Storage daemon address to the File daemon, - * then wait for File daemon to make connection - * with Storage daemon. + * then wait for File daemon to make connection + * with Storage daemon. */ if (jcr->store->SDDport == 0) { jcr->store->SDDport = jcr->store->SDport; @@ -170,11 +172,11 @@ bool do_restore(JCR *jcr) replace = REPLACE_ALWAYS; /* always replace */ } if (jcr->where) { - where = jcr->where; /* override */ + where = jcr->where; /* override */ } else if (jcr->job->RestoreWhere) { where = jcr->job->RestoreWhere; /* no override take from job */ } else { - where = ∅ /* None */ + where = ∅ /* None */ } jcr->prefix_links = jcr->job->PrefixLinks; bash_spaces(where); @@ -212,7 +214,7 @@ void restore_cleanup(JCR *jcr, int TermCode) double kbps; Dmsg0(20, "In restore_cleanup\n"); - dequeue_messages(jcr); /* display any queued messages */ + dequeue_messages(jcr); /* display any queued messages */ set_jcr_job_status(jcr, TermCode); if (jcr->unlink_bsr && jcr->RestoreBootstrap) { @@ -222,7 +224,7 @@ void restore_cleanup(JCR *jcr, int TermCode) update_job_end_record(jcr); - msg_type = M_INFO; /* by default INFO message */ + msg_type = M_INFO; /* by default INFO message */ switch (TermCode) { case JS_Terminated: if (jcr->ExpectedFiles > jcr->jr.JobFiles) { @@ -234,21 +236,21 @@ void restore_cleanup(JCR *jcr, int TermCode) case JS_FatalError: case JS_ErrorTerminated: term_msg = _("*** Restore Error ***"); - msg_type = M_ERROR; /* Generate error message */ + msg_type = M_ERROR; /* Generate error message */ if (jcr->store_bsock) { - bnet_sig(jcr->store_bsock, BNET_TERMINATE); - if (jcr->SD_msg_chan) { - pthread_cancel(jcr->SD_msg_chan); - } + bnet_sig(jcr->store_bsock, BNET_TERMINATE); + if (jcr->SD_msg_chan) { + pthread_cancel(jcr->SD_msg_chan); + } } break; case JS_Canceled: term_msg = _("Restore Canceled"); if (jcr->store_bsock) { - bnet_sig(jcr->store_bsock, BNET_TERMINATE); - if (jcr->SD_msg_chan) { - pthread_cancel(jcr->SD_msg_chan); - } + bnet_sig(jcr->store_bsock, BNET_TERMINATE); + if (jcr->SD_msg_chan) { + pthread_cancel(jcr->SD_msg_chan); + } } break; default: @@ -284,20 +286,20 @@ void restore_cleanup(JCR *jcr, int TermCode) " FD termination status: %s\n" " SD termination status: %s\n" " Termination: %s\n\n"), - edt, - jcr->jr.JobId, - jcr->jr.Job, - jcr->client->hdr.name, - sdt, - edt, - edit_uint64_with_commas((uint64_t)jcr->ExpectedFiles, ec1), - edit_uint64_with_commas((uint64_t)jcr->jr.JobFiles, ec2), - edit_uint64_with_commas(jcr->jr.JobBytes, ec3), - (float)kbps, - jcr->Errors, - fd_term_msg, - sd_term_msg, - term_msg); + edt, + jcr->jr.JobId, + jcr->jr.Job, + jcr->client->hdr.name, + sdt, + edt, + edit_uint64_with_commas((uint64_t)jcr->ExpectedFiles, ec1), + edit_uint64_with_commas((uint64_t)jcr->jr.JobFiles, ec2), + edit_uint64_with_commas(jcr->jr.JobBytes, ec3), + (float)kbps, + jcr->Errors, + fd_term_msg, + sd_term_msg, + term_msg); Dmsg0(20, "Leaving restore_cleanup\n"); } diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 98bf738c98..dc3db1a422 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -29,9 +29,9 @@ #endif extern char my_name[]; -extern CLIENT *me; /* our client resource */ +extern CLIENT *me; /* our client resource */ -int enable_vss = 0; /* set to use vss */ +int enable_vss = 0; /* set to use vss */ /* Imported functions */ extern int status_cmd(JCR *jcr); @@ -90,7 +90,7 @@ static struct s_cmds cmds[] = { {"bootstrap", bootstrap_cmd, 0}, {"RunBeforeJob", runbefore_cmd, 0}, {"RunAfterJob", runafter_cmd, 0}, - {NULL, NULL} /* list terminator */ + {NULL, NULL} /* list terminator */ }; /* Commands received from director that need scanning */ @@ -183,37 +183,37 @@ void *handle_client_request(void *dirp) /* Read command */ if (bnet_recv(dir) < 0) { - break; /* connection terminated */ + break; /* connection terminated */ } dir->msg[dir->msglen] = 0; Dmsg1(100, "msg); found = false; for (i=0; cmds[i].cmd; i++) { - if (strncmp(cmds[i].cmd, dir->msg, strlen(cmds[i].cmd)) == 0) { - found = true; /* indicate command found */ - if (!jcr->authenticated && cmds[i].func != hello_cmd) { - bnet_fsend(dir, no_auth); - bnet_sig(dir, BNET_EOD); - break; - } - if ((jcr->authenticated) && (!cmds[i].monitoraccess) && (jcr->director->monitor)) { + if (strncmp(cmds[i].cmd, dir->msg, strlen(cmds[i].cmd)) == 0) { + found = true; /* indicate command found */ + if (!jcr->authenticated && cmds[i].func != hello_cmd) { + bnet_fsend(dir, no_auth); + bnet_sig(dir, BNET_EOD); + break; + } + if ((jcr->authenticated) && (!cmds[i].monitoraccess) && (jcr->director->monitor)) { Dmsg1(100, "Command %s illegal.\n", cmds[i].cmd); - bnet_fsend(dir, illegal_cmd); - bnet_sig(dir, BNET_EOD); - break; - } + bnet_fsend(dir, illegal_cmd); + bnet_sig(dir, BNET_EOD); + break; + } Dmsg1(100, "Executing %s command.\n", cmds[i].cmd); - if (!cmds[i].func(jcr)) { /* do command */ - quit = true; /* error or fully terminated, get out */ + if (!cmds[i].func(jcr)) { /* do command */ + quit = true; /* error or fully terminated, get out */ Dmsg1(20, "Quit command loop. Canceled=%d\n", job_canceled(jcr)); - } - break; - } + } + break; + } } - if (!found) { /* command not found */ - bnet_fsend(dir, errmsg); - quit = true; - break; + if (!found) { /* command not found */ + bnet_fsend(dir, errmsg); + quit = true; + break; } } @@ -227,7 +227,7 @@ void *handle_client_request(void *dirp) } generate_daemon_event(jcr, "JobEnd"); - dequeue_messages(jcr); /* send any queued messages */ + dequeue_messages(jcr); /* send any queued messages */ /* Inform Director that we are done */ bnet_sig(dir, BNET_TERMINATE); @@ -239,48 +239,48 @@ void *handle_client_request(void *dirp) int i, j, k; /* Delete FileSet Include lists */ for (i=0; iinclude_list.size(); i++) { - findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i); - for (j=0; jopts_list.size(); j++) { - findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); - for (k=0; kregex.size(); k++) { - regfree((regex_t *)fo->regex.get(k)); - } - fo->regex.destroy(); - fo->regexdir.destroy(); - fo->regexfile.destroy(); - fo->wild.destroy(); - fo->wilddir.destroy(); - fo->wildfile.destroy(); - fo->base.destroy(); - fo->fstype.destroy(); - if (fo->reader) { - free(fo->reader); - } - if (fo->writer) { - free(fo->writer); - } - } - incexe->opts_list.destroy(); - incexe->name_list.destroy(); + findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i); + for (j=0; jopts_list.size(); j++) { + findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); + for (k=0; kregex.size(); k++) { + regfree((regex_t *)fo->regex.get(k)); + } + fo->regex.destroy(); + fo->regexdir.destroy(); + fo->regexfile.destroy(); + fo->wild.destroy(); + fo->wilddir.destroy(); + fo->wildfile.destroy(); + fo->base.destroy(); + fo->fstype.destroy(); + if (fo->reader) { + free(fo->reader); + } + if (fo->writer) { + free(fo->writer); + } + } + incexe->opts_list.destroy(); + incexe->name_list.destroy(); } fileset->include_list.destroy(); /* Delete FileSet Exclude lists */ for (i=0; iexclude_list.size(); i++) { - findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i); - for (j=0; jopts_list.size(); j++) { - findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); - fo->regex.destroy(); - fo->regexdir.destroy(); - fo->regexfile.destroy(); - fo->wild.destroy(); - fo->wilddir.destroy(); - fo->wildfile.destroy(); - fo->base.destroy(); - fo->fstype.destroy(); - } - incexe->opts_list.destroy(); - incexe->name_list.destroy(); + findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i); + for (j=0; jopts_list.size(); j++) { + findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); + fo->regex.destroy(); + fo->regexdir.destroy(); + fo->regexfile.destroy(); + fo->wild.destroy(); + fo->wilddir.destroy(); + fo->wildfile.destroy(); + fo->base.destroy(); + fo->fstype.destroy(); + } + incexe->opts_list.destroy(); + incexe->name_list.destroy(); } fileset->exclude_list.destroy(); free(fileset); @@ -290,7 +290,7 @@ void *handle_client_request(void *dirp) term_find_files((FF_PKT *)jcr->ff); jcr->ff = NULL; Dmsg0(100, "Done with term_find_files\n"); - free_jcr(jcr); /* destroy JCR record */ + free_jcr(jcr); /* destroy JCR record */ Dmsg0(100, "Done with free_jcr\n"); return NULL; } @@ -323,20 +323,20 @@ static int cancel_cmd(JCR *jcr) if (!(cjcr=get_jcr_by_full_name(Job))) { bnet_fsend(dir, "2901 Job %s not found.\n", Job); } else { - if (cjcr->store_bsock) { - P(cjcr->mutex); - cjcr->store_bsock->timed_out = 1; - cjcr->store_bsock->terminated = 1; + if (cjcr->store_bsock) { + P(cjcr->mutex); + cjcr->store_bsock->timed_out = 1; + cjcr->store_bsock->terminated = 1; /* * #if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) */ #if !defined(HAVE_CYGWIN) - pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL); + pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL); #endif - V(cjcr->mutex); - } - set_jcr_job_status(cjcr, JS_Canceled); - free_jcr(cjcr); + V(cjcr->mutex); + } + set_jcr_job_status(cjcr, JS_Canceled); + free_jcr(cjcr); bnet_fsend(dir, _("2001 Job %s marked to be canceled.\n"), Job); } } else { @@ -396,8 +396,8 @@ static int job_cmd(JCR *jcr) sd_auth_key = get_memory(dir->msglen); if (sscanf(dir->msg, jobcmd, &jcr->JobId, jcr->Job, - &jcr->VolSessionId, &jcr->VolSessionTime, - sd_auth_key) != 5) { + &jcr->VolSessionId, &jcr->VolSessionTime, + sd_auth_key) != 5) { pm_strcpy(jcr->errmsg, dir->msg); Jmsg(jcr, M_FATAL, 0, _("Bad Job Command: %s"), jcr->errmsg); bnet_fsend(dir, BADjob); @@ -474,13 +474,13 @@ static bool run_cmd(JCR *jcr, char *cmd, const char *name) if (bpipe == NULL) { berrno be; Jmsg(jcr, M_FATAL, 0, _("%s could not execute. ERR=%s\n"), name, - be.strerror()); + be.strerror()); return false; } while (fgets(line, sizeof(line), bpipe->rfd)) { int len = strlen(line); if (len > 0 && line[len-1] == '\n') { - line[len-1] = 0; + line[len-1] = 0; } Jmsg(jcr, M_INFO, 0, _("%s: %s\n"), name, line); } @@ -488,7 +488,7 @@ static bool run_cmd(JCR *jcr, char *cmd, const char *name) if (status != 0) { berrno be; Jmsg(jcr, M_FATAL, 0, _("%s returned non-zero status=%d. ERR=%s\n"), name, - status, be.strerror(status)); + status, be.strerror(status)); return false; } return true; @@ -557,39 +557,39 @@ static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *filese ch = (uint8_t)*p; switch (ch) { case '|': - p++; /* skip over | */ + p++; /* skip over | */ fn = get_pool_memory(PM_FNAME); fn = edit_job_codes(jcr, fn, p, ""); bpipe = open_bpipe(fn, 0, "r"); free_pool_memory(fn); if (!bpipe) { Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"), - p, strerror(errno)); - return; + p, strerror(errno)); + return; } while (fgets(buf, sizeof(buf), bpipe->rfd)) { - strip_trailing_junk(buf); - fileset->incexe->name_list.append(bstrdup(buf)); + strip_trailing_junk(buf); + fileset->incexe->name_list.append(bstrdup(buf)); } if ((stat=close_bpipe(bpipe)) != 0) { Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"), - p, stat, strerror(errno)); - return; + p, stat, strerror(errno)); + return; } break; case '<': Dmsg0(100, "Doing < include on client.\n"); - p++; /* skip over < */ + p++; /* skip over < */ if ((ffd = fopen(p, "r")) == NULL) { - berrno be; + berrno be; Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"), - p, be.strerror()); - return; + p, be.strerror()); + return; } while (fgets(buf, sizeof(buf), ffd)) { - strip_trailing_junk(buf); + strip_trailing_junk(buf); Dmsg1(100, "%s\n", buf); - fileset->incexe->name_list.append(bstrdup(buf)); + fileset->incexe->name_list.append(bstrdup(buf)); } fclose(ffd); break; @@ -668,27 +668,27 @@ static void add_fileset(JCR *jcr, const char *item) char prbuf[500]; preg = (regex_t *)malloc(sizeof(regex_t)); if (current_opts->flags & FO_IGNORECASE) { - rc = regcomp(preg, item, REG_EXTENDED|REG_ICASE); + rc = regcomp(preg, item, REG_EXTENDED|REG_ICASE); } else { - rc = regcomp(preg, item, REG_EXTENDED); + rc = regcomp(preg, item, REG_EXTENDED); } if (rc != 0) { - regerror(rc, preg, prbuf, sizeof(prbuf)); - regfree(preg); - free(preg); + regerror(rc, preg, prbuf, sizeof(prbuf)); + regfree(preg); + free(preg); Jmsg(jcr, M_FATAL, 0, "REGEX %s compile error. ERR=%s\n", item, prbuf); - state = state_error; - break; + state = state_error; + break; } state = state_options; if (subcode == ' ') { - current_opts->regex.append(preg); + current_opts->regex.append(preg); } else if (subcode == 'D') { - current_opts->regexdir.append(preg); + current_opts->regexdir.append(preg); } else if (subcode == 'F') { - current_opts->regexfile.append(preg); + current_opts->regexfile.append(preg); } else { - state = state_error; + state = state_error; } break; case 'B': @@ -705,13 +705,13 @@ static void add_fileset(JCR *jcr, const char *item) current_opts = start_options(ff); state = state_options; if (subcode == ' ') { - current_opts->wild.append(bstrdup(item)); + current_opts->wild.append(bstrdup(item)); } else if (subcode == 'D') { - current_opts->wilddir.append(bstrdup(item)); + current_opts->wilddir.append(bstrdup(item)); } else if (subcode == 'F') { - current_opts->wildfile.append(bstrdup(item)); + current_opts->wildfile.append(bstrdup(item)); } else { - state = state_error; + state = state_error; } break; case 'O': @@ -747,37 +747,37 @@ static bool term_fileset(JCR *jcr) findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i); Dmsg0(400, "I\n"); for (j=0; jopts_list.size(); j++) { - findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); - for (k=0; kregex.size(); k++) { + findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); + for (k=0; kregex.size(); k++) { Dmsg1(400, "R %s\n", (char *)fo->regex.get(k)); - } - for (k=0; kregexdir.size(); k++) { + } + for (k=0; kregexdir.size(); k++) { Dmsg1(400, "RD %s\n", (char *)fo->regexdir.get(k)); - } - for (k=0; kregexfile.size(); k++) { + } + for (k=0; kregexfile.size(); k++) { Dmsg1(400, "RF %s\n", (char *)fo->regexfile.get(k)); - } - for (k=0; kwild.size(); k++) { + } + for (k=0; kwild.size(); k++) { Dmsg1(400, "W %s\n", (char *)fo->wild.get(k)); - } - for (k=0; kwilddir.size(); k++) { + } + for (k=0; kwilddir.size(); k++) { Dmsg1(400, "WD %s\n", (char *)fo->wilddir.get(k)); - } - for (k=0; kwildfile.size(); k++) { + } + for (k=0; kwildfile.size(); k++) { Dmsg1(400, "WF %s\n", (char *)fo->wildfile.get(k)); - } - for (k=0; kbase.size(); k++) { + } + for (k=0; kbase.size(); k++) { Dmsg1(400, "B %s\n", (char *)fo->base.get(k)); - } - for (k=0; kfstype.size(); k++) { + } + for (k=0; kfstype.size(); k++) { Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k)); - } - if (fo->reader) { + } + if (fo->reader) { Dmsg1(400, "D %s\n", fo->reader); - } - if (fo->writer) { + } + if (fo->writer) { Dmsg1(400, "T %s\n", fo->writer); - } + } } for (j=0; jname_list.size(); j++) { Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j)); @@ -787,31 +787,31 @@ static bool term_fileset(JCR *jcr) findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i); Dmsg0(400, "E\n"); for (j=0; jopts_list.size(); j++) { - findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); - for (k=0; kregex.size(); k++) { + findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); + for (k=0; kregex.size(); k++) { Dmsg1(400, "R %s\n", (char *)fo->regex.get(k)); - } - for (k=0; kregexdir.size(); k++) { + } + for (k=0; kregexdir.size(); k++) { Dmsg1(400, "RD %s\n", (char *)fo->regexdir.get(k)); - } - for (k=0; kregexfile.size(); k++) { + } + for (k=0; kregexfile.size(); k++) { Dmsg1(400, "RF %s\n", (char *)fo->regexfile.get(k)); - } - for (k=0; kwild.size(); k++) { + } + for (k=0; kwild.size(); k++) { Dmsg1(400, "W %s\n", (char *)fo->wild.get(k)); - } - for (k=0; kwilddir.size(); k++) { + } + for (k=0; kwilddir.size(); k++) { Dmsg1(400, "WD %s\n", (char *)fo->wilddir.get(k)); - } - for (k=0; kwildfile.size(); k++) { + } + for (k=0; kwildfile.size(); k++) { Dmsg1(400, "WF %s\n", (char *)fo->wildfile.get(k)); - } - for (k=0; kbase.size(); k++) { + } + for (k=0; kbase.size(); k++) { Dmsg1(400, "B %s\n", (char *)fo->base.get(k)); - } - for (k=0; kfstype.size(); k++) { + } + for (k=0; kfstype.size(); k++) { Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k)); - } + } } for (j=0; jname_list.size(); j++) { Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j)); @@ -835,72 +835,72 @@ static void set_options(findFOPTS *fo, const char *opts) switch (*p) { case 'a': /* alway replace */ case '0': /* no option */ - break; + break; case 'e': - fo->flags |= FO_EXCLUDE; - break; + fo->flags |= FO_EXCLUDE; + break; case 'f': - fo->flags |= FO_MULTIFS; - break; + fo->flags |= FO_MULTIFS; + break; case 'h': /* no recursion */ - fo->flags |= FO_NO_RECURSION; - break; + fo->flags |= FO_NO_RECURSION; + break; case 'H': /* no hard link handling */ - fo->flags |= FO_NO_HARDLINK; - break; + fo->flags |= FO_NO_HARDLINK; + break; case 'i': - fo->flags |= FO_IGNORECASE; - break; + fo->flags |= FO_IGNORECASE; + break; case 'M': /* MD5 */ - fo->flags |= FO_MD5; - break; + fo->flags |= FO_MD5; + break; case 'n': - fo->flags |= FO_NOREPLACE; - break; + fo->flags |= FO_NOREPLACE; + break; case 'p': /* use portable data format */ - fo->flags |= FO_PORTABLE; - break; + fo->flags |= FO_PORTABLE; + break; case 'R': /* Resource forks and Finder Info */ - fo->flags |= FO_HFSPLUS; + fo->flags |= FO_HFSPLUS; case 'r': /* read fifo */ - fo->flags |= FO_READFIFO; - break; + fo->flags |= FO_READFIFO; + break; case 'S': - fo->flags |= FO_SHA1; - break; + fo->flags |= FO_SHA1; + break; case 's': - fo->flags |= FO_SPARSE; - break; + fo->flags |= FO_SPARSE; + break; case 'm': - fo->flags |= FO_MTIMEONLY; - break; + fo->flags |= FO_MTIMEONLY; + break; case 'k': - fo->flags |= FO_KEEPATIME; - break; + fo->flags |= FO_KEEPATIME; + break; case 'A': - fo->flags |= FO_ACL; - break; + fo->flags |= FO_ACL; + break; case 'V': /* verify options */ - /* Copy Verify Options */ + /* Copy Verify Options */ for (j=0; *p && *p != ':'; p++) { - fo->VerifyOpts[j] = *p; - if (j < (int)sizeof(fo->VerifyOpts) - 1) { - j++; - } - } - fo->VerifyOpts[j] = 0; - break; + fo->VerifyOpts[j] = *p; + if (j < (int)sizeof(fo->VerifyOpts) - 1) { + j++; + } + } + fo->VerifyOpts[j] = 0; + break; case 'w': - fo->flags |= FO_IF_NEWER; - break; + fo->flags |= FO_IF_NEWER; + break; case 'Z': /* gzip compression */ - fo->flags |= FO_GZIP; + fo->flags |= FO_GZIP; fo->GZIP_level = *++p - '0'; Dmsg1(200, "Compression level=%d\n", fo->GZIP_level); - break; + break; default: Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *p); - break; + break; } } } @@ -931,6 +931,15 @@ static int fileset_cmd(JCR *jcr) return bnet_fsend(dir, OKinc); } +static void free_bootstrap(JCR *jcr) +{ + if (jcr->RestoreBootstrap) { + unlink(jcr->RestoreBootstrap); + free_pool_memory(jcr->RestoreBootstrap); + jcr->RestoreBootstrap = NULL; + } +} + /* * The Director sends us the bootstrap file, which @@ -942,10 +951,7 @@ static int bootstrap_cmd(JCR *jcr) POOLMEM *fname = get_pool_memory(PM_FNAME); FILE *bs; - if (jcr->RestoreBootstrap) { - unlink(jcr->RestoreBootstrap); - free_pool_memory(jcr->RestoreBootstrap); - } + free_bootstrap(jcr); Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name, jcr->Job); Dmsg1(400, "bootstrap=%s\n", fname); @@ -953,17 +959,15 @@ static int bootstrap_cmd(JCR *jcr) bs = fopen(fname, "a+"); /* create file */ if (!bs) { berrno be; + Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"), + jcr->RestoreBootstrap, be.strerror()); /* * Suck up what he is sending to us so that he will then * read our error message. */ while (bnet_recv(dir) >= 0) - { } - - Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"), - jcr->RestoreBootstrap, be.strerror()); - free_pool_memory(jcr->RestoreBootstrap); - jcr->RestoreBootstrap = NULL; + { } + free_bootstrap(jcr); set_jcr_job_status(jcr, JS_ErrorTerminated); return 0; } @@ -973,7 +977,10 @@ static int bootstrap_cmd(JCR *jcr) fputs(dir->msg, bs); } fclose(bs); - + /* + * Note, do not free the bootstrap yet -- it needs to be + * sent to the SD + */ return bnet_fsend(dir, OKbootstrap); } @@ -1009,54 +1016,54 @@ static int level_cmd(JCR *jcr) return 1; /* * We get his UTC since time, then sync the clocks and correct it - * to agree with our clock. + * to agree with our clock. */ } else if (strcmp(level, "since_utime") == 0) { buf = get_memory(dir->msglen+1); utime_t since_time, adj; btime_t his_time, bt_start, rt=0, bt_adj=0; if (jcr->JobLevel == L_NONE) { - jcr->JobLevel = L_SINCE; /* if no other job level set, do it now */ + jcr->JobLevel = L_SINCE; /* if no other job level set, do it now */ } if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d", - buf, &mtime_only) != 2) { - goto bail_out; + buf, &mtime_only) != 2) { + goto bail_out; } - since_time = str_to_uint64(buf); /* this is the since time */ + since_time = str_to_uint64(buf); /* this is the since time */ char ed1[50], ed2[50]; /* * Sync clocks by polling him for the time. We take * 10 samples of his time throwing out the first two. */ for (int i=0; i<10; i++) { - bt_start = get_current_btime(); - bnet_sig(dir, BNET_BTIME); /* poll for time */ - if (bnet_recv(dir) <= 0) { /* get response */ - goto bail_out; - } + bt_start = get_current_btime(); + bnet_sig(dir, BNET_BTIME); /* poll for time */ + if (bnet_recv(dir) <= 0) { /* get response */ + goto bail_out; + } if (sscanf(dir->msg, "btime %s", buf) != 1) { - goto bail_out; - } - if (i < 2) { /* toss first two results */ - continue; - } - his_time = str_to_uint64(buf); - rt = get_current_btime() - bt_start; /* compute round trip time */ - bt_adj -= his_time - bt_start - rt/2; + goto bail_out; + } + if (i < 2) { /* toss first two results */ + continue; + } + his_time = str_to_uint64(buf); + rt = get_current_btime() - bt_start; /* compute round trip time */ + bt_adj -= his_time - bt_start - rt/2; Dmsg2(200, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2)); } - bt_adj = bt_adj / 8; /* compute average time */ + bt_adj = bt_adj / 8; /* compute average time */ Dmsg2(100, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2)); adj = btime_to_utime(bt_adj); - since_time += adj; /* adjust for clock difference */ + since_time += adj; /* adjust for clock difference */ if (adj != 0) { Jmsg(jcr, M_INFO, 0, _("DIR and FD clocks differ by %d seconds, FD automatically adjusting.\n"), adj); } bnet_sig(dir, BNET_EOD); Dmsg2(100, "adj = %d since_time=%d\n", (int)adj, (int)since_time); - jcr->incremental = 1; /* set incremental or decremental backup */ + jcr->incremental = 1; /* set incremental or decremental backup */ jcr->mtime = (time_t)since_time; /* set since time */ } else { Jmsg1(jcr, M_FATAL, 0, "Unknown backup level: %s\n", level); @@ -1088,9 +1095,9 @@ static int session_cmd(JCR *jcr) Dmsg1(100, "SessionCmd: %s", dir->msg); if (sscanf(dir->msg, sessioncmd, jcr->VolumeName, - &jcr->VolSessionId, &jcr->VolSessionTime, - &jcr->StartFile, &jcr->EndFile, - &jcr->StartBlock, &jcr->EndBlock) != 7) { + &jcr->VolSessionId, &jcr->VolSessionTime, + &jcr->StartFile, &jcr->EndFile, + &jcr->StartBlock, &jcr->EndBlock) != 7) { pm_strcpy(jcr->errmsg, dir->msg); Jmsg(jcr, M_FATAL, 0, "Bad session command: %s", jcr->errmsg); return 0; @@ -1105,10 +1112,10 @@ static int session_cmd(JCR *jcr) */ static int storage_cmd(JCR *jcr) { - int stored_port; /* storage daemon port */ - int enable_ssl; /* enable ssl to sd */ + int stored_port; /* storage daemon port */ + int enable_ssl; /* enable ssl to sd */ BSOCK *dir = jcr->dir_bsock; - BSOCK *sd; /* storage daemon bsock */ + BSOCK *sd; /* storage daemon bsock */ Dmsg1(100, "StorageCmd: %s", dir->msg); if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port, &enable_ssl) != 3) { @@ -1120,12 +1127,12 @@ static int storage_cmd(JCR *jcr) /* Open command communications with Storage daemon */ /* Try to connect for 1 hour at 10 second intervals */ sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"), - jcr->stored_addr, NULL, stored_port, 1); + jcr->stored_addr, NULL, stored_port, 1); if (sd == NULL) { Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"), - jcr->stored_addr, stored_port); + jcr->stored_addr, stored_port); Dmsg2(100, "Failed to connect to Storage daemon: %s:%d\n", - jcr->stored_addr, stored_port); + jcr->stored_addr, stored_port); return 0; } Dmsg0(110, "Connection OK to SD.\n"); @@ -1179,7 +1186,7 @@ static int backup_cmd(JCR *jcr) Dmsg1(110, "msg); if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) { Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg); - goto cleanup; + goto cleanup; } Dmsg1(110, "Got Ticket=%d\n", jcr->Ticket); } else { @@ -1207,31 +1214,31 @@ static int backup_cmd(JCR *jcr) /* START VSS ON WIN 32 */ if (g_pVSSClient && enable_vss == 1) { if (g_pVSSClient->InitializeForBackup()) { - /* tell vss which drives to snapshot */ - char szWinDriveLetters[27]; - if (get_win32_driveletters((FF_PKT *)jcr->ff, szWinDriveLetters)) { + /* tell vss which drives to snapshot */ + char szWinDriveLetters[27]; + if (get_win32_driveletters((FF_PKT *)jcr->ff, szWinDriveLetters)) { Jmsg(jcr, M_INFO, 0, _("Generate VSS snapshots. Driver=\"%s\", Drive(s)=\"%s\"\n"), g_pVSSClient->GetDriverName(), szWinDriveLetters); - if (!g_pVSSClient->CreateSnapshots(szWinDriveLetters)) { + if (!g_pVSSClient->CreateSnapshots(szWinDriveLetters)) { Jmsg(jcr, M_WARNING, 0, _("Generate VSS snapshots failed\n")); - } - else { - /* tell user if snapshot creation of a specific drive failed */ - size_t i; - for (i=0; iGetWriterCount(); i++) { - int msg_type = M_INFO; - if (g_pVSSClient->GetWriterState(i) < 0) - msg_type = M_WARNING; + } + /* inform user about writer states */ + for (i=0; iGetWriterCount(); i++) { + int msg_type = M_INFO; + if (g_pVSSClient->GetWriterState(i) < 0) + msg_type = M_WARNING; Jmsg(jcr, msg_type, 0, _("VSS Writer: %s\n"), g_pVSSClient->GetWriterInfo(i)); - } - } - } + } + } + } } else { Jmsg(jcr, M_WARNING, 0, _("VSS was not initialized properly. VSS support is disabled.\n")); } @@ -1245,20 +1252,20 @@ static int backup_cmd(JCR *jcr) if (!blast_data_to_storage_daemon(jcr, NULL)) { set_jcr_job_status(jcr, JS_ErrorTerminated); bnet_suppress_error_messages(sd, 1); - bget_msg(sd); /* Read final response from append_data */ + bget_msg(sd); /* Read final response from append_data */ Dmsg0(110, "Error in blast_data.\n"); } else { set_jcr_job_status(jcr, JS_Terminated); if (jcr->JobStatus != JS_Terminated) { - bnet_suppress_error_messages(sd, 1); - goto cleanup; /* bail out now */ + 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")) { - set_jcr_job_status(jcr, JS_ErrorTerminated); - goto cleanup; + set_jcr_job_status(jcr, JS_ErrorTerminated); + goto cleanup; } /* @@ -1267,8 +1274,8 @@ static int backup_cmd(JCR *jcr) bnet_fsend(sd, append_end, jcr->Ticket); /* Get end OK */ if (!response(jcr, sd, OK_end, "Append End")) { - set_jcr_job_status(jcr, JS_ErrorTerminated); - goto cleanup; + set_jcr_job_status(jcr, JS_ErrorTerminated); + goto cleanup; } /* @@ -1276,18 +1283,18 @@ static int backup_cmd(JCR *jcr) */ bnet_fsend(sd, append_close, jcr->Ticket); while (bget_msg(sd) >= 0) { /* stop on signal or error */ - if (sscanf(sd->msg, OK_close, &SDJobStatus) == 1) { - ok = 1; + if (sscanf(sd->msg, OK_close, &SDJobStatus) == 1) { + ok = 1; Dmsg2(200, "SDJobStatus = %d %c\n", SDJobStatus, (char)SDJobStatus); - } + } } if (!ok) { Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n")); - goto cleanup; + goto cleanup; } if (SDJobStatus != JS_Terminated) { Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"), - SDJobStatus); + SDJobStatus); } } @@ -1304,7 +1311,7 @@ cleanup: edit_uint64(jcr->JobBytes, ed2), jcr->Errors); Dmsg1(110, "End FD msg: %s\n", dir->msg); - return 0; /* return and stop command loop */ + return 0; /* return and stop command loop */ } /* @@ -1351,7 +1358,7 @@ static int verify_cmd(JCR *jcr) break; case L_VERIFY_VOLUME_TO_CATALOG: if (!open_sd_read_session(jcr)) { - return 0; + return 0; } start_dir_heartbeat(jcr); do_verify_volume(jcr); @@ -1363,7 +1370,7 @@ static int verify_cmd(JCR *jcr) Dmsg1(130, "bfiled>stored: %s", sd->msg); /* ****FIXME**** check response */ - bget_msg(sd); /* get OK */ + bget_msg(sd); /* get OK */ /* Inform Storage daemon that we are done */ bnet_sig(sd, BNET_TERMINATE); @@ -1386,7 +1393,7 @@ static int verify_cmd(JCR *jcr) /* Inform Director that we are done */ bnet_sig(dir, BNET_TERMINATE); - return 0; /* return and terminate command loop */ + return 0; /* return and terminate command loop */ } /* @@ -1412,9 +1419,9 @@ static int restore_cmd(JCR *jcr) if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, where) != 3) { if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) { - pm_strcpy(jcr->errmsg, dir->msg); + pm_strcpy(jcr->errmsg, dir->msg); Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg); - return 0; + return 0; } *where = 0; } @@ -1463,7 +1470,7 @@ static int restore_cmd(JCR *jcr) bnet_fsend(sd, read_close, jcr->Ticket); Dmsg1(130, "bfiled>stored: %s", sd->msg); - bget_msg(sd); /* get OK */ + bget_msg(sd); /* get OK */ /* Inform Storage daemon that we are done */ bnet_sig(sd, BNET_TERMINATE); @@ -1482,7 +1489,7 @@ bail_out: bnet_sig(dir, BNET_TERMINATE); Dmsg0(130, "Done in job.c\n"); - return 0; /* return and terminate command loop */ + return 0; /* return and terminate command loop */ } static int open_sd_read_session(JCR *jcr) @@ -1511,7 +1518,7 @@ static int open_sd_read_session(JCR *jcr) Dmsg1(110, "bfiledmsg); if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) { Jmsg(jcr, M_FATAL, 0, _("Bad response to SD read open: %s\n"), sd->msg); - return 0; + return 0; } Dmsg1(110, "bfiled: got Ticket=%d\n", jcr->Ticket); } else { @@ -1547,11 +1554,7 @@ static void filed_free_jcr(JCR *jcr) if (jcr->store_bsock) { bnet_close(jcr->store_bsock); } - if (jcr->RestoreBootstrap) { - unlink(jcr->RestoreBootstrap); - free_pool_memory(jcr->RestoreBootstrap); - jcr->RestoreBootstrap = NULL; - } + free_bootstrap(jcr); if (jcr->last_fname) { free_pool_memory(jcr->last_fname); } @@ -1568,7 +1571,7 @@ static void filed_free_jcr(JCR *jcr) * sent. Check that the response is OK. * * Returns: 0 on failure - * 1 on success + * 1 on success */ int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd) { @@ -1578,18 +1581,18 @@ int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd) if (bget_msg(sd) > 0) { Dmsg0(110, sd->msg); if (strcmp(sd->msg, resp) == 0) { - return 1; + return 1; } } if (job_canceled(jcr)) { - return 0; /* if canceled avoid useless error messages */ + return 0; /* if canceled avoid useless error messages */ } if (is_bnet_error(sd)) { Jmsg2(jcr, M_FATAL, 0, _("Comm error with SD. bad response to %s. ERR=%s\n"), - cmd, bnet_strerror(sd)); + cmd, bnet_strerror(sd)); } else { Jmsg3(jcr, M_FATAL, 0, _("Bad response to %s command. Wanted %s, got %s\n"), - cmd, resp, sd->msg); + cmd, resp, sd->msg); } return 0; } @@ -1610,7 +1613,7 @@ static int send_bootstrap_file(JCR *jcr) if (!bs) { berrno be; Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"), - jcr->RestoreBootstrap, be.strerror()); + jcr->RestoreBootstrap, be.strerror()); set_jcr_job_status(jcr, JS_ErrorTerminated); goto bail_out; } @@ -1629,11 +1632,6 @@ static int send_bootstrap_file(JCR *jcr) stat = 1; bail_out: - if (jcr->RestoreBootstrap) { - unlink(jcr->RestoreBootstrap); - free_pool_memory(jcr->RestoreBootstrap); - jcr->RestoreBootstrap = NULL; - } - + free_bootstrap(jcr); return stat; } -- 2.39.5