From: Kern Sibbald Date: Sat, 24 Aug 2002 20:18:04 +0000 (+0000) Subject: Make restore work well X-Git-Tag: Release-1.25~23 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=de7fb537edde5d2dd6257b4efc670f331ad30b76;p=bacula%2Fbacula Make restore work well git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@120 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kernstodo b/bacula/kernstodo index 9dd2b382b1..df56c94e79 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -28,6 +28,8 @@ From Chuck: --sd.conf password does not match dir.conf storage password ======= +- In restore job, print some summary information at end, such + as rate, ... job status, ... - After unmount, if restore job started, ask to mount. - Fix db_update_fileset in cats/sql_get.c - Fix start/end blocks for File diff --git a/bacula/src/dird/getmsg.c b/bacula/src/dird/getmsg.c index 9c2022f110..abf81e5d53 100644 --- a/bacula/src/dird/getmsg.c +++ b/bacula/src/dird/getmsg.c @@ -60,6 +60,9 @@ static char OK_msg[] = "1000 OK\n"; * to the appropriate handler. If the message is * in any other format, it will be returned. * + * E.g. any message beginning with a digit will be returned. + * any message beginning with Jmsg will be processed. + * */ int32_t bget_msg(BSOCK *bs, int rtn) { diff --git a/bacula/src/dird/msgchan.c b/bacula/src/dird/msgchan.c index d3a88d7e71..814410d2c6 100644 --- a/bacula/src/dird/msgchan.c +++ b/bacula/src/dird/msgchan.c @@ -104,7 +104,7 @@ int start_storage_daemon_job(JCR *jcr) */ bash_spaces(jcr->job->hdr.name); bash_spaces(jcr->client->hdr.name); - bash_spaces(jcr->client->hdr.name); + bash_spaces(jcr->fileset->hdr.name); bnet_fsend(sd, jobcmd, jcr->JobId, jcr->Job, jcr->job->hdr.name, jcr->client->hdr.name, jcr->JobType, jcr->JobLevel, jcr->fileset->hdr.name, !jcr->pool->catalog_files, diff --git a/bacula/src/dird/restore.c b/bacula/src/dird/restore.c index 464a273638..1cae3457ca 100644 --- a/bacula/src/dird/restore.c +++ b/bacula/src/dird/restore.c @@ -53,6 +53,7 @@ static char OKrestore[] = "2000 OK restore\n"; static char OKstore[] = "2000 OK storage\n"; static char OKsession[] = "2000 OK session\n"; static char OKbootstrap[] = "2000 OK bootstrap\n"; +static char EndJob[] = "2800 End Job TermCode=%d JobFiles=%u JobBytes=%" lld "\n"; /* Forward referenced functions */ static void restore_cleanup(JCR *jcr, int status); @@ -71,6 +72,7 @@ int do_restore(JCR *jcr) char dt[MAX_TIME_LENGTH]; BSOCK *fd; JOB_DBR rjr; /* restore job record */ + int ok = FALSE; if (!get_or_create_client_record(jcr)) { @@ -245,10 +247,14 @@ int do_restore(JCR *jcr) /*** ****FIXME**** get job termination status */ Dmsg0(20, "wait for job termination\n"); while (bget_msg(fd, 0) > 0) { - Dmsg1(0, "dirdmsg); + Dmsg1(100, "dirdmsg); + if (sscanf(fd->msg, EndJob, &jcr->JobStatus, &jcr->JobFiles, + &jcr->JobBytes) == 3) { + ok = TRUE; + } } - restore_cleanup(jcr, JS_Terminated); + restore_cleanup(jcr, ok?jcr->JobStatus:JS_ErrorTerminated); return 1; } @@ -257,18 +263,70 @@ int do_restore(JCR *jcr) * Release resources allocated during restore. * */ -static void restore_cleanup(JCR *jcr, int status) +static void restore_cleanup(JCR *jcr, int TermCode) { - char dt[MAX_TIME_LENGTH]; + char sdt[MAX_TIME_LENGTH], edt[MAX_TIME_LENGTH]; + char ec1[30], ec2[30]; + char term_code[100]; + char *term_msg; + int msg_type; + double kbps; Dmsg0(20, "In restore_cleanup\n"); - jcr->JobStatus = status; + jcr->JobStatus = TermCode; update_job_end_record(jcr); - bstrftime(dt, sizeof(dt), jcr->jr.EndTime); - Jmsg(jcr, M_INFO, 0, _("%s End Restore Job %s.\n\n"), - dt, jcr->Job); + msg_type = M_INFO; /* by default INFO message */ + switch (TermCode) { + case JS_Terminated: + term_msg = _("Restore OK"); + break; + case JS_FatalError: + case JS_ErrorTerminated: + term_msg = _("*** Restore Error ***"); + msg_type = M_ERROR; /* Generate error message */ + if (jcr->store_bsock) { + bnet_sig(jcr->store_bsock, BNET_TERMINATE); + pthread_cancel(jcr->SD_msg_chan); + } + break; + case JS_Cancelled: + term_msg = _("Restore Cancelled"); + if (jcr->store_bsock) { + bnet_sig(jcr->store_bsock, BNET_TERMINATE); + pthread_cancel(jcr->SD_msg_chan); + } + break; + default: + term_msg = term_code; + sprintf(term_code, _("Inappropriate term code: %c\n"), TermCode); + break; + } + bstrftime(sdt, sizeof(sdt), jcr->jr.StartTime); + bstrftime(edt, sizeof(edt), jcr->jr.EndTime); + kbps = (double)jcr->jr.JobBytes / (1000 * (jcr->jr.EndTime - jcr->jr.StartTime)); + + Jmsg(jcr, msg_type, 0, _("%s\n\ +JobId: %d\n\ +Job: %s\n\ +Client: %s\n\ +Start time: %s\n\ +End time: %s\n\ +Files Restored: %s\n\ +Bytes Restored: %s\n\ +Rate: %.1f KB/s\n\ +Termination: %s\n\n"), + edt, + jcr->jr.JobId, + jcr->jr.Job, + jcr->client->hdr.name, + sdt, + edt, + edit_uint64_with_commas(jcr->jr.JobFiles, ec1), + edit_uint64_with_commas(jcr->jr.JobBytes, ec2), + (float)kbps, + term_msg); Dmsg0(20, "Leaving restore_cleanup\n"); } diff --git a/bacula/src/dird/ua_run.c b/bacula/src/dird/ua_run.c index 87b4a8dfaa..63afffc465 100644 --- a/bacula/src/dird/ua_run.c +++ b/bacula/src/dird/ua_run.c @@ -485,8 +485,8 @@ JobId: %s\n"), break; } /* ***FIXME*** allow drive:/ for Windows */ - if (ua->cmd[0] != '/') { - bsendmsg(ua, _("Prefix must begin with a /\n")); + if (ua->cmd[0] != 0 && ua->cmd[0] != '/') { + bsendmsg(ua, _("Prefix must be null or begin with a /\n")); } else { if (jcr->RestoreWhere) { free(jcr->RestoreWhere); diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 2c8e98111c..be261e2061 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -108,6 +108,7 @@ static char OKstore[] = "2000 OK storage\n"; static char OKjob[] = "2000 OK Job\n"; static char OKsetdebug[] = "2000 OK setdebug=%d\n"; static char BADjob[] = "2901 Bad Job\n"; +static char EndJob[] = "2800 End Job TermCode=%d JobFiles=%u JobBytes=%" lld "\n"; /* Responses received from Storage Daemon */ static char OK_end[] = "3000 OK end\n"; @@ -260,7 +261,7 @@ static int estimate_cmd(JCR *jcr) { BSOCK *dir = jcr->dir_bsock; make_estimate(jcr); - return bnet_fsend(dir, OKest, jcr->JobFiles, jcr->JobBytes); + return bnet_fsend(dir, OKest, jcr->num_files_examined, jcr->JobBytes); } /* @@ -698,6 +699,8 @@ static int restore_cmd(JCR *jcr) /* Inform Storage daemon that we are done */ bnet_sig(sd, BNET_TERMINATE); + bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->num_files_examined, jcr->JobBytes); + /* Inform Director that we are done */ bnet_sig(dir, BNET_TERMINATE); diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 6bce564013..67a3e8d6cc 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -279,8 +279,12 @@ void do_restore(JCR *jcr) close(ofd); set_statp(jcr, fname, ofile, lname, type, &statp); } + jcr->JobStatus = JS_Terminated; + goto ok_out; bail_out: + jcr->JobStatus = JS_ErrorTerminated; +ok_out: if (jcr->compress_buf) { free(jcr->compress_buf); jcr->compress_buf = NULL; diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 0433fbdea0..8ec4bb3766 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -157,7 +157,7 @@ int release_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) } else if (dev->num_writers > 0) { dev->num_writers--; - Dmsg1(00, "There are %d writers in release_device\n", dev->num_writers); + Dmsg1(100, "There are %d writers in release_device\n", dev->num_writers); if (dev->num_writers == 0) { weof_dev(dev, 1); Dmsg0(100, "dir_create_jobmedia_record. Release\n"); diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index 011e849588..b2db38f144 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -270,6 +270,7 @@ static void do_setup(char *infname) } pm_strcpy(&jcr->VolumeName, VolName); + Dmsg1(000, "Volume=%s\n", jcr->VolumeName); if (!acquire_device_for_read(jcr, dev, block)) { Emsg0(M_ERROR, 0, dev->errmsg); exit(1); diff --git a/bacula/src/stored/job.c b/bacula/src/stored/job.c index f32535f0d9..68aec7c356 100644 --- a/bacula/src/stored/job.c +++ b/bacula/src/stored/job.c @@ -44,9 +44,9 @@ static char use_device[] = "use device=%s media_type=%s pool_name=%s pool_type=% /* Responses sent to Director daemon */ static char OKjob[] = "3000 OK Job SDid=%u SDtime=%u Authorization=%s\n"; static char OK_device[] = "3000 OK use device\n"; -static char NO_device[] = "3904 Device %s not available\n"; -static char BAD_use[] = "3903 Bad use command: %s\n"; -static char BAD_job[] = "3905 Bad Job command: %s\n"; +static char NO_device[] = "3914 Device %s not available\n"; +static char BAD_use[] = "3913 Bad use command: %s\n"; +static char BAD_job[] = "3915 Bad Job command: %s\n"; diff --git a/bacula/src/stored/read.c b/bacula/src/stored/read.c index f1137ac64f..5f9fdaa931 100644 --- a/bacula/src/stored/read.c +++ b/bacula/src/stored/read.c @@ -109,12 +109,10 @@ int do_read_data(JCR *jcr) } /* Read Record */ Dmsg1(500, "Main read_record. rem=%d\n", rec->remainder); + if (!read_block_from_device(dev, block)) { Dmsg1(500, "Main read record failed. rem=%d\n", rec->remainder); if (dev->state & ST_EOT) { - if (rec->remainder) { - Dmsg0(500, "Not end of record.\n"); - } if (!mount_next_read_volume(jcr, dev, block)) { break; } @@ -131,6 +129,16 @@ int do_read_data(JCR *jcr) for (rec->state=0; !is_block_empty(rec); ) { + if (!read_record_from_block(block, rec)) { + break; + } + /* + * At this point, we have at least a record header. + * Now decide if we want this record or not, but remember + * before accessing the record, we may need to read again to + * get all the data. + */ + /* Some sort of label? */ if (rec->FileIndex < 0) { char *rtype; @@ -163,13 +171,15 @@ int do_read_data(JCR *jcr) Dmsg1(40, "Got label = %d\n", rec->FileIndex); if (rec->FileIndex == EOM_LABEL) { /* end of tape? */ Dmsg0(40, "Get EOM LABEL\n"); + rec->remainder = 0; break; /* yes, get out */ } + rec->remainder = 0; continue; /* ignore other labels */ } /* end if label record */ + /* Match BSR against current record */ if (jcr->bsr) { - /* Match BSR against current record */ if (!match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec)) { Dmsg0(50, "BSR rejected record\n"); rec->remainder = 0; @@ -184,8 +194,9 @@ int do_read_data(JCR *jcr) continue; /* ignore */ } } + if (is_partial_record(rec)) { - break; + break; /* Go read full record */ } /* Generate Header parameters and send to File daemon diff --git a/bacula/src/version.h b/bacula/src/version.h index e7c4762f7e..1c9b489b99 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.25" #define VSTRING "1" -#define DATE "22 August 2002" -#define LSMDATE "22Aug02" +#define DATE "24 August 2002" +#define LSMDATE "24Aug02" /* Debug flags */ #define DEBUG 1