]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_status.c
Minor tweaks to Migration
[bacula/bacula] / bacula / src / dird / ua_status.c
index 5eec04d41b4c274fa8f2d65c0ecac4b16e38c90a..596d7426591665766f02adf0d921f80c122728ff 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,
 #include "bacula.h"
 #include "dird.h"
 
-extern char my_name[];
-extern time_t daemon_start_time;
-extern int num_jobs_run;
-
 static void list_scheduled_jobs(UAContext *ua);
 static void list_running_jobs(UAContext *ua);
 static void list_terminated_jobs(UAContext *ua);
@@ -66,14 +62,14 @@ int qstatus_cmd(UAContext *ua, const char *cmd)
             bsendmsg(ua, DotStatusJob, edit_int64(njcr->JobId, ed1), 
                      njcr->JobStatus, njcr->JobErrors);
          }
-         free_jcr(njcr);
       }
+      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, edit_int64(njcr->JobId, ed1), 
-                  njcr->JobStatus, njcr->JobErrors);
+         bsendmsg(ua, DotStatusJob, edit_int64(job->JobId, ed1), 
+                  job->JobStatus, job->Errors);
       }
    } else {
       bsendmsg(ua, "1900 Bad .status command, wrong argument.\n");
@@ -98,21 +94,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], NT_("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], NT_("dir")) == 0 ||
+                 strcasecmp(ua->argk[i], NT_("director")) == 0) {
          do_director_status(ua);
          return 1;
-      } else if (strcasecmp(ua->argk[i], _("client")) == 0) {
+      } else if (strcasecmp(ua->argk[i], NT_("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);
          }
@@ -124,10 +120,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, NT_("Director"));
+      add_prompt(ua, NT_("Storage"));
+      add_prompt(ua, NT_("Client"));
+      add_prompt(ua, NT_("All"));
       Dmsg0(20, "do_prompt: select daemon\n");
       if ((item=do_prompt(ua, "",  _("Select daemon type for status"), prmt, sizeof(prmt))) < 0) {
          return 1;
@@ -179,7 +175,7 @@ static void do_all_status(UAContext *ua)
    i = 0;
    foreach_res(store, R_STORAGE) {
       found = false;
-      if (!acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
+      if (!acl_access_ok(ua, Storage_ACL, store->name())) {
          continue;
       }
       for (j=0; j<i; j++) {
@@ -213,7 +209,7 @@ static void do_all_status(UAContext *ua)
    i = 0;
    foreach_res(client, R_CLIENT) {
       found = false;
-      if (!acl_access_ok(ua, Client_ACL, client->hdr.name)) {
+      if (!acl_access_ok(ua, Client_ACL, client->name())) {
          continue;
       }
       for (j=0; j<i; j++) {
@@ -242,11 +238,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"),
@@ -269,20 +270,20 @@ 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)
 {
    BSOCK *sd;
 
-   set_storage(ua->jcr, store);
+   set_wstorage(ua->jcr, store);
    /* Try connecting for up to 15 seconds */
    bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"),
-      store->hdr.name, store->address, store->SDport);
+      store->name(), store->address, store->SDport);
    if (!connect_to_storage_daemon(ua->jcr, 1, 15, 0)) {
       bsendmsg(ua, _("\nFailed to connect to Storage daemon %s.\n====\n"),
-         store->hdr.name);
+         store->name());
       if (ua->jcr->store_bsock) {
          bnet_close(ua->jcr->store_bsock);
          ua->jcr->store_bsock = NULL;
@@ -317,10 +318,10 @@ static void do_client_status(UAContext *ua, CLIENT *client)
 
    /* Try to connect for 15 seconds */
    bsendmsg(ua, _("Connecting to Client %s at %s:%d\n"),
-      client->hdr.name, client->address, client->FDport);
+      client->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);
+         client->name());
       if (ua->jcr->file_bsock) {
          bnet_close(ua->jcr->file_bsock);
          ua->jcr->file_bsock = NULL;
@@ -355,6 +356,7 @@ struct sched_pkt {
    int priority;
    time_t runtime;
    POOL *pool;
+   STORE *store;
 };
 
 static void prt_runtime(UAContext *ua, sched_pkt *sp)
@@ -374,8 +376,9 @@ static void prt_runtime(UAContext *ua, sched_pkt *sp)
          close_db = true;             /* new db opened, remember to close it */
       }
       if (ok) {
-         mr.PoolId = jcr->PoolId;
-         ok = find_next_volume_for_append(jcr, &mr, 0);
+         mr.PoolId = jcr->jr.PoolId;
+         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));
@@ -393,7 +396,7 @@ static void prt_runtime(UAContext *ua, sched_pkt *sp)
    }
    bsendmsg(ua, _("%-14s %-8s %3d  %-18s %-18s %s\n"),
       level_ptr, job_type_to_str(sp->job->JobType), sp->priority, dt,
-      sp->job->hdr.name, mr.VolumeName);
+      sp->job->name(), mr.VolumeName);
    if (close_db) {
       db_close_database(jcr, jcr->db);
    }
@@ -430,21 +433,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, NT_("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->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;
@@ -453,6 +468,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;
@@ -463,6 +483,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++;
       }
@@ -474,7 +495,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");
 }
 
@@ -491,7 +512,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.
@@ -500,10 +520,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,8 +536,7 @@ static void list_running_jobs(UAContext *ua)
    bsendmsg(ua, _(" JobId Level   Name                       Status\n"));
    bsendmsg(ua, _("======================================================================\n"));
    foreach_jcr(jcr) {
-      if (jcr->JobId == 0 || !acl_access_ok(ua, Job_ACL, jcr->job->hdr.name)) {
-         free_jcr(jcr);
+      if (jcr->JobId == 0 || !acl_access_ok(ua, Job_ACL, jcr->job->name())) {
          continue;
       }
       njobs++;
@@ -549,13 +570,17 @@ static void list_running_jobs(UAContext *ua)
          break;
       case JS_WaitFD:
          emsg = (char *) get_pool_memory(PM_FNAME);
-         Mmsg(emsg, _("is waiting on Client %s"), jcr->client->hdr.name);
+         Mmsg(emsg, _("is waiting on Client %s"), jcr->client->name());
          pool_mem = true;
          msg = emsg;
          break;
       case JS_WaitSD:
          emsg = (char *) get_pool_memory(PM_FNAME);
-         Mmsg(emsg, _("is waiting on Storage %s"), jcr->store->hdr.name);
+         if (jcr->wstore) {
+            Mmsg(emsg, _("is waiting on Storage %s"), jcr->wstore->name());
+         } else {
+            Mmsg(emsg, _("is waiting on Storage %s"), jcr->rstore->name());
+         }
          pool_mem = true;
          msg = emsg;
          break;
@@ -609,7 +634,7 @@ static void list_running_jobs(UAContext *ua)
             pool_mem = true;
          }
          Mmsg(emsg, _("is waiting for Client %s to connect to Storage %s"),
-              jcr->client->hdr.name, jcr->store->hdr.name);
+              jcr->client->name(), jcr->wstore->name());
          msg = emsg;
          break;
       }
