]> git.sur5r.net Git - bacula/bacula/commitdiff
Send previous Job name during Incremental/Differential to the FD
authorEric Bollengier <eric@baculasystems.com>
Fri, 6 Jan 2012 21:06:49 +0000 (22:06 +0100)
committerEric Bollengier <eric@baculasystems.com>
Fri, 6 Jan 2012 22:18:36 +0000 (23:18 +0100)
bacula/src/cats/protos.h
bacula/src/cats/sql_find.c
bacula/src/dird/fd_cmds.c
bacula/src/filed/fd_plugins.c
bacula/src/filed/fd_plugins.h
bacula/src/filed/job.c
bacula/src/jcr.h

index a6777a45700be1671247632ecb442555555166ca..c0a4aff7f6f1f23854754d420a39403963a4c8d4 100644 (file)
@@ -75,8 +75,8 @@ int db_delete_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pool_dbr);
 int db_delete_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
 
 /* sql_find.c */
-bool db_find_last_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, int JobLevel);
-bool db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime);
+bool db_find_last_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, char *job, int JobLevel);
+bool db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, char *job);
 bool db_find_last_jobid(JCR *jcr, B_DB *mdb, const char *Name, JOB_DBR *jr);
 int db_find_next_volume(JCR *jcr, B_DB *mdb, int index, bool InChanger, MEDIA_DBR *mr);
 bool db_find_failed_job_since(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM *stime, int &JobLevel);
index 1f2f22f9c55ea7e70b9ae682a1d328a01028777e..d012d6e61b36d9339e166fb8372fbb4ef4264382 100644 (file)
  * find last Job start time Incremental and Differential saves.
  *
  *  StartTime is returned in stime
+ *  Job name is returned in job (MAX_NAME_LENGTH)
  *
  * Returns: 0 on failure
- *          1 on success, jr is unchanged, but stime is set
+ *          1 on success, jr is unchanged, but stime and job are set
  */
 bool
-db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime)
+db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, char *job)
 {
    SQL_ROW row;
    char ed1[50], ed2[50];
@@ -70,11 +71,13 @@ db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime)
    db_lock(mdb);
    mdb->db_escape_string(jcr, esc_name, jr->Name, strlen(jr->Name));
    pm_strcpy(stime, "0000-00-00 00:00:00");   /* default */
+   job[0] = 0;
+
    /* If no Id given, we must find corresponding job */
    if (jr->JobId == 0) {
       /* Differential is since last Full backup */
       Mmsg(mdb->cmd,
-"SELECT StartTime FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND "
+"SELECT StartTime, Job 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",
            jr->JobType, L_FULL, esc_name, 
@@ -104,7 +107,7 @@ db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime)
          sql_free_result(mdb);
          /* Now edit SQL command for Incremental Job */
          Mmsg(mdb->cmd,
-"SELECT StartTime FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND "
+"SELECT StartTime, Job FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND "
 "Level IN ('%c','%c','%c') AND Name='%s' AND ClientId=%s "
 "AND FileSetId=%s ORDER BY StartTime DESC LIMIT 1",
             jr->JobType, L_INCREMENTAL, L_DIFFERENTIAL, L_FULL, esc_name,
@@ -115,7 +118,7 @@ db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime)
       }
    } else {
       Dmsg1(100, "Submitting: %s\n", mdb->cmd);
-      Mmsg(mdb->cmd, "SELECT StartTime FROM Job WHERE Job.JobId=%s", 
+      Mmsg(mdb->cmd, "SELECT StartTime, Job FROM Job WHERE Job.JobId=%s", 
            edit_int64(jr->JobId, ed1));
    }
 
@@ -132,8 +135,9 @@ db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime)
       sql_free_result(mdb);
       goto bail_out;
    }
-   Dmsg1(100, "Got start time: %s\n", row[0]);
+   Dmsg2(100, "Got start time: %s, job: %s\n", row[0], row[1]);
    pm_strcpy(stime, row[0]);
+   bstrncpy(job, row[1], MAX_NAME_LENGTH);
 
    sql_free_result(mdb);
 
@@ -150,12 +154,14 @@ bail_out:
  * Find the last job start time for the specified JobLevel
  *
  *  StartTime is returned in stime
+ *  Job name is returned in job (MAX_NAME_LENGTH)
  *
  * Returns: false on failure
- *          true  on success, jr is unchanged, but stime is set
+ *          true  on success, jr is unchanged, but stime and job are set
  */
 bool
