]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_status.c
Use bpipe for shell expansion
[bacula/bacula] / bacula / src / dird / ua_status.c
index a05ee54b1cb04c10d879366cffe1565aeda70147..77a2fa55be1e0911eef1a8d3ba826a5fcc15b87c 100644 (file)
@@ -3,10 +3,12 @@
  *   Bacula Director -- User Agent Status Command
  *
  *     Kern Sibbald, August MMI
+ *
+ *   Version $Id$
  */
 
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2003 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
@@ -27,7 +29,6 @@
 
 #include "bacula.h"
 #include "dird.h"
-#include "ua.h"
 
 extern char my_name[];
 extern time_t daemon_start_time;
@@ -68,7 +69,7 @@ int statuscmd(UAContext *ua, char *cmd)
         }
         return 1;
       } else {
-        store = get_storage_resource(ua, cmd);
+        store = get_storage_resource(ua, 0);
         if (store) {
            do_storage_status(ua, store);
         }
@@ -83,7 +84,7 @@ int statuscmd(UAContext *ua, char *cmd)
       add_prompt(ua, _("Client"));
       add_prompt(ua, _("All"));
       Dmsg0(20, "do_prompt: select daemon\n");
-      if ((item=do_prompt(ua, _("Select daemon type for status"), cmd)) < 0) {
+      if ((item=do_prompt(ua, "",  _("Select daemon type for status"), cmd, MAX_NAME_LENGTH)) < 0) {
         return 1;
       }
       Dmsg1(20, "item=%d\n", item);
@@ -158,7 +159,7 @@ static void do_all_status(UAContext *ua, char *cmd)
    client = NULL;
    for (i=0; (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)); i++)
       { }
-   unique_client = (CLIENT **) malloc(i * sizeof(CLIENT));
+   unique_client = (CLIENT **)malloc(i * sizeof(CLIENT));
    /* Find Unique Client address/port */        
    client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
    i = 0;
@@ -196,32 +197,20 @@ static void do_director_status(UAContext *ua, char *cmd)
    int pool_mem = FALSE;
 
    Dmsg0(200, "Doing status\n");
-   bsendmsg(ua, "%s Version: " VERSION " (" DATE ")\n", my_name);
+   bsendmsg(ua, "%s Version: " VERSION " (" BDATE ")\n", my_name);
    bstrftime(dt, sizeof(dt), daemon_start_time);
    bsendmsg(ua, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
         last_job.NumJobs == 1 ? "" : "s");
    if (last_job.NumJobs > 0) {
-      char *termstat, jstat[2];
+      char termstat[30];
 
       bstrftime(dt, sizeof(dt), last_job.end_time);
       bsendmsg(ua, _("Last Job %s finished at %s\n"), last_job.Job, dt);
-      switch (last_job.JobStatus) {
-        case JS_Terminated:
-            termstat = _("OK");
-           break;
-       case JS_ErrorTerminated:
-            termstat = _("Error");
-           break;
-       default:
-           jstat[0] = last_job.JobStatus;
-           jstat[1] = 0;
-           termstat = jstat;
-           break;
-      }
+      jobstatus_to_ascii(last_job.JobStatus, termstat, sizeof(termstat));
           
       bsendmsg(ua, _("  Files=%s Bytes=%s Termination Status=%s\n"), 
-          edit_uint_with_commas(last_job.JobFiles, b1),
-          edit_uint_with_commas(last_job.JobBytes, b2),
+          edit_uint64_with_commas(last_job.JobFiles, b1),
+          edit_uint64_with_commas(last_job.JobBytes, b2),
           termstat);
    }
    lock_jcr_chain();
@@ -249,7 +238,7 @@ static void do_director_status(UAContext *ua, char *cmd)
         case JS_ErrorTerminated:
             msg = _("has erred");
            break;
-        case JS_Cancelled:
+        case JS_Canceled:
             msg = _("has been canceled");
            break;
         case JS_WaitFD:
@@ -262,6 +251,26 @@ static void do_director_status(UAContext *ua, char *cmd)
             Mmsg(&msg, _("is waiting on Storage %s"), jcr->store->hdr.name);
            pool_mem = TRUE;
            break;
+        case JS_WaitStoreRes:
+            msg = _("is waiting on max Storage jobs");
+           break;
+        case JS_WaitClientRes:
+            msg = _("is waiting on max Client jobs");
+           break;
+        case JS_WaitJobRes:
+            msg = _("is waiting on max Job jobs");
+           break;
+        case JS_WaitPriority:
+            msg = _("is waiting for higher priority jobs to finish");
+           break;
+        case JS_WaitMaxJobs:
+            msg = _("is waiting on max total jobs");
+           break;
+        case JS_WaitStartTime:
+            msg = _("is waiting for its start time");
+           break;
+
+
         default:
            msg = (char *) get_pool_memory(PM_FNAME);
             Mmsg(&msg, _("is in unknown state %c"), jcr->JobStatus);
@@ -320,12 +329,16 @@ static void do_storage_status(UAContext *ua, STORE *store)
    if (!connect_to_storage_daemon(ua->jcr, 1, 15, 0)) {
       bsendmsg(ua, _("\nFailed to connect to Storage daemon %s.\n====\n"),
         store->hdr.name);
+      if (ua->jcr->store_bsock) {
+        bnet_close(ua->jcr->store_bsock);
+        ua->jcr->store_bsock = NULL;
+      }        
       return;
    }
    Dmsg0(20, _("Connected to storage daemon\n"));
    sd = ua->jcr->store_bsock;
    bnet_fsend(sd, "status");
-   while (bnet_recv(sd) > 0) {
+   while (bnet_recv(sd) >= 0) {
       bsendmsg(ua, "%s", sd->msg);
    }
    bnet_sig(sd, BNET_TERMINATE);
@@ -341,18 +354,29 @@ static void do_client_status(UAContext *ua, CLIENT *client)
    /* Connect to File daemon */
 
    ua->jcr->client = client;
+   /* Release any old dummy key */
+   if (ua->jcr->sd_auth_key) {
+      free(ua->jcr->sd_auth_key);
+   }
+   /* Create a new dummy SD auth key */
+   ua->jcr->sd_auth_key = bstrdup("dummy");
+
    /* Try to connect for 15 seconds */
    bsendmsg(ua, _("Connecting to Client %s at %s:%d\n"), 
       client->hdr.name, client->address, client->FDport);
    if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) {
       bsendmsg(ua, _("Failed to connect to Client %s.\n====\n"),
         client->hdr.name);
+      if (ua->jcr->file_bsock) {
+        bnet_close(ua->jcr->file_bsock);
+        ua->jcr->file_bsock = NULL;
+      }        
       return;
    }
    Dmsg0(20, _("Connected to file daemon\n"));
    fd = ua->jcr->file_bsock;
    bnet_fsend(fd, "status");
-   while (bnet_recv(fd) > 0) {
+   while (bnet_recv(fd) >= 0) {
       bsendmsg(ua, "%s", fd->msg);
    }
    bnet_sig(fd, BNET_TERMINATE);
@@ -362,26 +386,19 @@ static void do_client_status(UAContext *ua, CLIENT *client)
    return;  
 }
 
-static void prt_runtime(UAContext *ua, JOB *job, time_t runtime)
+static void prt_runhdr(UAContext *ua)
 {
-   char dt[MAX_TIME_LENGTH], *type;
+   bsendmsg(ua, _("Level          Type     Scheduled          Name\n"));
+   bsendmsg(ua, _("=================================================================\n"));
+}
+
+static void prt_runtime(UAContext *ua, JOB *job, int level, time_t runtime)
+{
+   char dt[MAX_TIME_LENGTH];      
 
    bstrftime(dt, sizeof(dt), runtime);
-   switch (job->JobType) {
-      case JT_BACKUP:
-         type = _("Backup");
-        break;
-      case JT_VERIFY:
-         type = _("Verify");
-        break;
-      case JT_RESTORE:
-         type = _("Restore");
-        break;
-      default:
-         type = _("Unknown type of");
-        break;
-   }
-   bsendmsg(ua, _("%s job \"%s\" scheduled for %s\n"), type, job->hdr.name, dt);
+   bsendmsg(ua, _("%-14s %-8s %-18s %s\n"), 
+      level_to_str(level), job_type_to_str(job->JobType), dt, job->hdr.name);
 }
 
 /*         
@@ -395,9 +412,11 @@ static void print_jobs_scheduled(UAContext *ua)
    JOB *job;
    SCHED *sched;
    struct tm tm;
-   int mday, wday, month, tmday, twday, tmonth, i, hour;
+   int mday, wday, month, wpos, tmday, twday, tmonth, twpos, i, hour;
    int tod, tom;
    int found;
+   int hdr_printed = FALSE;
+   int level;
 
    Dmsg0(200, "enter find_runs()\n");
 
@@ -406,33 +425,39 @@ static void print_jobs_scheduled(UAContext *ua)
    mday = tm.tm_mday - 1;
    wday = tm.tm_wday;
    month = tm.tm_mon;
+   wpos = (tm.tm_mday - 1) / 7;
 
    tomorrow = now + 60 * 60 * 24;
    localtime_r(&tomorrow, &tm);
    tmday = tm.tm_mday - 1;
    twday = tm.tm_wday;
    tmonth = tm.tm_mon;
+   twpos  = (tm.tm_mday - 1) / 7;
 
    /* Loop through all jobs */
    LockRes();
    for (job=NULL; (job=(JOB *)GetNextRes(R_JOB, (RES *)job)); ) {
+      level = job->level;   
       sched = job->schedule;
       if (sched == NULL) {           /* scheduled? */
         continue;                    /* no, skip this job */
       }
       for (run=sched->run; run; run=run->next) {
+        if (run->level) {
+           level = run->level;
+        }
         /* 
          * Find runs in next 24 hours
          */
         tod = (bit_is_set(mday, run->mday) || bit_is_set(wday, run->wday)) && 
-               bit_is_set(month, run->month);
+               bit_is_set(month, run->month) && bit_is_set(wpos, run->wpos);
 
         tom = (bit_is_set(tmday, run->mday) || bit_is_set(twday, run->wday)) &&
-               bit_is_set(tmonth, run->month);
+               bit_is_set(tmonth, run->month) && bit_is_set(wpos, run->wpos);
 
          Dmsg2(200, "tod=%d tom=%d\n", tod, tom);
         found = FALSE;
-        if (tod) {
+        if (tod) {                   /* Jobs scheduled today (next 24 hours) */
            /* find time (time_t) job is to be run */
            localtime_r(&now, &tm);
            hour = 0;
@@ -443,7 +468,11 @@ static void print_jobs_scheduled(UAContext *ua)
                  tm.tm_sec = 0;
                  runtime = mktime(&tm);
                  if (runtime > now) {
-                    prt_runtime(ua, job, runtime);
+                    if (!hdr_printed) {
+                       hdr_printed = TRUE;
+                       prt_runhdr(ua);
+                    }
+                    prt_runtime(ua, job, level, runtime);
                     found = TRUE;
                     break;
                  }
@@ -451,8 +480,8 @@ static void print_jobs_scheduled(UAContext *ua)
            }
         }
 
-        Dmsg2(200, "runtime=%d now=%d\n", runtime, now);
-       if (!found && tom) {
+//       Dmsg2(200, "runtime=%d now=%d\n", runtime, now);
+        if (!found && tom) {            /* look at jobs scheduled tomorrow */
            localtime_r(&tomorrow, &tm);
            hour = 0;
            for (i=0; i < 24; i++) {
@@ -467,11 +496,15 @@ static void print_jobs_scheduled(UAContext *ua)
            runtime = mktime(&tm);
             Dmsg2(200, "truntime=%d now=%d\n", runtime, now);
            if (runtime < tomorrow) {
-              prt_runtime(ua, job, runtime);
+              if (!hdr_printed) {
+                 hdr_printed = TRUE;
+                 prt_runhdr(ua);
+              }
+              prt_runtime(ua, job, level, runtime);
            }
         }
-      }  
-   }
+      } /* end for loop over runs */ 
+   } /* end for loop over resources */
    UnlockRes();
    Dmsg0(200, "Leave find_runs()\n");
 }