- case L_DIFFERENTIAL:
- case L_INCREMENTAL:
- /* Look up start time of last job */
- jcr->jr.JobId = 0;
- if (!db_find_job_start_time(jcr, jcr->db, &jcr->jr, &jcr->stime)) {
- Jmsg(jcr, M_INFO, 0, "%s", db_strerror(jcr->db));
- Jmsg(jcr, M_INFO, 0, _("No prior or suitable Full backup found. Doing FULL backup.\n"));
- bsnprintf(since, since_len, " (upgraded from %s)",
- level_to_str(jcr->JobLevel));
- jcr->JobLevel = jcr->jr.Level = L_FULL;
- } else {
- bstrncpy(since, ", since=", sizeof(since));
- bstrncat(since, jcr->stime, sizeof(since));
- }
- Dmsg1(115, "Last start time = %s\n", jcr->stime);
- break;
+ case L_DIFFERENTIAL:
+ case L_INCREMENTAL:
+ POOLMEM *stime = get_pool_memory(PM_MESSAGE);
+ /* Look up start time of last Full job */
+ now = time(NULL);
+ jcr->jr.JobId = 0; /* flag to return since time */
+ have_full = db_find_job_start_time(jcr, jcr->db, &jcr->jr, &jcr->stime);
+ /* If there was a successful job, make sure it is recent enough */
+ if (jcr->JobLevel == L_INCREMENTAL && have_full && jcr->job->MaxDiffInterval > 0) {
+ /* Lookup last diff job */
+ if (db_find_last_job_start_time(jcr, jcr->db, &jcr->jr, &stime, L_DIFFERENTIAL)) {
+ diff_time = str_to_utime(stime);
+ do_diff = ((now - diff_time) <= jcr->job->MaxDiffInterval);
+ }
+ }
+ if (have_full && jcr->job->MaxFullInterval > 0 &&
+ db_find_last_job_start_time(jcr, jcr->db, &jcr->jr, &stime, L_FULL)) {
+ full_time = str_to_utime(stime);
+ do_full = ((now - full_time) <= jcr->job->MaxFullInterval);
+ }
+ free_pool_memory(stime);
+
+ if (!have_full || do_full) {
+ /* No recent Full job found, so upgrade this one to Full */
+ Jmsg(jcr, M_INFO, 0, "%s", db_strerror(jcr->db));
+ Jmsg(jcr, M_INFO, 0, _("No prior or suitable Full backup found in catalog. Doing FULL backup.\n"));
+ bsnprintf(since, since_len, _(" (upgraded from %s)"),
+ level_to_str(jcr->JobLevel));
+ jcr->JobLevel = jcr->jr.JobLevel = L_FULL;
+ } else if (do_diff) {
+ /* No recent diff job found, so upgrade this one to Full */
+ Jmsg(jcr, M_INFO, 0, _("No prior or suitable Differential backup found in catalog. Doing Differential backup.\n"));
+ bsnprintf(since, since_len, _(" (upgraded from %s)"),
+ level_to_str(jcr->JobLevel));
+ jcr->JobLevel = jcr->jr.JobLevel = L_DIFFERENTIAL;
+ } else {
+ if (jcr->job->rerun_failed_levels) {
+ if (db_find_failed_job_since(jcr, jcr->db, &jcr->jr, jcr->stime, JobLevel)) {
+ Jmsg(jcr, M_INFO, 0, _("Prior failed job found in catalog. Upgrading to %s.\n"),
+ level_to_str(JobLevel));
+ bsnprintf(since, since_len, _(" (upgraded from %s)"),
+ level_to_str(jcr->JobLevel));
+ jcr->JobLevel = jcr->jr.JobLevel = JobLevel;
+ jcr->jr.JobId = jcr->JobId;
+ break;
+ }
+ }
+ bstrncpy(since, _(", since="), since_len);
+ bstrncat(since, jcr->stime, since_len);
+ }
+ jcr->jr.JobId = jcr->JobId;
+ break;