]> git.sur5r.net Git - bacula/bacula/commitdiff
Implement new options in list command
authorEric Bollengier <eric@baculasystems.com>
Tue, 10 Nov 2015 15:05:48 +0000 (16:05 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 21 Nov 2015 17:56:46 +0000 (09:56 -0800)
It is possible to use the following arguments:
 - order=asc/desc
 - joberrors
 - jobstatus=T
 - client=xxx

*list jobs
+-------+--------------+---------------------+------+
| jobid | name         | starttime           | type |
+-------+--------------+---------------------+------+
|     1 | backup       | 2015-11-10 14:21:38 | B    |
|     2 | RestoreFiles | 2015-11-10 14:21:44 | R    |
|     3 | backup       | 2015-11-10 14:21:56 | B    |
|     4 | RestoreFiles | 2015-11-10 14:22:00 | R    |
+-------+--------------+---------------------+------+
*list jobs order=desc
+-------+--------------+---------------------+------+
| jobid | name         | starttime           | type |
+-------+--------------+---------------------+------+
|     4 | RestoreFiles | 2015-11-10 14:22:00 | R    |
|     3 | backup       | 2015-11-10 14:21:56 | B    |
|     2 | RestoreFiles | 2015-11-10 14:21:44 | R    |
|     1 | backup       | 2015-11-10 14:21:38 | B    |
+-------+--------------+---------------------+------+
*list jobs order=desc limit=1
+-------+--------------+---------------------+------+
| jobid | name         | starttime           | type |
+-------+--------------+---------------------+------+
|     4 | RestoreFiles | 2015-11-10 14:22:00 | R    |
+-------+--------------+---------------------+------+

bacula/src/dird/ua_output.c

index a0b6c9bc21b57e1e447e1bf5947e0a3eae918e85..42e833d1459f23fb2305b55dfe65e717493914f6 100644 (file)
@@ -350,11 +350,37 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
    if (!ua->db) {
       ua->error_msg(_("Hey! DB is NULL\n"));
    }
-
    /* Apply any limit */
-   j = find_arg_with_value(ua, NT_("limit"));
-   if (j >= 0) {
-      jr.limit = atoi(ua->argv[j]);
+   for (j = 1; j < ua->argc ; j++) {
+      if (strcasecmp(ua->argk[j], NT_("joberrors")) == 0) {
+         jr.JobErrors = 1;
+      } else if (!ua->argv[j]) {
+         /* skip */
+      } else if (strcasecmp(ua->argk[j], NT_("order")) == 0) {
+         if (strcasecmp(ua->argv[j], NT_("desc")) == 0) {
+            jr.order = 1;
+         } else if (strcasecmp(ua->argv[j], NT_("asc")) == 0) {
+            jr.order = 0;
+         } else {
+            ua->error_msg(_("Unknown order type %s\n"), ua->argv[j]);
+            return 1;
+         }
+      } else if (strcasecmp(ua->argk[j], NT_("limit")) == 0) {
+         jr.limit = atoi(ua->argv[j]);
+
+      } else if (strcasecmp(ua->argk[j], NT_("jobstatus")) == 0) {
+         if (B_ISALPHA(ua->argv[j][0])) {
+            jr.JobStatus = ua->argv[j][0];
+         }
+      } else if (strcasecmp(ua->argk[j], NT_("client")) == 0) {
+         if (is_name_valid(ua->argv[j], NULL)) {
+            CLIENT_DBR cr;
+            memset(&cr, 0, sizeof(cr));
+            if(get_client_dbr(ua, &cr)) {
+               jr.ClientId = cr.ClientId;
+            }
+         }
+      }
    }
 
    /* Scan arguments looking for things to do */
@@ -579,7 +605,12 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
          }
          db_list_copies_records(ua->jcr,ua->db,limit,jobids,prtit,ua,llist);
       } else if (strcasecmp(ua->argk[i], NT_("limit")) == 0
-                 || strcasecmp(ua->argk[i], NT_("days")) == 0) {
+                 || strcasecmp(ua->argk[i], NT_("days")) == 0
+                 || strcasecmp(ua->argk[i], NT_("joberrors")) == 0
+                 || strcasecmp(ua->argk[i], NT_("order")) == 0
+                 || strcasecmp(ua->argk[i], NT_("jobstatus")) == 0
+                 || strcasecmp(ua->argk[i], NT_("client")) == 0
+         ) {
          /* Ignore it */
       } else if (strcasecmp(ua->argk[i], NT_("snapshot")) == 0 ||
                  strcasecmp(ua->argk[i], NT_("snapshots")) == 0)