From fb483d8eeab9845b7bcaa77920989758e6e5083c Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 21 Jun 2003 16:45:53 +0000 Subject: [PATCH] First cut of estimate command git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@601 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/ReleaseNotes | 2 +- bacula/src/dird/fd_cmds.c | 2 +- bacula/src/dird/ua_cmds.c | 40 ++++++++++++++++++++++++++++++++++++- bacula/src/filed/estimate.c | 16 ++++++++++----- bacula/src/filed/job.c | 10 ++++++++-- bacula/src/jcr.h | 2 +- 6 files changed, 61 insertions(+), 11 deletions(-) diff --git a/bacula/ReleaseNotes b/bacula/ReleaseNotes index a2bfbb5e4d..cf010afc9c 100644 --- a/bacula/ReleaseNotes +++ b/bacula/ReleaseNotes @@ -1,7 +1,7 @@ Release Notes for Bacula 1.31 - Bacula code: Total files = 250 Total lines = 74,376 (*.h *.c *.in) + Bacula code: Total files = 251 Total lines = 74,587 (*.h *.c *.in) Major Changes this Release: - The database format has changed. Please see below. diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index 0aa9e4ae9b..8f57fe1a46 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -100,7 +100,7 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time, jcr->client->hdr.name, fd->msg); set_jcr_job_status(jcr, JS_ErrorTerminated); return 0; - } else { + } else if (jcr->db) { CLIENT_DBR cr; memset(&cr, 0, sizeof(cr)); bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name)); diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index acd33b5d37..7230bf311f 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -1179,7 +1179,45 @@ static int var_cmd(UAContext *ua, char *cmd) static int estimate_cmd(UAContext *ua, char *cmd) { - bsendmsg(ua, "Not yet implemented\n"); + JOB *job; + BSOCK *fd; + if (ua->argc < 2) { + return 1; + } + job = (JOB *)GetResWithName(R_JOB, ua->argk[1]); + ua->jcr->client = job->client; + bsendmsg(ua, _("Connecting to Client %s at %s:%d\n"), + job->client->hdr.name, job->client->address, job->client->FDport); + if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) { + bsendmsg(ua, _("Failed to connect to Client.\n")); + return 1; + } + fd = ua->jcr->file_bsock; + + if (!send_include_list(ua->jcr)) { + bsendmsg(ua, _("Error sending include list.\n")); + return 1; + } + + if (!send_exclude_list(ua->jcr)) { + bsendmsg(ua, _("Error sending exclude list.\n")); + return 1; + } + + bnet_fsend(fd, "level = full mtime_only=0\n"); + if (bnet_recv(fd) >= 0) { + bsendmsg(ua, "%s", fd->msg); + } + + bnet_fsend(fd, "estimate list=1\n"); + while (bnet_recv(fd) >= 0) { + bsendmsg(ua, "%s", fd->msg); + } + + bnet_sig(fd, BNET_TERMINATE); + bnet_close(fd); + ua->jcr->file_bsock = NULL; + return 1; } diff --git a/bacula/src/filed/estimate.c b/bacula/src/filed/estimate.c index 24d0471717..b25bda0b9b 100644 --- a/bacula/src/filed/estimate.c +++ b/bacula/src/filed/estimate.c @@ -42,7 +42,6 @@ int make_estimate(JCR *jcr) jcr->JobStatus = JS_Running; set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime, jcr->mtime_only); - stat = find_files(jcr, (FF_PKT *)jcr->ff, tally_file, (void *)jcr); return stat; @@ -54,11 +53,11 @@ int make_estimate(JCR *jcr) */ static int tally_file(FF_PKT *ff_pkt, void *ijcr) { - JCR *jcr = (JCR *) ijcr; + JCR *jcr = (JCR *)ijcr; + ATTR attr; switch (ff_pkt->type) { case FT_LNKSAVED: /* Hard linked, file already saved */ - break; case FT_REGE: case FT_REG: case FT_LNK: @@ -84,7 +83,14 @@ static int tally_file(FF_PKT *ff_pkt, void *ijcr) ff_pkt->statp.st_size > 0) { jcr->JobBytes += ff_pkt->statp.st_size; } - - jcr->JobFiles++; /* increment number of files sent */ + jcr->num_files_examined++; + jcr->JobFiles++; /* increment number of files seen */ + if (jcr->listing) { + memcpy(&attr.statp, &ff_pkt->statp, sizeof(struct stat)); + attr.type = ff_pkt->type; + attr.ofname = (POOLMEM *)ff_pkt->fname; + attr.olname = (POOLMEM *)ff_pkt->link; + print_ls_output(jcr, &attr); + } return 1; } diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index b4fdf052e3..6ffa1d7336 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -98,7 +98,7 @@ static char verifycmd[] = "verify level=%30s\n"; static char errmsg[] = "2999 Invalid command\n"; static char no_auth[] = "2998 No Authorization\n"; static char OKinc[] = "2000 OK include\n"; -static char OKest[] = "2000 OK estimate files=%ld bytes=%ld\n"; +static char OKest[] = "2000 OK estimate files=%u bytes=%s\n"; static char OKexc[] = "2000 OK exclude\n"; static char OKlevel[] = "2000 OK level\n"; static char OKbackup[] = "2000 OK backup\n"; @@ -283,8 +283,14 @@ static int setdebug_cmd(JCR *jcr) static int estimate_cmd(JCR *jcr) { BSOCK *dir = jcr->dir_bsock; + char ed2[50]; + + jcr->listing = 1; make_estimate(jcr); - return bnet_fsend(dir, OKest, jcr->num_files_examined, jcr->JobBytes); + bnet_fsend(dir, OKest, jcr->num_files_examined, + edit_uint64(jcr->JobBytes, ed2)); + bnet_sig(dir, BNET_EOD); + return 1; } /* diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 2add1749c9..e8b293d1ed 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -168,7 +168,7 @@ struct JCR { int incremental; /* set if incremental for SINCE */ time_t mtime; /* begin time for SINCE */ int mtime_only; /* compare only mtime and not ctime as well */ - int status; /* job status */ + int listing; /* job listing in estimate */ long Ticket; /* Ticket */ int save_level; /* save level */ char *big_buf; /* I/O buffer */ -- 2.39.5