Skip to content

Commit

Permalink
Added until_jobid parameter to "rerun" command
Browse files Browse the repository at this point in the history
Fixes #405: rerun command shoud be able to accept jobid interval
  • Loading branch information
Oleg Livshyts authored and joergsteffens committed Jan 30, 2015
1 parent 75a52e3 commit c882d10
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/dird/ua_cmds.c
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2014 Bareos GmbH & Co. KG
Copyright (C) 2013-2015 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -188,7 +188,7 @@ static struct cmdstruct commands[] = {
{ NT_("reload"), reload_cmd, _("Reload conf file"),
NT_(""), true, true },
{ NT_("rerun"), rerun_cmd, _("Rerun a job"),
NT_("jobid=<jobid> | since_jobid=<jobid> | days=<nr_days> | hours=<nr_hours> | yes"), false, true },
NT_("jobid=<jobid> | since_jobid=<jobid> [ until_jobid=<jobid> ] | days=<nr_days> | hours=<nr_hours> | yes"), false, true },
{ NT_("resolve"), resolve_cmd, _("Resolve a hostname"),
NT_("client=<client-name> | storage=<storage-name> <host-name>"), false, true },
{ NT_("run"), run_cmd, _("Run a job"),
Expand Down
23 changes: 19 additions & 4 deletions src/dird/ua_run.c
Expand Up @@ -131,10 +131,11 @@ static inline bool rerun_job(UAContext *ua, JobId_t JobId, bool yes, utime_t now
*/
int rerun_cmd(UAContext *ua, const char *cmd)
{
int i, j, d, h, s;
int i, j, d, h, s, u;
int days = 0;
int hours = 0;
int since_jobid = 0;
int until_jobid = 0;
struct tm tm;
JobId_t JobId;
dbid_list ids;
Expand All @@ -143,9 +144,11 @@ int rerun_cmd(UAContext *ua, const char *cmd)
time_t schedtime;
char dt[MAX_TIME_LENGTH];
char ed1[50];
char ed2[50];
bool yes = false; /* Was "yes" given on cmdline*/
bool timeframe = false; /* Should the selection happen based on timeframe? */
bool since_jobid_given = false; /* Was since_jobid given? */
bool until_jobid_given = false; /* Was until_jobid given? */
const int secs_in_day = 86400;
const int secs_in_hour = 3600;

Expand All @@ -162,12 +165,18 @@ int rerun_cmd(UAContext *ua, const char *cmd)
d = find_arg_with_value(ua, NT_("days"));
h = find_arg_with_value(ua, NT_("hours"));
s = find_arg_with_value(ua, NT_("since_jobid"));
u = find_arg_with_value(ua, NT_("until_jobid"));

if (s > 0) {
since_jobid = str_to_int64(ua->argv[s]);
since_jobid_given = true;
}

if (u > 0) {
until_jobid = str_to_int64(ua->argv[u]);
until_jobid_given = true;
}

if (d > 0 || h > 0) {
timeframe = true;
}
Expand All @@ -182,7 +191,7 @@ int rerun_cmd(UAContext *ua, const char *cmd)
}

if (j >= 0 && since_jobid_given) {
ua->send_msg("Please specifiy either jobid or since_jobid\n");
ua->send_msg("Please specifiy either jobid or since_jobid (and optionally until_jobid)\n");
goto bail_out;
}

Expand All @@ -208,8 +217,14 @@ int rerun_cmd(UAContext *ua, const char *cmd)
strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm);

if (since_jobid_given) {
Mmsg(query, "SELECT JobId FROM Job WHERE JobStatus = 'f' AND JobId >= %s ORDER BY JobId",
edit_int64(since_jobid, ed1));
if (until_jobid_given) {
Mmsg(query, "SELECT JobId FROM Job WHERE JobStatus = 'f' AND JobId >= %s AND JobId <= %s ORDER BY JobId",
edit_int64(since_jobid, ed1), edit_int64(until_jobid, ed2));
} else {
Mmsg(query, "SELECT JobId FROM Job WHERE JobStatus = 'f' AND JobId >= %s ORDER BY JobId",
edit_int64(since_jobid, ed1));
}

} else {
Mmsg(query, "SELECT JobId FROM Job WHERE JobStatus = 'f' AND SchedTime > '%s' ORDER BY JobId", dt);
}
Expand Down

0 comments on commit c882d10

Please sign in to comment.