/* Forward referenced functions */
static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist);
-static bool list_nextvol(UAContext *ua);
+static bool list_nextvol(UAContext *ua, int ndays);
/*
* Turn auto display of console messages on/off
/* List next volume */
} else if (strcasecmp(ua->argk[i], N_("nextvol")) == 0 ||
strcasecmp(ua->argk[i], N_("nextvolume")) == 0) {
- list_nextvol(ua);
- } else if (strcasecmp(ua->argk[i], N_("limit")) == 0) {
+ n = 1;
+ j = find_arg_with_value(ua, N_("days"));
+ if (j >= 0) {
+ n = atoi(ua->argv[j]);
+ if ((n < 0) || (n > 50)) {
+ bsendmsg(ua, _("Ignoring illegal value for days.\n"));
+ n = 1;
+ }
+ }
+ list_nextvol(ua, n);
+ } else if (strcasecmp(ua->argk[i], N_("limit")) == 0
+ || strcasecmp(ua->argk[i], N_("days")) == 0) {
/* Ignore it */
} else {
bsendmsg(ua, _("Unknown list keyword: %s\n"), NPRT(ua->argk[i]));
return 1;
}
-static bool list_nextvol(UAContext *ua)
+static bool list_nextvol(UAContext *ua, int ndays)
{
JOB *job;
JCR *jcr = ua->jcr;
time_t runtime;
bool found = false;
MEDIA_DBR mr;
+ POOL_DBR pr;
memset(&mr, 0, sizeof(mr));
int i = find_arg_with_value(ua, "job");
}
}
}
- for (run=NULL; (run = find_next_run(run, job, runtime)); ) {
+ for (run=NULL; (run = find_next_run(run, job, runtime, ndays)); ) {
pool = run->pool ? run->pool : NULL;
if (!complete_jcr_for_job(jcr, job, pool)) {
return false;
if (run->storage) {
jcr->store = run->storage;
}
+ memset(&pr, 0, sizeof(pr));
+ pr.PoolId = jcr->PoolId;
+ if (! db_get_pool_record(ua->jcr, ua->db, &pr)) {
+ strcpy(pr.Name, "*UnknownPool*");
+ }
if (!find_next_volume_for_append(jcr, &mr, 0)) {
- bsendmsg(ua, _("Could not find next Volume.\n"));
+ bsendmsg(ua, _("Could not find next Volume for Job %s (%s, %s).\n"),
+ job->hdr.name, pr.Name, level_to_str(run->level));
} else {
- bsendmsg(ua, _("The next Volume to be used by Job \"%s\" will be %s\n"),
- job->hdr.name, mr.VolumeName);
+ bsendmsg(ua,
+ _("The next Volume to be used by Job \"%s\" (%s, %s) will be %s\n"),
+ job->hdr.name, pr.Name, level_to_str(run->level), mr.VolumeName);
found = true;
}
if (jcr->db && jcr->db != ua->db) {
}
}
if (!found) {
- bsendmsg(ua, _("Could not find next Volume.\n"));
+ bsendmsg(ua, _("Could not find next Volume for Job %s.\n"),
+ job->hdr.name);
return false;
}
return true;
* For a given job, we examine all his run records
* to see if it is scheduled today or tomorrow.
*/
-RUN *find_next_run(RUN *run, JOB *job, time_t &runtime)
+RUN *find_next_run(RUN *run, JOB *job, time_t &runtime, int ndays)
{
- time_t now, tomorrow;
+ time_t now, future, endtime;
SCHED *sched;
- struct tm tm;
- int mday, wday, month, wom, tmday, twday, tmonth, twom, i;
- int woy, twoy;
- int tod, tom;
+ struct tm tm, runtm;
+ int mday, wday, month, wom, i;
+ int woy;
+ int day;
+ int is_scheduled;
sched = job->schedule;
if (sched == NULL) { /* scheduled? */
return NULL; /* no nothing to report */
}
- /* Break down current time into components */
+
+ /* Break down the time into components */
now = time(NULL);
- localtime_r(&now, &tm);
- mday = tm.tm_mday - 1;
- wday = tm.tm_wday;
- month = tm.tm_mon;
- wom = mday / 7;
- woy = tm_woy(now);
-
- /* Break down tomorrow into components */
- tomorrow = now + 60 * 60 * 24;
- localtime_r(&tomorrow, &tm);
- tmday = tm.tm_mday - 1;
- twday = tm.tm_wday;
- tmonth = tm.tm_mon;
- twom = tmday / 7;
- twoy = tm_woy(tomorrow);
+ endtime = now + (ndays * 60 * 60 * 24);
if (run == NULL) {
run = sched->run;
/*
* Find runs in next 24 hours
*/
- tod = bit_is_set(mday, run->mday) && bit_is_set(wday, run->wday) &&
+ for (day = 0; day <= ndays; day++) {
+ future = now + (day * 60 * 60 * 24);
+
+ /* Break down the time into components */
+ localtime_r(&future, &tm);
+ mday = tm.tm_mday - 1;
+ wday = tm.tm_wday;
+ month = tm.tm_mon;
+ wom = mday / 7;
+ woy = tm_woy(future);
+
+ is_scheduled = bit_is_set(mday, run->mday) && bit_is_set(wday, run->wday) &&
bit_is_set(month, run->month) && bit_is_set(wom, run->wom) &&
bit_is_set(woy, run->woy);
-
- tom = bit_is_set(tmday, run->mday) && bit_is_set(twday, run->wday) &&
- bit_is_set(tmonth, run->month) && bit_is_set(twom, run->wom) &&
- bit_is_set(twoy, run->woy);
-
+
#ifdef xxx
- Dmsg2(000, "tod=%d tom=%d\n", tod, tom);
- Dmsg1(000, "bit_set_mday=%d\n", bit_is_set(mday, run->mday));
- Dmsg1(000, "bit_set_wday=%d\n", bit_is_set(wday, run->wday));
- Dmsg1(000, "bit_set_month=%d\n", bit_is_set(month, run->month));
- Dmsg1(000, "bit_set_wom=%d\n", bit_is_set(wom, run->wom));
- Dmsg1(000, "bit_set_woy=%d\n", bit_is_set(woy, run->woy));
+ Dmsg2(000, "day=%d is_scheduled=%d\n", day, is_scheduled);
+ Dmsg1(000, "bit_set_mday=%d\n", bit_is_set(mday, run->mday));
+ Dmsg1(000, "bit_set_wday=%d\n", bit_is_set(wday, run->wday));
+ Dmsg1(000, "bit_set_month=%d\n", bit_is_set(month, run->month));
+ Dmsg1(000, "bit_set_wom=%d\n", bit_is_set(wom, run->wom));
+ Dmsg1(000, "bit_set_woy=%d\n", bit_is_set(woy, run->woy));
#endif
- if (tod) { /* Jobs scheduled today (next 24 hours) */
+
+ if (is_scheduled) { /* Jobs scheduled on that day */
#ifdef xxx
- char buf[300], num[10];
- bsnprintf(buf, sizeof(buf), "tm.hour=%d hour=", tm.tm_hour);
- for (i=0; i<24; i++) {
- if (bit_is_set(i, run->hour)) {
- bsnprintf(num, sizeof(num), "%d ", i);
- bstrncat(buf, num, sizeof(buf));
- }
- }
- bstrncat(buf, "\n", sizeof(buf));
- Dmsg1(000, "%s", buf);
+ char buf[300], num[10];
+ bsnprintf(buf, sizeof(buf), "tm.hour=%d hour=", tm.tm_hour);
+ for (i=0; i<24; i++) {
+ if (bit_is_set(i, run->hour)) {
+ bsnprintf(num, sizeof(num), "%d ", i);
+ bstrncat(buf, num, sizeof(buf));
+ }
+ }
+ bstrncat(buf, "\n", sizeof(buf));
+ Dmsg1(000, "%s", buf);
#endif
- /* find time (time_t) job is to be run */
- localtime_r(&now, &tm);
- for (i=tm.tm_hour; i < 24; i++) {
- if (bit_is_set(i, run->hour)) {
- tm.tm_hour = i;
- tm.tm_min = run->minute;
- tm.tm_sec = 0;
- runtime = mktime(&tm);
- Dmsg2(200, "now=%d runtime=%d\n", now, runtime);
- if (runtime > now) {
- Dmsg2(200, "Found it level=%d %c\n", run->level, run->level);
- return run; /* found it, return run resource */
- }
- }
- }
- }
-
-// Dmsg2(200, "runtime=%d now=%d\n", runtime, now);
- if (tom) { /* look at jobs scheduled tomorrow */
- localtime_r(&tomorrow, &tm);
- for (i=0; i < 24; i++) {
- if (bit_is_set(i, run->hour)) {
- tm.tm_hour = i;
- tm.tm_min = run->minute;
- tm.tm_sec = 0;
- runtime = mktime(&tm);
- Dmsg2(200, "now=%d runtime=%d\n", now, runtime);
- if (runtime < tomorrow) {
- Dmsg2(200, "Found it level=%d %c\n", run->level, run->level);
- return run; /* found it, return run resource */
- }
- }
- }
+ /* find time (time_t) job is to be run */
+ localtime_r(&future, &runtm);
+ for (i= 0; i < 24; i++) {
+ if (bit_is_set(i, run->hour)) {
+ runtm.tm_hour = i;
+ runtm.tm_min = run->minute;
+ runtm.tm_sec = 0;
+ runtime = mktime(&runtm);
+ Dmsg2(200, "now=%d runtime=%d\n", now, runtime);
+ if ((runtime > now) && (runtime < endtime)) {
+ Dmsg2(200, "Found it level=%d %c\n", run->level, run->level);
+ return run; /* found it, return run resource */
+ }
+ }
+ }
+ }
}
} /* end for loop over runs */
/* Nothing found */