/*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2009 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.
 
 /*
  * Find job start time if JobId specified, otherwise
- * find last full save for Incremental and Differential saves.
+ * find last Job start time Incremental and Differential saves.
  *
  *  StartTime is returned in stime
  *
    pm_strcpy(stime, "0000-00-00 00:00:00");   /* default */
    /* If no Id given, we must find corresponding job */
    if (jr->JobId == 0) {
-         /* Differential is since last Full backup */
-         Mmsg(mdb->cmd,
+      /* Differential is since last Full backup */
+      Mmsg(mdb->cmd,
 "SELECT StartTime FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND "
 "Level='%c' AND Name='%s' AND ClientId=%s AND FileSetId=%s "
 "ORDER BY StartTime DESC LIMIT 1",
 
       /* Look up start time of last Full job */
       now = (utime_t)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);
+      /*
+       * This is probably redundant, but some of the code below
+       * uses jcr->stime, so don't remove unless you are sure.
+       */
+      if (!db_find_job_start_time(jcr, jcr->db, &jcr->jr, &jcr->stime)) {
+         do_full = true;
+      }
+      have_full = db_find_last_job_start_time(jcr, jcr->db, &jcr->jr, &stime, L_FULL);
       if (have_full) {
-         last_full_time = str_to_utime(jcr->stime);
+         last_full_time = str_to_utime(stime);
       } else {
          do_full = true;               /* No full, upgrade to one */
       }
 
 
 #undef  VERSION
 #define VERSION "3.0.2"
-#define BDATE   "01 July 2009"
-#define LSMDATE "01Jul09"
+#define BDATE   "02 July 2009"
+#define LSMDATE "02Jul09"
 
 #define PROG_COPYRIGHT "Copyright (C) %d-2009 Free Software Foundation Europe e.V.\n"
 #define BYEAR "2009"       /* year for copyright messages in progs */
 
           
 General:
 
+02Jul09
+kes  Another fix for bug #1311 to get the correct last_full_time
 01Jul09
 kes  Fix bug #1317 Allow duplicate jobs = no does not work
 kes  Eliminate double job report when do_xxx_init() returns failure