From: Eric Bollengier Date: Tue, 10 Nov 2015 15:05:48 +0000 (+0100) Subject: Implement new options in list command X-Git-Tag: Release-7.4.0~180 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=69fce50cdc73876639645f4c0aa5a4267d075dd8;p=bacula%2Fbacula Implement new options in list command 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 | +-------+--------------+---------------------+------+ --- diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index a0b6c9bc21..42e833d145 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -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)