On Wed, Apr 22, 2009 at 08:33:51AM +0200, Kern Sibbald wrote:

> I am sorry, but it is not clear what you are doing here, in
> particular why you are adding a maxincinterval and what a "POLL" job
> is.

I was trying to improve handling for laptops and other devices that go
away for the night.  

MaxIncrInterval is intended to be the Incremental analog of
MaxDiffInterval.  A "Poll" is a level that doesn't actually do
anything except check if MaxIncrInterval, MaxDiffInterval, or
MaxFullInterval have been exceeded, doing a promotion if necessary.

The idea is that instead of just running a once-a-night backup that
might fail, one also runs a "poll" job every half hour or so, and sets
MaxIncrInterval to 1 day (or whatever.)  If the nightly incremental
fails, when the laptop does show up the next day and the poll runs,
the poll is promoted to an Incremental.  If the laptop was there and
got backed up, then the poll doesn't get promoted.

While this is intended for laptops, I think it also has a use in 24x7
server environments, where this is no ideal backup time and spreading
out the backup impact is good.  In such an environment, one can set
MaxIncrInterval, MaxDiffInterval, and MaxFullInterval, and *just* run
polls, without explicitly scheduling incrementals, differentials, and
fulls.  So if I specify MaxFullInterval of 1 week, and run a full
backup of serverA on Monday and serverB on Tuesday, bacula should
henceforth automatically separate serverA from serverB without me
having to explicitly specify this in the bacula config.

> PS: All patches need to be submitted as attachments to avoid email wrapping.

OK.  Patches attached.

