+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
+
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ 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
+ License as published by the Free Software Foundation and included
+ in the file LICENSE.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of Kern Sibbald.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
/*
*
* Bacula scheduler
*
* Kern Sibbald, May MM, major revision December MMIII
*
- * Version $Id$
- */
-/*
- Copyright (C) 2000-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 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,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- the file LICENSE for additional details.
-
*/
#include "bacula.h"
static dlist *jobs_to_run; /* list of jobs to be run */
/* Time interval in secs to sleep if nothing to be run */
-static int const NEXT_CHECK_SECS = 60;
+static int const next_check_secs = 60;
/* Forward referenced subroutines */
static void find_runs();
JCR *jcr;
JOB *job;
RUN *run;
- time_t now;
+ time_t now, prev;
static bool first = true;
job_item *next_job = NULL;
return jcr;
}
}
+
/* Wait until we have something in the
* next hour or so.
*/
if (!jobs_to_run->empty()) {
break;
}
- bmicrosleep(NEXT_CHECK_SECS, 0); /* recheck once per minute */
+ bmicrosleep(next_check_secs, 0); /* recheck once per minute */
}
#ifdef list_chain
/* Now wait for the time to run the job */
for (;;) {
time_t twait;
- if (schedules_invalidated) { /** discard scheduled queue and rebuild with new schedule objects. **/
+ /** discard scheduled queue and rebuild with new schedule objects. **/
+ lock_jobs();
+ if (schedules_invalidated) {
dump_job(next_job, "Invalidated job");
free(next_job);
while (!jobs_to_run->empty()) {
free(next_job);
}
schedules_invalidated = false;
+ unlock_jobs();
goto again;
}
- now = time(NULL);
+ unlock_jobs();
+ prev = now = time(NULL);
twait = next_job->runtime - now;
if (twait <= 0) { /* time to run it */
break;
}
- bmicrosleep((NEXT_CHECK_SECS<twait)?NEXT_CHECK_SECS:twait, 0); /* recheck at least once per minute */
+ /* Recheck at least once per minute */
+ bmicrosleep((next_check_secs < twait)?next_check_secs:twait, 0);
+ /* Attempt to handle clock shift (but not daylight savings time changes)
+ * we allow a skew of 10 seconds before invalidating everything.
+ */
+ now = time(NULL);
+ if (now < prev-10 || now > (prev+next_check_secs+10)) {
+ schedules_invalidated = true;
+ }
}
+ jcr = new_jcr(sizeof(JCR), dird_free_jcr);
run = next_job->run; /* pick up needed values */
job = next_job->job;
if (job->enabled) {
}
free(next_job);
if (!job->enabled) {
+ free_jcr(jcr);
goto again; /* ignore this job */
}
run->last_run = now; /* mark as run now */
- jcr = new_jcr(sizeof(JCR), dird_free_jcr);
ASSERT(job);
set_jcr_defaults(jcr, job);
if (run->level) {
- jcr->JobLevel = run->level; /* override run level */
+ jcr->setJobLevel(run->level); /* override run level */
}
if (run->pool) {
jcr->pool = run->pool; /* override pool */
+ jcr->run_pool_override = true;
}
if (run->full_pool) {
jcr->full_pool = run->full_pool; /* override full pool */
+ jcr->run_full_pool_override = true;
}
if (run->inc_pool) {
jcr->inc_pool = run->inc_pool; /* override inc pool */
+ jcr->run_inc_pool_override = true;
}
- if (run->dif_pool) {
- jcr->dif_pool = run->dif_pool; /* override dif pool */
+ if (run->diff_pool) {
+ jcr->diff_pool = run->diff_pool; /* override dif pool */
+ jcr->run_diff_pool_override = true;
}
if (run->storage) {
- set_storage(jcr, run->storage); /* override storage */
+ USTORE store;
+ store.store = run->storage;
+ pm_strcpy(store.store_source, _("run override"));
+ set_rwstorage(jcr, &store); /* override storage */
}
if (run->msgs) {
jcr->messages = run->msgs; /* override messages */
if (run->spool_data_set) {
jcr->spool_data = run->spool_data;
}
+ if (run->accurate_set) { /* overwrite accurate mode */
+ jcr->accurate = run->accurate;
+ }
if (run->write_part_after_job_set) {
jcr->write_part_after_job = run->write_part_after_job;
}
+ if (run->MaxRunSchedTime_set) {
+ jcr->MaxRunSchedTime = run->MaxRunSchedTime;
+ }
Dmsg0(dbglvl, "Leave wait_for_next_job()\n");
return jcr;
}
void term_scheduler()
{
if (jobs_to_run) {
- job_item *je;
- /* Release all queued job entries to be run */
- foreach_dlist(je, jobs_to_run) {
- free(je);
- }
delete jobs_to_run;
}
}
JOB *job;
SCHED *sched;
struct tm tm;
- int minute;
int hour, mday, wday, month, wom, woy;
/* Items corresponding to above at the next hour */
- int nh_hour, nh_mday, nh_wday, nh_month, nh_wom, nh_woy, nh_year;
+ int nh_hour, nh_mday, nh_wday, nh_month, nh_wom, nh_woy;
Dmsg0(dbglvl, "enter find_runs()\n");
-
/* compute values for time now */
now = time(NULL);
- localtime_r(&now, &tm);
+ (void)localtime_r(&now, &tm);
hour = tm.tm_hour;
- minute = tm.tm_min;
mday = tm.tm_mday - 1;
wday = tm.tm_wday;
month = tm.tm_mon;
wom = mday / 7;
woy = tm_woy(now); /* get week of year */
+ Dmsg7(dbglvl, "now = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
+ now, hour, month, mday, wday, wom, woy);
+
/*
* Compute values for next hour from now.
* We do this to be sure we don't miss a job while
* sleeping.
*/
next_hour = now + 3600;
- localtime_r(&next_hour, &tm);
+ (void)localtime_r(&next_hour, &tm);
nh_hour = tm.tm_hour;
nh_mday = tm.tm_mday - 1;
nh_wday = tm.tm_wday;
nh_month = tm.tm_mon;
- nh_year = tm.tm_year;
nh_wom = nh_mday / 7;
- nh_woy = tm_woy(now); /* get week of year */
+ nh_woy = tm_woy(next_hour); /* get week of year */
+
+ Dmsg7(dbglvl, "nh = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
+ next_hour, nh_hour, nh_month, nh_mday, nh_wday, nh_wom, nh_woy);
/* Loop through all jobs */
LockRes();
Dmsg3(dbglvl, "run@%p: run_now=%d run_nh=%d\n", run, run_now, run_nh);
- /* find time (time_t) job is to be run */
- localtime_r(&now, &tm); /* reset tm structure */
- tm.tm_min = run->minute; /* set run minute */
- tm.tm_sec = 0; /* zero secs */
- if (run_now) {
- runtime = mktime(&tm);
- add_job(job, run, now, runtime);
- }
- /* If job is to be run in the next hour schedule it */
- if (run_nh) {
- /* Set correct values */
- tm.tm_hour = nh_hour;
- tm.tm_mday = nh_mday + 1; /* fixup because we biased for tests above */
- tm.tm_mon = nh_month;
- tm.tm_year = nh_year;
- runtime = mktime(&tm);
- add_job(job, run, now, runtime);
+ if (run_now || run_nh) {
+ /* find time (time_t) job is to be run */
+ (void)localtime_r(&now, &tm); /* reset tm structure */
+ tm.tm_min = run->minute; /* set run minute */
+ tm.tm_sec = 0; /* zero secs */
+ runtime = mktime(&tm);
+ if (run_now) {
+ add_job(job, run, now, runtime);
+ }
+ /* If job is to be run in the next hour schedule it */
+ if (run_nh) {
+ add_job(job, run, now, runtime + 3600);
+ }
}
}
}
*/
if (((runtime - run->last_run) < 61) || ((runtime+59) < now)) {
#ifdef SCHED_DEBUG
- char dt[50], dt1[50], dt2[50];
- bstrftime_nc(dt, sizeof(dt), runtime);
- bstrftime_nc(dt1, sizeof(dt1), run->last_run);
- bstrftime_nc(dt2, sizeof(dt2), now);
- Dmsg7(000, "Drop: Job=\"%s\" run=%s(%x). last_run=%s(%x). now=%s(%x)\n", job->hdr.name,
- dt, runtime, dt1, run->last_run, dt2, now);
+ Dmsg4(000, "Drop: Job=\"%s\" run=%lld. last_run=%lld. now=%lld\n", job->hdr.name,
+ (utime_t)runtime, (utime_t)run->last_run, (utime_t)now);
fflush(stdout);
#endif
return;
}
#ifdef SCHED_DEBUG
- Dmsg4(000, "Add: Job=\"%s\" run=%x last_run=%x now=%x\n", job->hdr.name,
- runtime, run->last_run, now);
+ Dmsg4(000, "Add: Job=\"%s\" run=%lld last_run=%lld now=%lld\n", job->hdr.name,
+ (utime_t)runtime, (utime_t)run->last_run, (utime_t)now);
#endif
/* accept to run this job */
job_item *je = (job_item *)malloc(sizeof(job_item));