]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_status.c
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / dird / ua_status.c
index 1d2a390f87e67fe23d226340596646568fd28451..16b9581cf60f6e4e8a8071c0d44a13a93e9ad3b6 100644 (file)
@@ -7,11 +7,11 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2001-2005 Kern Sibbald
+   Copyright (C) 2001-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
-   version 2 as ammended with additional clauses defined in the
+   version 2 as amended with additional clauses defined in the
    file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
@@ -38,15 +38,16 @@ static void do_director_status(UAContext *ua);
 static void do_all_status(UAContext *ua);
 
 static char OKqstatus[]   = "1000 OK .status\n";
-static char DotStatusJob[] = "JobId=%d JobStatus=%c JobErrors=%d\n";
+static char DotStatusJob[] = "JobId=%s JobStatus=%c JobErrors=%d\n";
 
 /*
  * .status command
  */
 int qstatus_cmd(UAContext *ua, const char *cmd)
 {
-   JCR* njcr;
+   JCR* njcr = NULL;
    s_last_job* job;
+   char ed1[50];
 
    if (!open_db(ua)) {
       return 1;
@@ -62,19 +63,19 @@ int qstatus_cmd(UAContext *ua, const char *cmd)
       bsendmsg(ua, OKqstatus, ua->argk[2]);
       foreach_jcr(njcr) {
          if (njcr->JobId != 0) {
-            bsendmsg(ua, DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors);
+            bsendmsg(ua, DotStatusJob, edit_int64(njcr->JobId, ed1), 
+                     njcr->JobStatus, njcr->JobErrors);
          }
-         free_jcr(njcr);
       }
-   }
-   else if (strcasecmp(ua->argk[2], "last") == 0) {
+      endeach_jcr(njcr);
+   else if (strcasecmp(ua->argk[2], "last") == 0) {
       bsendmsg(ua, OKqstatus, ua->argk[2]);
       if ((last_jobs) && (last_jobs->size() > 0)) {
          job = (s_last_job*)last_jobs->last();
-         bsendmsg(ua, DotStatusJob, job->JobId, job->JobStatus, job->Errors);
+         bsendmsg(ua, DotStatusJob, edit_int64(job->JobId, ed1), 
+                  job->JobStatus, job->Errors);
       }
-   }
-   else {
+   } else {
       bsendmsg(ua, "1900 Bad .status command, wrong argument.\n");
       return 1;
    }
@@ -97,21 +98,21 @@ int status_cmd(UAContext *ua, const char *cmd)
    Dmsg1(20, "status:%s:\n", cmd);
 
    for (i=1; i<ua->argc; i++) {
-      if (strcasecmp(ua->argk[i], _("all")) == 0) {
+      if (strcasecmp(ua->argk[i], N_("all")) == 0) {
          do_all_status(ua);
          return 1;
-      } else if (strcasecmp(ua->argk[i], _("dir")) == 0 ||
-                 strcasecmp(ua->argk[i], _("director")) == 0) {
+      } else if (strcasecmp(ua->argk[i], N_("dir")) == 0 ||
+                 strcasecmp(ua->argk[i], N_("director")) == 0) {
          do_director_status(ua);
          return 1;
-      } else if (strcasecmp(ua->argk[i], _("client")) == 0) {
+      } else if (strcasecmp(ua->argk[i], N_("client")) == 0) {
          client = get_client_resource(ua);
          if (client) {
             do_client_status(ua, client);
          }
          return 1;
       } else {
-         store = get_storage_resource(ua, 0);
+         store = get_storage_resource(ua, false/*no default*/);
          if (store) {
             do_storage_status(ua, store);
          }
@@ -123,10 +124,10 @@ int status_cmd(UAContext *ua, const char *cmd)
        char prmt[MAX_NAME_LENGTH];
 
       start_prompt(ua, _("Status available for:\n"));
-      add_prompt(ua, _("Director"));
-      add_prompt(ua, _("Storage"));
-      add_prompt(ua, _("Client"));
-      add_prompt(ua, _("All"));
+      add_prompt(ua, N_("Director"));
+      add_prompt(ua, N_("Storage"));
+      add_prompt(ua, N_("Client"));
+      add_prompt(ua, N_("All"));
       Dmsg0(20, "do_prompt: select daemon\n");
       if ((item=do_prompt(ua, "",  _("Select daemon type for status"), prmt, sizeof(prmt))) < 0) {
          return 1;
@@ -241,11 +242,16 @@ static void do_director_status(UAContext *ua)
 {
    char dt[MAX_TIME_LENGTH];
 
-   bsendmsg(ua, "%s Version: " VERSION " (" BDATE ") %s %s %s\n", my_name,
+   bsendmsg(ua, _("%s Version: %s (%s) %s %s %s\n"), my_name, VERSION, BDATE,
             HOST_OS, DISTNAME, DISTVER);
    bstrftime_nc(dt, sizeof(dt), daemon_start_time);
-   bsendmsg(ua, _("Daemon started %s, %d Job%s run since started.\n"),
-        dt, num_jobs_run, num_jobs_run == 1 ? "" : "s");
+   if (num_jobs_run == 1) {
+      bsendmsg(ua, _("Daemon started %s, 1 Job run since started.\n"), dt);
+   }
+   else {
+      bsendmsg(ua, _("Daemon started %s, %d Jobs run since started.\n"),
+        dt, num_jobs_run);
+   }
    if (debug_level > 0) {
       char b1[35], b2[35], b3[35], b4[35];
       bsendmsg(ua, _(" Heap: bytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
@@ -268,7 +274,7 @@ static void do_director_status(UAContext *ua)
     * List terminated jobs
     */
    list_terminated_jobs(ua);
-   bsendmsg(ua, "====\n");
+   bsendmsg(ua, _("====\n"));
 }
 
 static void do_storage_status(UAContext *ua, STORE *store)
@@ -354,6 +360,7 @@ struct sched_pkt {
    int priority;
    time_t runtime;
    POOL *pool;
+   STORE *store;
 };
 
 static void prt_runtime(UAContext *ua, sched_pkt *sp)
@@ -374,7 +381,8 @@ static void prt_runtime(UAContext *ua, sched_pkt *sp)
       }
       if (ok) {
          mr.PoolId = jcr->PoolId;
-         ok = find_next_volume_for_append(jcr, &mr, 0);
+         mr.StorageId = sp->store->StorageId;
+         ok = find_next_volume_for_append(jcr, &mr, 1, false/*no create*/);
       }
       if (!ok) {
          bstrncpy(mr.VolumeName, "*unknown*", sizeof(mr.VolumeName));
@@ -429,21 +437,33 @@ static void list_scheduled_jobs(UAContext *ua)
    time_t runtime;
    RUN *run;
    JOB *job;
+   STORE* store;
    int level, num_jobs = 0;
    int priority;
    bool hdr_printed = false;
    dlist sched;
    sched_pkt *sp;
+   int days, i;
 
    Dmsg0(200, "enter list_sched_jobs()\n");
 
+   days = 1;
+   i = find_arg_with_value(ua, N_("days"));
+   if (i >= 0) {
+     days = atoi(ua->argv[i]);
+     if ((days < 0) || (days > 50)) {
+       bsendmsg(ua, _("Ignoring illegal value for days.\n"));
+       days = 1;
+     }
+   }
+
    /* Loop through all jobs */
    LockRes();
    foreach_res(job, R_JOB) {
-      if (!acl_access_ok(ua, Job_ACL, job->hdr.name)) {
+      if (!acl_access_ok(ua, Job_ACL, job->hdr.name) || !job->enabled) {
          continue;
       }
-      for (run=NULL; (run = find_next_run(run, job, runtime)); ) {
+      for (run=NULL; (run = find_next_run(run, job, runtime, days)); ) {
          level = job->JobLevel;
          if (run->level) {
             level = run->level;
@@ -452,6 +472,11 @@ static void list_scheduled_jobs(UAContext *ua)
          if (run->Priority) {
             priority = run->Priority;
          }
+         if (run->storage) {
+            store = run->storage;
+         } else {
+            store = (STORE *)job->storage->first();
+         }
          if (!hdr_printed) {
             prt_runhdr(ua);
             hdr_printed = true;
@@ -462,6 +487,7 @@ static void list_scheduled_jobs(UAContext *ua)
          sp->priority = priority;
          sp->runtime = runtime;
          sp->pool = run->pool;
+         sp->store = store;
          sched.binary_insert_multiple(sp, my_compare);
          num_jobs++;
       }
@@ -473,7 +499,7 @@ static void list_scheduled_jobs(UAContext *ua)
    if (num_jobs == 0) {
       bsendmsg(ua, _("No Scheduled Jobs.\n"));
    }
-   bsendmsg(ua, "====\n");
+   bsendmsg(ua, _("====\n"));
    Dmsg0(200, "Leave list_sched_jobs_runs()\n");
 }
 
@@ -490,7 +516,6 @@ static void list_running_jobs(UAContext *ua)
    Dmsg0(200, "enter list_run_jobs()\n");
    bsendmsg(ua, _("\nRunning Jobs:\n"));
    foreach_jcr(jcr) {
-      njobs++;
       if (jcr->JobId == 0) {      /* this is us */
          /* this is a console or other control job. We only show console
           * jobs in the status output.
@@ -499,10 +524,12 @@ static void list_running_jobs(UAContext *ua)
             bstrftime_nc(dt, sizeof(dt), jcr->start_time);
             bsendmsg(ua, _("Console connected at %s\n"), dt);
          }
-         njobs--;
-      }
-      free_jcr(jcr);
+         continue;
+      }       
+      njobs++;
    }
+   endeach_jcr(jcr);
+
    if (njobs == 0) {
       /* Note the following message is used in regress -- don't change */
       bsendmsg(ua, _("No Jobs running.\n====\n"));
@@ -514,7 +541,6 @@ static void list_running_jobs(UAContext *ua)
    bsendmsg(ua, _("======================================================================\n"));
    foreach_jcr(jcr) {
       if (jcr->JobId == 0 || !acl_access_ok(ua, Job_ACL, jcr->job->hdr.name)) {
-         free_jcr(jcr);
          continue;
       }
       njobs++;
@@ -633,9 +659,9 @@ static void list_running_jobs(UAContext *ua)
          free_pool_memory(emsg);
          pool_mem = false;
       }
-      free_jcr(jcr);
    }
-   bsendmsg(ua, "====\n");
+   endeach_jcr(jcr);
+   bsendmsg(ua, _("====\n"));
    Dmsg0(200, "leave list_run_jobs()\n");
 }
 
@@ -683,23 +709,23 @@ static void list_terminated_jobs(UAContext *ua)
       }
       switch (je->JobStatus) {
       case JS_Created:
-         termstat = "Created";
+         termstat = _("Created");
          break;
       case JS_FatalError:
       case JS_ErrorTerminated:
-         termstat = "Error";
+         termstat = _("Error");
          break;
       case JS_Differences:
-         termstat = "Diffs";
+         termstat = _("Diffs");
          break;
       case JS_Canceled:
-         termstat = "Cancel";
+         termstat = _("Cancel");
          break;
       case JS_Terminated:
-         termstat = "OK";
+         termstat = _("OK");
          break;
       default:
-         termstat = "Other";
+         termstat = _("Other");
          break;
       }
       bsendmsg(ua, _("%6d  %-6s %8s %14s %-7s  %-8s %s\n"),
@@ -710,6 +736,6 @@ static void list_terminated_jobs(UAContext *ua)
          termstat,
          dt, JobName);
    }
-   bsendmsg(ua, "\n");
+   bsendmsg(ua, _("\n"));
    unlock_last_jobs_list();
 }