]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/status.c
Fix reporting jobs from state file + misc
[bacula/bacula] / bacula / src / stored / status.c
index 0d135886982cfb98424be12cd4b28cd70180b79f..3452ed4c1e12e842d399590b1b232cc0cdcb55bc 100644 (file)
@@ -7,7 +7,7 @@
  *  
  */
 /*
-   Copyright (C) 2000-2003 Kern Sibbald and John Walker
+   Copyright (C) 2000-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -44,6 +44,9 @@ extern struct s_last_job last_job;
 
 /* Forward referenced functions */
 static void send_blocked_status(JCR *jcr, DEVICE *dev);
+static void list_terminated_jobs(void *arg);
+static void sendit(char *msg, int len, void *arg);
+static char *level_to_str(int level);
 
 
 /*
@@ -60,34 +63,30 @@ int status_cmd(JCR *jcr)
 
    bnet_fsend(user, "\n%s Version: " VERSION " (" BDATE ") %s %s %s\n", my_name,
              HOST_OS, DISTNAME, DISTVER);
-   bstrftime(dt, sizeof(dt), daemon_start_time);
-   bnet_fsend(user, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
-        last_job.NumJobs == 1 ? "" : "s");
-   if (last_job.NumJobs > 0) {
-      char termstat[30];
-
-      bstrftime(dt, sizeof(dt), last_job.end_time);
-      bnet_fsend(user, _("Last Job %s finished at %s\n"), last_job.Job, dt);
-
-      jobstatus_to_ascii(last_job.JobStatus, termstat, sizeof(termstat));
-      bnet_fsend(user, _("  Files=%s Bytes=%s Termination Status=%s\n"), 
-          edit_uint64_with_commas(last_job.JobFiles, b1),
-          edit_uint64_with_commas(last_job.JobBytes, b2),
-          termstat);
-   }
+   bstrftime_nc(dt, sizeof(dt), daemon_start_time);
+   bnet_fsend(user, _("Daemon started %s, %d Job%s run.\n"), dt, last_jobs->size(),
+        last_jobs->size() == 1 ? "" : "s");
+
+   /*
+    * List terminated jobs
+    */
+   list_terminated_jobs(user);
 
+   /*
+    * List devices
+    */
    LockRes();