-db_find_last_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, int JobLevel)
+db_find_last_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, 
+                            POOLMEM **stime, char *job, int JobLevel)
 {
    SQL_ROW row;
    char ed1[50], ed2[50];
@@ -164,9 +170,10 @@ db_find_last_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, i
    db_lock(mdb);
    mdb->db_escape_string(jcr, esc_name, jr->Name, strlen(jr->Name));
    pm_strcpy(stime, "0000-00-00 00:00:00");   /* default */
+   job[0] = 0;
 
    Mmsg(mdb->cmd,
-"SELECT StartTime FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND "
+"SELECT StartTime, Job 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",
       jr->JobType, JobLevel, esc_name, 
@@ -183,6 +190,8 @@ db_find_last_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, i
    }
    Dmsg1(100, "Got start time: %s\n", row[0]);
    pm_strcpy(stime, row[0]);
+   bstrncpy(job, row[1], MAX_NAME_LENGTH);
+
    sql_free_result(mdb);
    db_unlock(mdb);
    return true;
index 0add6c181ee92e3c022c6c4fbfa43572138d6b17..e294b2981dc350b59a2fdddc25416e533bbbd323 100644 (file)
@@ -49,7 +49,7 @@ const int dbglvl = 400;
 static char filesetcmd[]  = "fileset%s\n"; /* set full fileset */
 static char jobcmd[]      = "JobId=%s Job=%s SDid=%u SDtime=%u Authorization=%s\n";
 /* Note, mtime_only is not used here -- implemented as file option */
-static char levelcmd[]    = "level = %s%s%s mtime_only=%d\n";
+static char levelcmd[]    = "level = %s%s%s mtime_only=%d %s%s\n";
 static char runscript[]   = "Run OnSuccess=%u OnFailure=%u AbortOnError=%u When=%u Command=%s\n";
 static char runbeforenow[]= "RunBeforeNow\n";
 
@@ -176,6 +176,7 @@ void get_level_since_time(JCR *jcr, char *since, int since_len)
    utime_t now;
    utime_t last_full_time = 0;
    utime_t last_diff_time;
+   char prev_job[MAX_NAME_LENGTH];
 
    since[0] = 0;
    /* If job cloned and a since time already given, use it */
@@ -188,7 +189,7 @@ void get_level_since_time(JCR *jcr, char *since, int since_len)
    if (!jcr->stime) {
       jcr->stime = get_pool_memory(PM_MESSAGE);
    } 
-   jcr->stime[0] = 0;
+   jcr->PrevJob[0] = jcr->stime[0] = 0;
    /*
     * Lookup the last FULL backup job to get the time/date for a
     * differential or incremental save.
@@ -204,10 +205,11 @@ void get_level_since_time(JCR *jcr, char *since, int since_len)
        * 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)) {
+      if (!db_find_job_start_time(jcr,jcr->db, &jcr->jr, &jcr->stime, jcr->PrevJob)) {
          do_full = true;
       }
-      have_full = db_find_last_job_start_time(jcr, jcr->db, &jcr->jr, &stime, L_FULL);
+      have_full = db_find_last_job_start_time(jcr, jcr->db, &jcr->jr, 
+                                              &stime, prev_job, L_FULL);
       if (have_full) {
          last_full_time = str_to_utime(stime);
       } else {
@@ -218,7 +220,8 @@ void get_level_since_time(JCR *jcr, char *since, int since_len)
       /* Make sure the last diff is recent enough */
       if (have_full && jcr->getJobLevel() == L_INCREMENTAL && jcr->job->MaxDiffInterval > 0) {
          /* Lookup last diff job */
-         if (db_find_last_job_start_time(jcr, jcr->db, &jcr->jr, &stime, L_DIFFERENTIAL)) {
+         if (db_find_last_job_start_time(jcr, jcr->db, &jcr->jr, 
+                                         &stime, prev_job, L_DIFFERENTIAL)) {
             last_diff_time = str_to_utime(stime);
             /* If no Diff since Full, use Full time */
             if (last_diff_time < last_full_time) {
@@ -255,7 +258,8 @@ void get_level_since_time(JCR *jcr, char *since, int since_len)
          jcr->setJobLevel(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)) {
+            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)"),
@@ -271,7 +275,8 @@ void get_level_since_time(JCR *jcr, char *since, int since_len)
       jcr->jr.JobId = jcr->JobId;
       break;
    }
-   Dmsg2(100, "Level=%c last start time=%s\n", jcr->getJobLevel(), jcr->stime);
+   Dmsg3(100, "Level=%c last start time=%s job=%s\n", 
+         jcr->getJobLevel(), jcr->stime, jcr->PrevJob);
 }
 
 static void send_since_time(JCR *jcr)
@@ -281,7 +286,8 @@ static void send_since_time(JCR *jcr)
    char ed1[50];
 
    stime = str_to_utime(jcr->stime);
-   fd->fsend(levelcmd, "", NT_("since_utime "), edit_uint64(stime, ed1), 0);
+   fd->fsend(levelcmd, "", NT_("since_utime "), edit_uint64(stime, ed1), 0, 
+             NT_("prev_job="), jcr->PrevJob);
    while (bget_dirmsg(fd) >= 0) {  /* allow him to poll us to sync clocks */
       Jmsg(jcr, M_INFO, 0, "%s\n", fd->msg);
    }
@@ -302,19 +308,19 @@ bool send_level_command(JCR *jcr)
     */
    switch (jcr->getJobLevel()) {
    case L_BASE:
-      fd->fsend(levelcmd, not_accurate, "base", rerunning, 0);
+      fd->fsend(levelcmd, not_accurate, "base", rerunning, 0, "", "");
       break;
    /* L_NONE is the console, sending something off to the FD */
    case L_NONE:
    case L_FULL:
-      fd->fsend(levelcmd, not_accurate, "full", rerunning, 0);
+      fd->fsend(levelcmd, not_accurate, "full", rerunning, 0, "", "");
       break;
    case L_DIFFERENTIAL:
-      fd->fsend(levelcmd, accurate, "differential", rerunning, 0);
+      fd->fsend(levelcmd, accurate, "differential", rerunning, 0, "", "");
       send_since_time(jcr);
       break;
    case L_INCREMENTAL:
-      fd->fsend(levelcmd, accurate, "incremental", rerunning, 0);
+      fd->fsend(levelcmd, accurate, "incremental", rerunning, 0, "", "");
       send_since_time(jcr);
       break;
    case L_SINCE:
index 8f09df3744e634da46be97497006ef4c38b21a61..3fba6cc8b19a106af69c6606f80eb8127c235545 100644 (file)
@@ -1300,6 +1300,10 @@ static bRC baculaGetValue(bpContext *ctx, bVariable var, void *value)
       *((char **)value) = jcr->Job;
       Dmsg1(dbglvl, "Bacula: return Job name=%s\n", jcr->Job);
       break;
+   case bVarPrevJobName:
+      *((char **)value) = jcr->PrevJob;
+      Dmsg1(dbglvl, "Bacula: return Previous Job name=%s\n", jcr->PrevJob);
+      break;
    case bVarJobStatus:
       *((int *)value) = jcr->JobStatus;
       Dmsg1(dbglvl, "Bacula: return bVarJobStatus=%d\n", jcr->JobStatus);
index 0d00eb335f47ecf96e4f6c0653c87a5a833f6c70..3c8fa7d493ef6f9bfededb60d7d4296bbc55b527 100644 (file)
@@ -185,7 +185,8 @@ typedef enum {
   bVarExePath    = 16,
   bVarVersion    = 17,
   bVarDistName   = 18,
-  bVarBEEF       = 19
+  bVarBEEF       = 19,
+  bVarPrevJobName = 20
 } bVariable;
 
 /* Events that are passed to plugin */
index e4086dc4fe814213a6397ade64df530f34503140..6bcb7a23f26d166cdcf1192e30300d808e595fd1 100644 (file)
@@ -1602,12 +1602,15 @@ static int level_cmd(JCR *jcr)
       if (jcr->getJobLevel() == L_NONE) {
          jcr->setJobLevel(L_SINCE);     /* if no other job level set, do it now */
       }
-      if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
-                 buf, &mtime_only) != 2) {
-         goto bail_out;
+      if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d prev_job=%127s",
+                 buf, &mtime_only, jcr->PrevJob) != 3) {
+         if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
+                    buf, &mtime_only) != 2) {
+            goto bail_out;
+         }
       }
       since_time = str_to_uint64(buf);  /* this is the since time */
