From: Kern Sibbald Date: Sat, 21 Jun 2003 20:14:58 +0000 (+0000) Subject: Refinements to estimate X-Git-Tag: Release-1.31~53 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4eccc46840b493351da39152971476c8c6fc52a9;p=bacula%2Fbacula Refinements to estimate git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@603 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index a96206f4ce..11d97a4751 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -41,12 +41,10 @@ /* Commands sent to File daemon */ static char backupcmd[] = "backup\n"; static char storaddr[] = "storage address=%s port=%d ssl=%d\n"; -static char levelcmd[] = "level = %s%s mtime_only=%d\n"; /* Responses received from File daemon */ static char OKbackup[] = "2000 OK backup\n"; static char OKstore[] = "2000 OK storage\n"; -static char OKlevel[] = "2000 OK level\n"; static char EndJob[] = "2800 End Job TermCode=%d JobFiles=%u " "ReadBytes=%" lld " JobBytes=%" lld " Errors=%u\n"; @@ -106,31 +104,7 @@ int do_backup(JCR *jcr) Dmsg2(119, "Created FileSet %s record %u\n", jcr->fileset->hdr.name, jcr->jr.FileSetId); - /* Look up the last - * FULL backup job to get the time/date for a - * differential or incremental save. - */ - jcr->stime = get_pool_memory(PM_MESSAGE); - jcr->stime[0] = 0; - since[0] = 0; - switch (jcr->JobLevel) { - case L_DIFFERENTIAL: - case L_INCREMENTAL: - /* Look up start time of last job */ - jcr->jr.JobId = 0; - if (!db_find_job_start_time(jcr, jcr->db, &jcr->jr, &jcr->stime)) { - Jmsg(jcr, M_INFO, 0, "%s", db_strerror(jcr->db)); - Jmsg(jcr, M_INFO, 0, _("No prior or suitable Full backup found. Doing FULL backup.\n")); - bsnprintf(since, sizeof(since), " (upgraded from %s)", - level_to_str(jcr->jr.Level)); - jcr->JobLevel = jcr->jr.Level = L_FULL; - } else { - bstrncpy(since, ", since=", sizeof(since)); - bstrncat(since, jcr->stime, sizeof(since)); - } - Dmsg1(115, "Last start time = %s\n", jcr->stime); - break; - } + get_level_since_time(jcr, since, sizeof(since)); jcr->jr.JobId = jcr->JobId; jcr->jr.StartTime = jcr->start_time; @@ -219,28 +193,8 @@ int do_backup(JCR *jcr) goto bail_out; } - /* - * Send Level command to File daemon - */ - switch (jcr->JobLevel) { - case L_BASE: - bnet_fsend(fd, levelcmd, "base", " ", 0); - break; - case L_FULL: - bnet_fsend(fd, levelcmd, "full", " ", 0); - break; - case L_DIFFERENTIAL: - case L_INCREMENTAL: - bnet_fsend(fd, levelcmd, "since ", jcr->stime, 0); - break; - case L_SINCE: - default: - Jmsg2(jcr, M_FATAL, 0, _("Unimplemented backup level %d %c\n"), - jcr->JobLevel, jcr->JobLevel); - goto bail_out; - } - Dmsg1(120, ">filed: %s", fd->msg); - if (!response(jcr, fd, OKlevel, "Level", DISPLAY_ERROR)) { + + if (!send_level_command(jcr)) { goto bail_out; } diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index 8f57fe1a46..8323a21a88 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -39,6 +39,7 @@ static char inc[] = "include\n"; static char exc[] = "exclude\n"; static char jobcmd[] = "JobId=%d Job=%s SDid=%u SDtime=%u Authorization=%s\n"; +static char levelcmd[] = "level = %s%s mtime_only=%d\n"; /* Responses received from File daemon */ @@ -46,6 +47,7 @@ static char OKinc[] = "2000 OK include\n"; static char OKexc[] = "2000 OK exclude\n"; static char OKjob[] = "2000 OK Job"; static char OKbootstrap[] = "2000 OK bootstrap\n"; +static char OKlevel[] = "2000 OK level\n"; /* Forward referenced functions */ @@ -123,6 +125,72 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time, } +void get_level_since_time(JCR *jcr, char *since, int since_len) +{ + /* Lookup the last + * FULL backup job to get the time/date for a + * differential or incremental save. + */ + if (!jcr->stime) { + jcr->stime = get_pool_memory(PM_MESSAGE); + } + jcr->stime[0] = 0; + since[0] = 0; + switch (jcr->JobLevel) { + case L_DIFFERENTIAL: + case L_INCREMENTAL: + /* Look up start time of last job */ + jcr->jr.JobId = 0; + if (!db_find_job_start_time(jcr, jcr->db, &jcr->jr, &jcr->stime)) { + Jmsg(jcr, M_INFO, 0, "%s", db_strerror(jcr->db)); + Jmsg(jcr, M_INFO, 0, _("No prior or suitable Full backup found. Doing FULL backup.\n")); + bsnprintf(since, since_len, " (upgraded from %s)", + level_to_str(jcr->JobLevel)); + jcr->JobLevel = jcr->jr.Level = L_FULL; + } else { + bstrncpy(since, ", since=", sizeof(since)); + bstrncat(since, jcr->stime, sizeof(since)); + } + Dmsg1(115, "Last start time = %s\n", jcr->stime); + break; + } +} + + +/* + * Send level command for backup and estimate + */ +int send_level_command(JCR *jcr) +{ + BSOCK *fd = jcr->file_bsock; + /* + * Send Level command to File daemon + */ + switch (jcr->JobLevel) { + case L_BASE: + bnet_fsend(fd, levelcmd, "base", " ", 0); + break; + case L_FULL: + bnet_fsend(fd, levelcmd, "full", " ", 0); + break; + case L_DIFFERENTIAL: + case L_INCREMENTAL: + bnet_fsend(fd, levelcmd, "since ", jcr->stime, 0); + break; + case L_SINCE: + default: + Jmsg2(jcr, M_FATAL, 0, _("Unimplemented backup level %d %c\n"), + jcr->JobLevel, jcr->JobLevel); + return 0; + } + Dmsg1(120, ">filed: %s", fd->msg); + if (!response(jcr, fd, OKlevel, "Level", DISPLAY_ERROR)) { + return 0; + } + return 1; +} + + /* * Send either an Included or an Excluded list to FD */ diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 364f958e8c..48891b55a9 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -61,14 +61,16 @@ int variable_expansion(JCR *jcr, char *inp, POOLMEM **exp); /* fd_cmds.c */ extern int connect_to_file_daemon(JCR *jcr, int retry_interval, - int max_retry_time, int verbose); + int max_retry_time, int verbose); extern int send_include_list(JCR *jcr); extern int send_exclude_list(JCR *jcr); extern int send_bootstrap_file(JCR *jcr); +extern int send_level_command(JCR *jcr); extern int get_attributes_and_put_in_catalog(JCR *jcr); extern int get_attributes_and_compare_to_catalog(JCR *jcr, JobId_t JobId); extern int put_file_into_catalog(JCR *jcr, long file_index, char *fname, - char *link, char *attr, int stream); + char *link, char *attr, int stream); +extern void get_level_since_time(JCR *jcr, char *since, int since_len); /* getmsg.c */ enum e_prtmsg { @@ -88,7 +90,7 @@ extern void mount_request(JCR *jcr, BSOCK *bs, char *buf); /* msgchan.c */ extern int connect_to_storage_daemon(JCR *jcr, int retry_interval, - int max_retry_time, int verbose); + int max_retry_time, int verbose); extern int start_storage_daemon_job(JCR *jcr); extern int start_storage_daemon_message_thread(JCR *jcr); extern int bget_dirmsg(BSOCK *bs); @@ -128,28 +130,28 @@ UAContext *new_ua_context(JCR *jcr); void free_ua_context(UAContext *ua); /* ua_select.c */ -STORE *select_storage_resource(UAContext *ua); -JOB *select_job_resource(UAContext *ua); -JOB *select_restore_job_resource(UAContext *ua); -CLIENT *select_client_resource(UAContext *ua); +STORE *select_storage_resource(UAContext *ua); +JOB *select_job_resource(UAContext *ua); +JOB *select_restore_job_resource(UAContext *ua); +CLIENT *select_client_resource(UAContext *ua); FILESET *select_fileset_resource(UAContext *ua); -int select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr); -int select_media_dbr(UAContext *ua, MEDIA_DBR *mr); -int select_pool_dbr(UAContext *ua, POOL_DBR *pr); -int select_client_dbr(UAContext *ua, CLIENT_DBR *cr); - -void start_prompt(UAContext *ua, char *msg); -void add_prompt(UAContext *ua, char *prompt); -int do_prompt(UAContext *ua, char *automsg, char *msg, char *prompt, int max_prompt); -CAT *get_catalog_resource(UAContext *ua); +int select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr); +int select_media_dbr(UAContext *ua, MEDIA_DBR *mr); +int select_pool_dbr(UAContext *ua, POOL_DBR *pr); +int select_client_dbr(UAContext *ua, CLIENT_DBR *cr); + +void start_prompt(UAContext *ua, char *msg); +void add_prompt(UAContext *ua, char *prompt); +int do_prompt(UAContext *ua, char *automsg, char *msg, char *prompt, int max_prompt); +CAT *get_catalog_resource(UAContext *ua); STORE *get_storage_resource(UAContext *ua, int use_default); -int get_media_type(UAContext *ua, char *MediaType, int max_media); -int get_pool_dbr(UAContext *ua, POOL_DBR *pr); -int get_client_dbr(UAContext *ua, CLIENT_DBR *cr); +int get_media_type(UAContext *ua, char *MediaType, int max_media); +int get_pool_dbr(UAContext *ua, POOL_DBR *pr); +int get_client_dbr(UAContext *ua, CLIENT_DBR *cr); POOL *get_pool_resource(UAContext *ua); POOL *select_pool_resource(UAContext *ua); CLIENT *get_client_resource(UAContext *ua); -int get_job_dbr(UAContext *ua, JOB_DBR *jr); +int get_job_dbr(UAContext *ua, JOB_DBR *jr); int find_arg_keyword(UAContext *ua, char **list); int find_arg(UAContext *ua, char *keyword); diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 9d958763c7..acdf92a3b9 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -1184,6 +1184,7 @@ static int estimate_cmd(UAContext *ua, char *cmd) FILESET *fileset = NULL; int listing = 0; BSOCK *fd; + char since[MAXSTRING]; for (int i=1; iargc; i++) { if (strcasecmp(ua->argk[i], _("client")) == 0) { @@ -1224,6 +1225,15 @@ static int estimate_cmd(UAContext *ua, char *cmd) } ua->jcr->client = client; ua->jcr->fileset = fileset; + close_db(ua); + ua->catalog = client->catalog; + + if (!open_db(ua)) { + return 1; + } + + get_level_since_time(ua->jcr, since, sizeof(since)); + 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)) { @@ -1242,9 +1252,8 @@ static int estimate_cmd(UAContext *ua, char *cmd) return 1; } - bnet_fsend(fd, "level = full mtime_only=0\n"); - if (bnet_recv(fd) >= 0) { - bsendmsg(ua, "%s", fd->msg); + if (!send_level_command(ua->jcr)) { + return 1; } bnet_fsend(fd, "estimate listing=%d\n", listing); @@ -1531,6 +1540,8 @@ int open_db(UAContext *ua) } } + ua->jcr->catalog = ua->catalog; + Dmsg0(150, "Open database\n"); ua->db = db_init_database(ua->jcr, ua->catalog->db_name, ua->catalog->db_user, ua->catalog->db_password, ua->catalog->db_address, diff --git a/bacula/src/dird/ua_server.c b/bacula/src/dird/ua_server.c index 070a31575d..54f4801ed5 100644 --- a/bacula/src/dird/ua_server.c +++ b/bacula/src/dird/ua_server.c @@ -176,7 +176,6 @@ static void *handle_UA_client_request(void *arg) getout: - close_db(ua); /* do this before freeing JCR */ free_ua_context(ua); free_jcr(jcr); @@ -221,6 +220,8 @@ void free_ua_context(UAContext *ua) bnet_close(ua->UA_sock); } + close_db(ua); + free(ua); } diff --git a/bacula/src/dird/verify.c b/bacula/src/dird/verify.c index 7c7c14c354..0242b82aa8 100644 --- a/bacula/src/dird/verify.c +++ b/bacula/src/dird/verify.c @@ -165,19 +165,6 @@ int do_verify(JCR *jcr) jcr->RestoreBootstrap = bstrdup(fname); free_pool_memory(fname); -#ifdef xxx - /* - * Now find the Volumes we will need for the Verify - */ - jcr->VolumeName[0] = 0; - if (!db_get_job_volume_names(jcr, jcr->db, jr.JobId, &jcr->VolumeName) || - jcr->VolumeName[0] == 0) { - Jmsg(jcr, M_FATAL, 0, _("Cannot find Volume Name for verify JobId=%u. ERR=%s"), - jr.JobId, db_strerror(jcr->db)); - goto bail_out; - } - Dmsg1(20, "Got job Volume Names: %s\n", jcr->VolumeName); -#endif /* * Start conversation with Storage daemon */