-   for (device=NULL;  (device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device)); ) {
+   foreach_res(device, R_DEVICE) {
       for (dev=device->dev; dev; dev=dev->next) {
-        if (dev->state & ST_OPENED) {
-           if (dev->state & ST_LABEL) {
-               bnet_fsend(user, _("Device %s is mounted with Volume \"%s\"\n"), 
+        if (dev_state(dev, ST_OPENED)) {
+           if (dev_state(dev, ST_LABEL)) {
+               bnet_fsend(user, _("Device \"%s\" is mounted with Volume \"%s\"\n"), 
                  dev_name(dev), dev->VolHdr.VolName);
            } else {
-               bnet_fsend(user, _("Device %s open but no Bacula volume is mounted.\n"), dev_name(dev));
+               bnet_fsend(user, _("Device \"%s\" open but no Bacula volume is mounted.\n"), dev_name(dev));
            }
            send_blocked_status(jcr, dev);
-           if (dev->state & ST_APPEND) {
+           if (dev_state(dev, ST_APPEND)) {
               bpb = dev->VolCatInfo.VolCatBlocks;
               if (bpb <= 0) {
                  bpb = 1;
@@ -117,7 +116,7 @@ int status_cmd(JCR *jcr)
               edit_uint64_with_commas(dev->block_num, b2));
 
         } else {
-            bnet_fsend(user, _("Device %s is not open.\n"), dev_name(dev));
+            bnet_fsend(user, _("Device \"%s\" is not open.\n"), dev_name(dev));
            send_blocked_status(jcr, dev);
         }
       }
@@ -127,13 +126,13 @@ int status_cmd(JCR *jcr)
    found = 0;
    lock_jcr_chain();
    /* NOTE, we reuse a calling argument jcr. Be warned! */ 
-   for (jcr=NULL; (jcr=get_next_jcr(jcr)); ) {
+   foreach_jcr(jcr) {
       if (jcr->JobStatus == JS_WaitFD) {
          bnet_fsend(user, _("%s Job %s waiting for Client connection.\n"),
            job_type_to_str(jcr->JobType), jcr->Job);
       }
       if (jcr->device) {
-         bnet_fsend(user, _("%s %s job %s using Volume \"%s\" on device %s\n"), 
+         bnet_fsend(user, _("%s %s job %s using Volume \"%s\" on device \"%s\"\n"), 
                   job_level_to_str(jcr->JobLevel),
                   job_type_to_str(jcr->JobType),
                   jcr->Job,
@@ -167,7 +166,7 @@ int status_cmd(JCR *jcr)
       bnet_fsend(user, _("No jobs running.\n"));
    }
 
-#ifdef full_status
+#ifdef xfull_status
    bnet_fsend(user, "\n\n");
    dump_resource(R_DEVICE, resources[R_DEVICE-r_first].res_head, sendit, user);
 #endif
@@ -241,3 +240,139 @@ static void send_blocked_status(JCR *jcr, DEVICE *dev)
    }
 
 }
+
+static void list_terminated_jobs(void *arg)
+{
+   char dt[MAX_TIME_LENGTH], b1[30], b2[30];
+   char level[10];
+   struct s_last_job *je;
+   char *msg;
+
+   if (last_jobs->size() == 0) {
+      msg = _("No Terminated Jobs.\n"); 
+      sendit(msg, strlen(msg), arg);
+      return;
+   }
+   lock_last_jobs_list();
+   msg =  _("\nTerminated Jobs:\n"); 
+   sendit(msg, strlen(msg), arg);
+   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];
+      char *termstat;
+      char buf[1000];
+
+      bstrftime_nc(dt, sizeof(dt), je->end_time);
+      switch (je->JobType) {
+      case JT_ADMIN:
+      case JT_RESTORE:
+         bstrncpy(level, "    ", sizeof(level));
+        break;
+      default:
+        bstrncpy(level, level_to_str(je->JobLevel), sizeof(level));
+        level[4] = 0;
+        break;
+      }
+      switch (je->JobStatus) {
+      case JS_Created:
+         termstat = "Created";
+        break;
+      case JS_FatalError:
+      case JS_ErrorTerminated:
+         termstat = "Error";
+        break;
+      case JS_Differences:
+         termstat = "Diffs";
+        break;
+      case JS_Canceled:
+         termstat = "Cancel";
+        break;
+      case JS_Terminated:
+         termstat = "OK";
+        break;
+      default:
+         termstat = "Other";
+        break;
+      }
+      bstrncpy(JobName, je->Job, sizeof(JobName));
+      /* There are three periods after the Job name */
+      char *p;
+      for (int i=0; i<3; i++) {
+         if ((p=strrchr(JobName, '.')) != NULL) {
+           *p = 0;
+        }
+      }
+      bsnprintf(buf, sizeof(buf), _("%6d  %-4s %8s %14s %-7s  %-8s %s\n"), 
+        je->JobId,
+        level, 
+        edit_uint64_with_commas(je->JobFiles, b1),
+        edit_uint64_with_commas(je->JobBytes, b2), 
+        termstat,
+        dt, JobName);
+      sendit(buf, strlen(buf), arg);
+   }
+   sendit("\n", 1, arg);
+   unlock_last_jobs_list();
+}
+
+/*
+ * Convert Job Level into a string
+ */
+static char *level_to_str(int level) 
+{
+   char *str;
+
+   switch (level) {
+   case L_BASE:
+      str = _("Base");
+   case L_FULL:
+      str = _("Full");
+      break;
+   case L_INCREMENTAL:
+      str = _("Incremental");
+      break;
+   case L_DIFFERENTIAL:
+      str = _("Differential");
+      break;
+   case L_SINCE:
+      str = _("Since");
+      break;
+   case L_VERIFY_CATALOG:
+      str = _("Verify Catalog");
+      break;
+   case L_VERIFY_INIT:
+      str = _("Init Catalog");
+      break;
+   case L_VERIFY_VOLUME_TO_CATALOG:
+      str = _("Volume to Catalog");
+      break;
+   case L_VERIFY_DISK_TO_CATALOG:
+      str = _("Disk to Catalog");
+      break;
+   case L_VERIFY_DATA:
+      str = _("Data");
+      break;
+   case L_NONE:
+      str = " ";
+      break;
+   default:
+      str = _("Unknown Job Level");
+      break;
+   }
+   return str;
+}
+
+/*
+ * Send to Director 
+ */
+static void sendit(char *msg, int len, void *arg)
+{
+   BSOCK *user = (BSOCK *)arg;
+
+   memcpy(user->msg, msg, len+1);
+   user->msglen = len+1;
+   bnet_send(user);
+}