]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/jobq.c
Restart incomplete jobs only if type Backup
[bacula/bacula] / bacula / src / dird / jobq.c
index 0e4d68898d08edaca27f3e3f3d9cc3f284379447..7ceeb86f3e61f52870682b3bcd0d53bc03a556f2 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2003-2010 Free Software Foundation Europe e.V.
+   Copyright (C) 2003-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 two of the GNU General Public
+   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.
 
@@ -15,7 +15,7 @@
    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 General Public License
+   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.
@@ -612,21 +612,31 @@ void *jobq_server(void *arg)
  */
 static bool reschedule_job(JCR *jcr, jobq_t *jq, jobq_item_t *je)
 {
+   bool resched = false;
    /*
-    * Reschedule the job if necessary and requested
+    * Reschedule the job if requested and possible
     */
-   if (jcr->job->RescheduleOnError &&
-       jcr->JobStatus != JS_Terminated &&
-       jcr->JobStatus != JS_Canceled &&
-       jcr->getJobType() == JT_BACKUP &&
-       (jcr->job->RescheduleTimes == 0 ||
-        jcr->reschedule_count < jcr->job->RescheduleTimes)) {
+   /* Basic condition is that more reschedule times remain */
+   if (jcr->job->RescheduleTimes == 0 ||
+       jcr->reschedule_count < jcr->job->RescheduleTimes) {
+      resched = 
+         /* Check for incomplete jobs */
+         (jcr->job->RescheduleIncompleteJobs && 
+          jcr->is_incomplete() && jcr->is_JobType(JT_BACKUP)) ||
+         /* Check for failed jobs */
+         (jcr->job->RescheduleOnError &&
+          !jcr->is_JobStatus(JS_Terminated) &&
+          !jcr->is_JobStatus(JS_Canceled) &&
+          jcr->is_JobType(JT_BACKUP));
+   }
+   if (resched) {
        char dt[50], dt2[50];
 
        /*
         * Reschedule this job by cleaning it up, but
         *  reuse the same JobId if possible.
         */
+      jcr->incomplete = jcr->is_incomplete();   /* save incomplete status */
       time_t now = time(NULL);
       jcr->reschedule_count++;
       jcr->sched_time = now + jcr->job->RescheduleInterval;
@@ -640,10 +650,12 @@ static bool reschedule_job(JCR *jcr, jobq_t *jq, jobq_item_t *je)
       jcr->JobStatus = -1;
       set_jcr_job_status(jcr, JS_WaitStartTime);
       jcr->SDJobStatus = 0;
+      jcr->JobErrors = 0;
       if (!allow_duplicate_job(jcr)) {
          return false;
       }
-      if (jcr->JobBytes == 0) {
+      /* Only jobs with no output or Incomplete jobs can run on same JCR */
+      if (jcr->JobBytes == 0 || jcr->incomplete) {
          Dmsg2(2300, "Requeue job=%d use=%d\n", jcr->JobId, jcr->use_count());
          V(jq->mutex);
          jobq_add(jq, jcr);     /* queue the job to run again */