@@ -634,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");
 }
 
@@ -652,8 +677,8 @@ static void list_terminated_jobs(UAContext *ua)
    lock_last_jobs_list();
    struct s_last_job *je;
    bsendmsg(ua, _("\nTerminated Jobs:\n"));
-   bsendmsg(ua, _(" JobId  Level     Files      Bytes     Status   Finished        Name \n"));
-   bsendmsg(ua, _("========================================================================\n"));
+   bsendmsg(ua, _(" JobId  Level    Files      Bytes   Status   Finished        Name \n"));
+   bsendmsg(ua, _("====================================================================\n"));
    foreach_dlist(je, last_jobs) {
       char JobName[MAX_NAME_LENGTH];
       const char *termstat;
@@ -684,33 +709,33 @@ 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"),
+      bsendmsg(ua, _("%6d  %-6s %8s %10s  %-7s  %-8s %s\n"),
          je->JobId,
          level,
          edit_uint64_with_commas(je->JobFiles, b1),
-         edit_uint64_with_commas(je->JobBytes, b2),
+         edit_uint64_with_suffix(je->JobBytes, b2),
          termstat,
          dt, JobName);
    }
-   bsendmsg(ua, "\n");
+   bsendmsg(ua, _("\n"));
    unlock_last_jobs_list();
 }