-      Dmsg1(100, "since_time=%lld\n", since_time);
+      Dmsg2(100, "since_time=%lld prev_job=%s\n", since_time, jcr->PrevJob);
       char ed1[50], ed2[50];
       /*
        * Sync clocks by polling him for the time. We take
index 4017933106531e9b3124c12f28ff01659d052265..4cef43231fcfb619f8294edf57b50ae7ee621d90 100644 (file)
@@ -334,6 +334,7 @@ public:
    JCR *mig_jcr;                      /* JCR for migration/copy job */
    char FSCreateTime[MAX_TIME_LENGTH]; /* FileSet CreateTime as returned from DB */
    char since[MAX_TIME_LENGTH];       /* since time */
+   char PrevJob[MAX_NAME_LENGTH];     /* Previous job name assiciated with since time */
    union {
       JobId_t RestoreJobId;           /* Id specified by UA */
       JobId_t MigrateJobId;
@@ -396,6 +397,7 @@ public:
    int32_t buf_size;                  /* length of buffer */
    FF_PKT *ff;                        /* Find Files packet */
    char stored_addr[MAX_NAME_LENGTH]; /* storage daemon address */
+   char PrevJob[MAX_NAME_LENGTH];     /* Previous job name assiciated with since time */
    uint32_t StartFile;
    uint32_t EndFile;
    uint32_t StartBlock;