- Morty
diff -ur bacula-3.0.0-dist/src/dird/fd_cmds.c 
bacula-3.0.0-maxdiff_fix/src/dird/fd_cmds.c
--- bacula-3.0.0-dist/src/dird/fd_cmds.c        2008-10-24 09:04:16.000000000 
-0400
+++ bacula-3.0.0-maxdiff_fix/src/dird/fd_cmds.c 2009-04-21 20:29:45.000000000 
-0400
@@ -198,6 +198,8 @@
          if (db_find_last_job_start_time(jcr, jcr->db, &jcr->jr, &stime, 
L_DIFFERENTIAL)) {
             last_diff_time = str_to_utime(stime);
             do_diff = ((now - last_diff_time) >= jcr->job->MaxDiffInterval);
+         } else {
+            do_diff = 1; /* if it's *never* run, promote */
          }
       }
       if (have_full && jcr->job->MaxFullInterval > 0 &&
diff -ur bacula-3.0.0-dist/src/cats/sql_find.c 
bacula-3.0.0-maxincr_and_poll/src/cats/sql_find.c
--- bacula-3.0.0-dist/src/cats/sql_find.c       2009-03-07 15:59:46.000000000 
-0500
+++ bacula-3.0.0-maxincr_and_poll/src/cats/sql_find.c   2009-04-21 
19:54:01.000000000 -0400
@@ -86,8 +86,9 @@
       if (jr->JobLevel == L_DIFFERENTIAL) {
          /* SQL cmd for Differential backup already edited above */
 
-      /* Incremental is since last Full, Incremental, or Differential */
-      } else if (jr->JobLevel == L_INCREMENTAL) {
+      /* Incremental is since last Full, Incremental, or Differential.
+         For Poll, do Incremental search as worst case */
+      } else if (jr->JobLevel == L_INCREMENTAL || jr->JobLevel == L_POLL) {
          /*
           * For an Incremental job, we must first ensure
           *  that a Full backup was done (cmd edited above)
diff -ur bacula-3.0.0-dist/src/dird/backup.c 
bacula-3.0.0-maxincr_and_poll/src/dird/backup.c
--- bacula-3.0.0-dist/src/dird/backup.c 2009-03-07 15:59:46.000000000 -0500
+++ bacula-3.0.0-maxincr_and_poll/src/dird/backup.c     2009-04-21 
19:40:10.000000000 -0400
@@ -85,6 +85,10 @@
       return false;
    }
 
+   if (jcr->get_JobLevel() == L_POLL) { /* do nothing if not promoted */
+      return true;
+   }
+
    jcr->jr.PoolId = get_or_create_pool_record(jcr, jcr->pool->name());
    if (jcr->jr.PoolId == 0) {
       return false;
@@ -189,6 +193,11 @@
       return do_vbackup(jcr);
    }
 
+   if (jcr->get_JobLevel() == L_POLL) {
+      set_jcr_job_status(jcr, JS_Terminated);
+      return true; /* nothing to do for unpromoted poll jobs */
+   }
+
    /* Print Job Start message */
    Jmsg(jcr, M_INFO, 0, _("Start Backup JobId %s, Job=%s\n"),
         edit_uint64(jcr->JobId, ed1), jcr->Job);
diff -ur bacula-3.0.0-dist/src/dird/dird_conf.c 
bacula-3.0.0-maxincr_and_poll/src/dird/dird_conf.c
--- bacula-3.0.0-dist/src/dird/dird_conf.c      2009-03-05 04:43:19.000000000 
-0500
+++ bacula-3.0.0-maxincr_and_poll/src/dird/dird_conf.c  2009-04-21 
06:26:44.000000000 -0400
@@ -305,6 +305,7 @@
    {"maxstartdelay",store_time, ITEM(res_job.MaxStartDelay), 0, 0, 0},
    {"maxfullinterval",  store_time, ITEM(res_job.MaxFullInterval), 0, 0, 0},
    {"maxdiffinterval",  store_time, ITEM(res_job.MaxDiffInterval), 0, 0, 0},
+   {"maxincrinterval",  store_time, ITEM(res_job.MaxIncrInterval), 0, 0, 0},
    {"jobretention", store_time, ITEM(res_job.JobRetention),  0, 0, 0},
    {"prefixlinks", store_bool, ITEM(res_job.PrefixLinks), 0, ITEM_DEFAULT, 
false},
    {"prunejobs",   store_bool, ITEM(res_job.PruneJobs), 0, ITEM_DEFAULT, 
false},
@@ -457,6 +458,7 @@
    {"Base",          L_BASE,            JT_BACKUP},
    {"Incremental",   L_INCREMENTAL,     JT_BACKUP},
    {"Differential",  L_DIFFERENTIAL,    JT_BACKUP},
+   {"Poll",          L_POLL,            JT_BACKUP},
    {"Since",         L_SINCE,           JT_BACKUP},
    {"VirtualFull",   L_VIRTUAL_FULL,    JT_BACKUP},
    {"Catalog",       L_VERIFY_CATALOG,  JT_VERIFY},
diff -ur bacula-3.0.0-dist/src/dird/dird_conf.h 
bacula-3.0.0-maxincr_and_poll/src/dird/dird_conf.h
--- bacula-3.0.0-dist/src/dird/dird_conf.h      2009-01-28 05:47:21.000000000 
-0500
+++ bacula-3.0.0-maxincr_and_poll/src/dird/dird_conf.h  2009-04-21 
05:18:52.000000000 -0400
@@ -395,6 +395,7 @@
    utime_t JobRetention;              /* job retention period in seconds */
    utime_t MaxFullInterval;           /* Maximum time interval between Fulls */
    utime_t MaxDiffInterval;           /* Maximum time interval between Diffs */
+   utime_t MaxIncrInterval;           /* Maximum time interval between 
Incrementals */
    utime_t DuplicateJobProximity;     /* Permitted time between duplicicates */
    int64_t spool_size;                /* Size of spool file for this job */
    uint32_t MaxConcurrentJobs;        /* Maximum concurrent jobs */
diff -ur bacula-3.0.0-dist/src/dird/fd_cmds.c 
bacula-3.0.0-maxincr_and_poll/src/dird/fd_cmds.c
--- bacula-3.0.0-dist/src/dird/fd_cmds.c        2008-10-24 09:04:16.000000000 
-0400
+++ bacula-3.0.0-maxincr_and_poll/src/dird/fd_cmds.c    2009-04-21 
20:49:51.000000000 -0400
@@ -164,9 +164,11 @@
    bool have_full;
    bool do_full = false;
    bool do_diff = false;
+   bool do_incr = false;
    utime_t now;
    utime_t last_full_time;
    utime_t last_diff_time;
+   utime_t last_incr_time;
 
    since[0] = 0;
    /* If job cloned and a since time already given, use it */
@@ -187,23 +189,39 @@
    switch (jcr->get_JobLevel()) {
    case L_DIFFERENTIAL:
    case L_INCREMENTAL:
+   case L_POLL:
       POOLMEM *stime = get_pool_memory(PM_MESSAGE);
       /* 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);
       /* If there was a successful job, make sure it is recent enough */
-      if (jcr->get_JobLevel() == L_INCREMENTAL && have_full && 
jcr->job->MaxDiffInterval > 0) {
+      if ((jcr->get_JobLevel() == L_INCREMENTAL || jcr->get_JobLevel() == 
L_POLL)
+           && 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)) {
             last_diff_time = str_to_utime(stime);
             do_diff = ((now - last_diff_time) >= jcr->job->MaxDiffInterval);
+         } else {
+            do_diff = 1; /* if there was *never* a diff, we're overdue */
          }
       }
-      if (have_full && jcr->job->MaxFullInterval > 0 &&
-         db_find_last_job_start_time(jcr, jcr->db, &jcr->jr, &stime, L_FULL)) {
-         last_full_time = str_to_utime(stime);
-         do_full = ((now - last_full_time) >= jcr->job->MaxFullInterval);
+      if (have_full && jcr->job->MaxFullInterval > 0) {
+         if (db_find_last_job_start_time(jcr, jcr->db, &jcr->jr, &stime, 
L_FULL)) {
+           last_full_time = str_to_utime(stime);
+           do_full = ((now - last_full_time) >= jcr->job->MaxFullInterval);
+         } else {
+           do_full = 1; /* if there was never a full, we're overdue.  
Redundant to have_full */
+         }
+      }
+      if (jcr->get_JobLevel()==L_POLL && have_full && !do_full && !do_diff && 
+          jcr->job->MaxIncrInterval > 0) {
+         if (db_find_last_job_start_time(jcr, jcr->db, &jcr->jr, &stime, 
L_INCREMENTAL)) {
+           last_incr_time = str_to_utime(stime);
+           do_incr = ((now - last_incr_time) >= jcr->job->MaxIncrInterval);
+         } else {
+           do_incr = 1; /* if there was never an incremental, we're overdue */
+         }
       }
       free_pool_memory(stime);
 
@@ -220,6 +238,12 @@
          bsnprintf(since, since_len, _(" (upgraded from %s)"),
             level_to_str(jcr->get_JobLevel()));
          jcr->set_JobLevel(jcr->jr.JobLevel = L_DIFFERENTIAL);
+      } else if (do_incr) {
+         /* No recent diff job found, so upgrade this one to Full */
+         Jmsg(jcr, M_INFO, 0, _("No prior or suitable Incremental backup found 
in catalog. Doing Incremental backup.\n"));
+         bsnprintf(since, since_len, _(" (upgraded from %s)"),
+            level_to_str(jcr->get_JobLevel()));
+         jcr->set_JobLevel(jcr->jr.JobLevel = L_INCREMENTAL);
       } else {
          if (jcr->job->rerun_failed_levels) {
             if (db_find_failed_job_since(jcr, jcr->db, &jcr->jr, jcr->stime, 
JobLevel)) {
diff -ur bacula-3.0.0-dist/src/dird/ua_run.c 
bacula-3.0.0-maxincr_and_poll/src/dird/ua_run.c
--- bacula-3.0.0-dist/src/dird/ua_run.c 2009-03-25 17:14:58.000000000 -0400
+++ bacula-3.0.0-maxincr_and_poll/src/dird/ua_run.c     2009-04-21 
06:48:02.000000000 -0400
@@ -688,6 +688,7 @@
       add_prompt(ua, _("Differential"));
       add_prompt(ua, _("Since"));
       add_prompt(ua, _("VirtualFull"));
+      add_prompt(ua, _("Poll"));
       switch (do_prompt(ua, "", _("Select level"), NULL, 0)) {
 //    case 0:
 //       jcr->JobLevel = L_BASE;
@@ -707,6 +708,9 @@
       case 4:
          jcr->set_JobLevel(L_VIRTUAL_FULL);
          break;
+      case 5:
+         jcr->set_JobLevel(L_POLL);
+         break;
       default:
          break;
       }
diff -ur bacula-3.0.0-dist/src/filed/status.c 
bacula-3.0.0-maxincr_and_poll/src/filed/status.c
--- bacula-3.0.0-dist/src/filed/status.c        2009-03-06 15:00:47.000000000 
-0500
+++ bacula-3.0.0-maxincr_and_poll/src/filed/status.c    2009-04-21 
06:55:27.000000000 -0400
@@ -446,6 +446,9 @@
    case L_DIFFERENTIAL:
       str = _("Differential");
       break;
+   case L_POLL:
+      str = _("Poll");
+      break;
    case L_SINCE:
       str = _("Since");
       break;
diff -ur bacula-3.0.0-dist/src/jcr.h bacula-3.0.0-maxincr_and_poll/src/jcr.h
--- bacula-3.0.0-dist/src/jcr.h 2009-03-07 15:59:46.000000000 -0500
+++ bacula-3.0.0-maxincr_and_poll/src/jcr.h     2009-04-21 19:46:14.000000000 
-0400
@@ -45,6 +45,7 @@
 #define L_INCREMENTAL            'I'  /* since last backup */
 #define L_DIFFERENTIAL           'D'  /* since last full backup */
 #define L_SINCE                  'S'
+#define L_POLL                   'P'  /* poll if time for backup */
 #define L_VERIFY_CATALOG         'C'  /* verify from catalog */
 #define L_VERIFY_INIT            'V'  /* verify save (init DB) */
 #define L_VERIFY_VOLUME_TO_CATALOG 'O'  /* verify Volume to catalog entries */
diff -ur bacula-3.0.0-dist/src/lib/util.c 
bacula-3.0.0-maxincr_and_poll/src/lib/util.c
--- bacula-3.0.0-dist/src/lib/util.c    2009-03-07 15:59:46.000000000 -0500
+++ bacula-3.0.0-maxincr_and_poll/src/lib/util.c        2009-04-21 
06:53:57.000000000 -0400
@@ -408,6 +408,9 @@
    case L_DIFFERENTIAL:
       str = _("Differential");
       break;
+   case L_POLL:
+      str = _("Poll");
+      break;
    case L_SINCE:
       str = _("Since");
       break;
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Bacula-devel mailing list
Bacula-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-devel

Reply via email to