From: Kern Sibbald Date: Sun, 24 Feb 2008 19:42:51 +0000 (+0000) Subject: kes First cut of converting FD .status to work with bat API. X-Git-Tag: Release-7.0.0~4959 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=cd57b477c999d51d1bb339ff6ac9bb967a780f24;p=bacula%2Fbacula kes First cut of converting FD .status to work with bat API. New form is: .status client=XXX header .status client=XXX running .status client=XXX terminated git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6482 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kernstodo b/bacula/kernstodo index d472d1d590..769c92a92d 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -70,6 +70,9 @@ Professional Needs: and http://www.openeyet.nl/scc/ for managing customer changes Priority: +- Look at in src/filed/backup.c +> pm_strcpy(ff_pkt->fname, ff_pkt->fname_save); +> pm_strcpy(ff_pkt->link, ff_pkt->link_save); - Add Catalog = to Pool resource so that pools will exist in only one catalog -- currently Pools are "global". - New directive "Delete purged Volumes" @@ -1837,4 +1840,3 @@ Block Position: 0 - Unicode input http://en.wikipedia.org/wiki/Byte_Order_Mark - Look at moving the Storage directive from the Job to the Pool in the default conf files. - diff --git a/bacula/src/dird/ua_status.c b/bacula/src/dird/ua_status.c index 2b5a122169..204b1cd396 100644 --- a/bacula/src/dird/ua_status.c +++ b/bacula/src/dird/ua_status.c @@ -43,8 +43,8 @@ extern void *start_heap; static void list_scheduled_jobs(UAContext *ua); static void list_running_jobs(UAContext *ua); static void list_terminated_jobs(UAContext *ua); -static void do_storage_status(UAContext *ua, STORE *store); -static void do_client_status(UAContext *ua, CLIENT *client); +static void do_storage_status(UAContext *ua, STORE *store, char *cmd); +static void do_client_status(UAContext *ua, CLIENT *client, char *cmd); static void do_director_status(UAContext *ua); static void do_all_status(UAContext *ua); @@ -57,43 +57,61 @@ static char DotStatusJob[] = "JobId=%s JobStatus=%c JobErrors=%d\n"; bool dot_status_cmd(UAContext *ua, const char *cmd) { + STORE *store; + CLIENT *client; JCR* njcr = NULL; s_last_job* job; char ed1[50]; - Dmsg1(20, "status:%s:\n", cmd); + Dmsg2(20, "status=\"%s\" argc=%d\n", cmd, ua->argc); - if ((ua->argc != 3) || (strcasecmp(ua->argk[1], "dir"))) { + if (ua->argc < 3) { ua->send_msg("1900 Bad .status command, missing arguments.\n"); return false; } - if (strcasecmp(ua->argk[2], "current") == 0) { - ua->send_msg(OKqstatus, ua->argk[2]); - foreach_jcr(njcr) { - if (njcr->JobId != 0 && acl_access_ok(ua, Job_ACL, njcr->job->name())) { - ua->send_msg(DotStatusJob, edit_int64(njcr->JobId, ed1), - njcr->JobStatus, njcr->JobErrors); + if (strcasecmp(ua->argk[1], "dir") == 0) { + if (strcasecmp(ua->argk[2], "current") == 0) { + ua->send_msg(OKqstatus, ua->argk[2]); + foreach_jcr(njcr) { + if (njcr->JobId != 0 && acl_access_ok(ua, Job_ACL, njcr->job->name())) { + ua->send_msg(DotStatusJob, edit_int64(njcr->JobId, ed1), + njcr->JobStatus, njcr->JobErrors); + } } - } - endeach_jcr(njcr); - } else if (strcasecmp(ua->argk[2], "last") == 0) { - ua->send_msg(OKqstatus, ua->argk[2]); - if ((last_jobs) && (last_jobs->size() > 0)) { - job = (s_last_job*)last_jobs->last(); - if (acl_access_ok(ua, Job_ACL, job->Job)) { - ua->send_msg(DotStatusJob, edit_int64(job->JobId, ed1), - job->JobStatus, job->Errors); + endeach_jcr(njcr); + } else if (strcasecmp(ua->argk[2], "last") == 0) { + ua->send_msg(OKqstatus, ua->argk[2]); + if ((last_jobs) && (last_jobs->size() > 0)) { + job = (s_last_job*)last_jobs->last(); + if (acl_access_ok(ua, Job_ACL, job->Job)) { + ua->send_msg(DotStatusJob, edit_int64(job->JobId, ed1), + job->JobStatus, job->Errors); + } } + } else if (strcasecmp(ua->argk[2], "header") == 0) { + list_dir_status_header(ua); + } else if (strcasecmp(ua->argk[2], "scheduled") == 0) { + list_scheduled_jobs(ua); + } else if (strcasecmp(ua->argk[2], "running") == 0) { + list_running_jobs(ua); + } else if (strcasecmp(ua->argk[2], "terminated") == 0) { + list_terminated_jobs(ua); + } else { + ua->send_msg("1900 Bad .status command, wrong argument.\n"); + return false; + } + } else if (strcasecmp(ua->argk[1], "client") == 0) { + client = get_client_resource(ua); + if (client) { + Dmsg2(000, "Client=%s arg=%s\n", client->name(), NPRT(ua->argk[2])); + do_client_status(ua, client, ua->argk[2]); + } + } else if (strcasecmp(ua->argk[1], "storage") == 0) { + store = get_storage_resource(ua, false /*no default*/); + if (store) { + do_storage_status(ua, store, ua->argk[2]); } - } else if (strcasecmp(ua->argk[2], "header") == 0) { - list_dir_status_header(ua); - } else if (strcasecmp(ua->argk[2], "scheduled") == 0) { - list_scheduled_jobs(ua); - } else if (strcasecmp(ua->argk[2], "running") == 0) { - list_running_jobs(ua); - } else if (strcasecmp(ua->argk[2], "terminated") == 0) { - list_terminated_jobs(ua); } else { ua->send_msg("1900 Bad .status command, wrong argument.\n"); return false; @@ -133,13 +151,13 @@ int status_cmd(UAContext *ua, const char *cmd) } else if (strcasecmp(ua->argk[i], NT_("client")) == 0) { client = get_client_resource(ua); if (client) { - do_client_status(ua, client); + do_client_status(ua, client, NULL); } return 1; } else { store = get_storage_resource(ua, false/*no default*/); if (store) { - do_storage_status(ua, store); + do_storage_status(ua, store, NULL); } return 1; } @@ -165,13 +183,13 @@ int status_cmd(UAContext *ua, const char *cmd) case 1: store = select_storage_resource(ua); if (store) { - do_storage_status(ua, store); + do_storage_status(ua, store, NULL); } break; case 2: client = select_client_resource(ua); if (client) { - do_client_status(ua, client); + do_client_status(ua, client, NULL); } break; case 3: @@ -223,7 +241,7 @@ static void do_all_status(UAContext *ua) /* Call each unique Storage daemon */ for (j=0; jsend_msg("====\n"); } -static void do_storage_status(UAContext *ua, STORE *store) +static void do_storage_status(UAContext *ua, STORE *store, char *cmd) { BSOCK *sd; USTORE lstore; @@ -316,7 +334,7 @@ static void do_storage_status(UAContext *ua, STORE *store) pm_strcpy(lstore.store_source, _("unknown source")); set_wstorage(ua->jcr, &lstore); /* Try connecting for up to 15 seconds */ - ua->send_msg(_("Connecting to Storage daemon %s at %s:%d\n"), + if (!ua->api) ua->send_msg(_("Connecting to Storage daemon %s at %s:%d\n"), store->name(), store->address, store->SDport); if (!connect_to_storage_daemon(ua->jcr, 1, 15, 0)) { ua->send_msg(_("\nFailed to connect to Storage daemon %s.\n====\n"), @@ -329,17 +347,21 @@ static void do_storage_status(UAContext *ua, STORE *store) } Dmsg0(20, _("Connected to storage daemon\n")); sd = ua->jcr->store_bsock; - bnet_fsend(sd, "status"); - while (bnet_recv(sd) >= 0) { + if (cmd) { + sd->fsend(".status %s", cmd); + } else { + sd->fsend("status"); + } + while (sd->recv() >= 0) { ua->send_msg("%s", sd->msg); } - bnet_sig(sd, BNET_TERMINATE); - bnet_close(sd); + sd->signal( BNET_TERMINATE); + sd->close(); ua->jcr->store_bsock = NULL; return; } -static void do_client_status(UAContext *ua, CLIENT *client) +static void do_client_status(UAContext *ua, CLIENT *client, char *cmd) { BSOCK *fd; @@ -354,7 +376,7 @@ static void do_client_status(UAContext *ua, CLIENT *client) ua->jcr->sd_auth_key = bstrdup("dummy"); /* Try to connect for 15 seconds */ - ua->send_msg(_("Connecting to Client %s at %s:%d\n"), + if (!ua->api) ua->send_msg(_("Connecting to Client %s at %s:%d\n"), client->name(), client->address, client->FDport); if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) { ua->send_msg(_("Failed to connect to Client %s.\n====\n"), @@ -367,7 +389,11 @@ static void do_client_status(UAContext *ua, CLIENT *client) } Dmsg0(20, _("Connected to file daemon\n")); fd = ua->jcr->file_bsock; - fd->fsend("status"); + if (cmd) { + fd->fsend(".status %s", cmd); + } else { + fd->fsend("status"); + } while (fd->recv() >= 0) { ua->send_msg("%s", fd->msg); } diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index afff50db84..ca53cd6d52 100644 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2001-2007 Free Software Foundation Europe e.V. + Copyright (C) 2001-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -40,7 +40,9 @@ extern void *start_heap; /* Forward referenced functions */ -static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg); +static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg, bool api); +static void list_running_jobs(void sendit(const char *msg, int len, void *sarg), void *arg, bool api); +static void list_status_header(void sendit(const char *msg, int len, void *sarg), void *arg, bool api); static void bsock_sendit(const char *msg, int len, void *arg); static const char *level_to_str(int level); @@ -66,12 +68,16 @@ extern VSSClient *g_pVSSClient; */ void output_status(void sendit(const char *msg, int len, void *sarg), void *arg) { - int sec, bps; + list_status_header(sendit, arg, false /*no api*/); + list_running_jobs(sendit, arg, false /*no api*/); + list_terminated_jobs(sendit, arg, false /*no api*/); +} + +static void list_status_header(void sendit(const char *msg, int len, void *sarg), void *arg, bool api) +{ POOL_MEM msg(PM_MESSAGE); char b1[32], b2[32], b3[32], b4[32], b5[35]; int len; - bool found = false; - JCR *njcr; char dt[MAX_TIME_LENGTH]; len = Mmsg(msg, _("%s Version: %s (%s) %s %s %s %s\n"), @@ -136,13 +142,25 @@ void output_status(void sendit(const char *msg, int len, void *sarg), void *arg) len = Mmsg(msg, _(" Sizeof: boffset_t=%d size_t=%d debug=%d trace=%d\n"), sizeof(boffset_t), sizeof(size_t), debug_level, get_trace()); sendit(msg.c_str(), len, arg); +} +static void list_running_jobs(void sendit(const char *msg, int len, void *sarg), void *arg, bool api) +{ + int sec, bps; + POOL_MEM msg(PM_MESSAGE); + char b1[32], b2[32], b3[32]; + int len; + bool found = false; + JCR *njcr; + char dt[MAX_TIME_LENGTH]; /* * List running jobs */ Dmsg0(1000, "Begin status jcr loop.\n"); - len = Mmsg(msg, _("\nRunning Jobs:\n")); - sendit(msg.c_str(), len, arg); + if (!api) { + len = Mmsg(msg, _("\nRunning Jobs:\n")); + sendit(msg.c_str(), len, arg); + } const char *vss = ""; #ifdef WIN32_VSS if (g_pVSSClient && g_pVSSClient->IsInitialized()) { @@ -197,34 +215,39 @@ void output_status(void sendit(const char *msg, int len, void *sarg), void *arg) } endeach_jcr(njcr); - if (!found) { - len = Mmsg(msg, _("No Jobs running.\n")); - sendit(msg.c_str(), len, arg); + if (!api) { + if (!found) { + len = Mmsg(msg, _("No Jobs running.\n")); + sendit(msg.c_str(), len, arg); + } + sendit(_("====\n"), 5, arg); } - sendit(_("====\n"), 5, arg); - - list_terminated_jobs(sendit, arg); } + -static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg) +static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg, bool api) { char dt[MAX_TIME_LENGTH], b1[30], b2[30]; char level[10]; struct s_last_job *je; const char *msg; - msg = _("\nTerminated Jobs:\n"); - sendit(msg, strlen(msg), arg); + if (!api) { + msg = _("\nTerminated Jobs:\n"); + sendit(msg, strlen(msg), arg); + } if (last_jobs->size() == 0) { - sendit(_("====\n"), 5, arg); + if (!api) sendit(_("====\n"), 5, arg); return; } lock_last_jobs_list(); - msg = _(" JobId Level Files Bytes Status Finished Name \n"); - sendit(msg, strlen(msg), arg); - msg = _("======================================================================\n"); - sendit(msg, strlen(msg), arg); + if (!api) { + msg = _(" JobId Level Files Bytes Status Finished Name \n"); + sendit(msg, strlen(msg), arg); + msg = _("======================================================================\n"); + sendit(msg, strlen(msg), arg); + } foreach_dlist(je, last_jobs) { char JobName[MAX_NAME_LENGTH]; const char *termstat; @@ -270,16 +293,26 @@ static void list_terminated_jobs(void sendit(const char *msg, int len, void *sa *p = 0; } } - bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %10s %-7s %-8s %s\n"), - je->JobId, - level, - edit_uint64_with_commas(je->JobFiles, b1), - edit_uint64_with_suffix(je->JobBytes, b2), - termstat, - dt, JobName); + if (api) { + bsnprintf(buf, sizeof(buf), _("%6d\t%-6s\t%8s\t%10s\t%-7s\t%-8s\t%s\n"), + je->JobId, + level, + edit_uint64_with_commas(je->JobFiles, b1), + edit_uint64_with_suffix(je->JobBytes, b2), + termstat, + dt, JobName); + } else { + bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %10s %-7s %-8s %s\n"), + je->JobId, + level, + edit_uint64_with_commas(je->JobFiles, b1), + edit_uint64_with_suffix(je->JobBytes, b2), + termstat, + dt, JobName); + } sendit(buf, strlen(buf), arg); } - sendit(_("====\n"), 5, arg); + if (!api) sendit(_("====\n"), 5, arg); unlock_last_jobs_list(); } @@ -294,7 +327,7 @@ static void bsock_sendit(const char *msg, int len, void *arg) user->msg = check_pool_memory_size(user->msg, len+1); memcpy(user->msg, msg, len+1); user->msglen = len+1; - bnet_send(user); + user->send(); } /* @@ -304,10 +337,10 @@ int status_cmd(JCR *jcr) { BSOCK *user = jcr->dir_bsock; - bnet_fsend(user, "\n"); + user->fsend("\n"); output_status(bsock_sendit, (void *)user); - bnet_sig(user, BNET_EOD); + user->signal(BNET_EOD); return 1; } @@ -317,47 +350,53 @@ int status_cmd(JCR *jcr) int qstatus_cmd(JCR *jcr) { BSOCK *dir = jcr->dir_bsock; - POOLMEM *time; + POOLMEM *cmd; JCR *njcr; s_last_job* job; - time = get_memory(dir->msglen+1); + cmd = get_memory(dir->msglen+1); - if (sscanf(dir->msg, qstatus, time) != 1) { + if (sscanf(dir->msg, qstatus, cmd) != 1) { pm_strcpy(&jcr->errmsg, dir->msg); Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg); - bnet_fsend(dir, _("2900 Bad .status command, missing argument.\n")); - bnet_sig(dir, BNET_EOD); - free_memory(time); + dir->fsend(_("2900 Bad .status command, missing argument.\n")); + dir->signal(BNET_EOD); + free_memory(cmd); return 0; } - unbash_spaces(time); + unbash_spaces(cmd); - if (strcmp(time, "current") == 0) { - bnet_fsend(dir, OKqstatus, time); + if (strcmp(cmd, "current") == 0) { + dir->fsend(OKqstatus, cmd); foreach_jcr(njcr) { if (njcr->JobId != 0) { - bnet_fsend(dir, DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors); + dir->fsend(DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors); } } endeach_jcr(njcr); - } else if (strcmp(time, "last") == 0) { - bnet_fsend(dir, OKqstatus, time); + } else if (strcmp(cmd, "last") == 0) { + dir->fsend(OKqstatus, cmd); if ((last_jobs) && (last_jobs->size() > 0)) { job = (s_last_job*)last_jobs->last(); - bnet_fsend(dir, DotStatusJob, job->JobId, job->JobStatus, job->Errors); + dir->fsend(DotStatusJob, job->JobId, job->JobStatus, job->Errors); } + } else if (strcasecmp(cmd, "header") == 0) { + list_status_header(bsock_sendit, (void *)dir, true/*api*/); + } else if (strcasecmp(cmd, "running") == 0) { + list_running_jobs(bsock_sendit, (void *)dir, true/*api*/); + } else if (strcasecmp(cmd, "terminated") == 0) { + list_terminated_jobs(bsock_sendit, (void *)dir, true/*api*/); } else { pm_strcpy(&jcr->errmsg, dir->msg); Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg); - bnet_fsend(dir, _("2900 Bad .status command, wrong argument.\n")); + dir->fsend(_("2900 Bad .status command, wrong argument.\n")); bnet_sig(dir, BNET_EOD); - free_memory(time); + free_memory(cmd); return 0; } bnet_sig(dir, BNET_EOD); - free_memory(time); + free_memory(cmd); return 1; } diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index f2cf96157f..42c300f776 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,11 @@ General: 24Feb08 +kes First cut of converting FD .status to work with bat API. + New form is: + .status client=XXX header + .status client=XXX running + .status client=XXX terminated kes Implement first cut of Copy Job. kes Implement Catalog in Pool resource. It overrides catalog specified in the Client resource.