]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/dird_conf.c
Correct pool source setting
[bacula/bacula] / bacula / src / dird / dird_conf.c
index 1ce92662d8513f0e1e8c86141b7be577974508c4..9eedba0e6f9113abf8437228dfb1b221d5ab2bd8 100644 (file)
@@ -62,7 +62,10 @@ void store_replace(LEX *lc, RES_ITEM *item, int index, int pass);
 void store_acl(LEX *lc, RES_ITEM *item, int index, int pass);
 static void store_device(LEX *lc, RES_ITEM *item, int index, int pass);
 static void store_migtype(LEX *lc, RES_ITEM *item, int index, int pass);
-
+static void store_runscript(LEX *lc, RES_ITEM *item, int index, int pass);
+static void store_runscript_when(LEX *lc, RES_ITEM *item, int index, int pass);
+static void store_runscript_cmd(LEX *lc, RES_ITEM *item, int index, int pass);
+static void store_short_runscript(LEX *lc, RES_ITEM *item, int index, int pass);
 
 /* We build the current resource here as we are
  * scanning the resource configuration definition,
@@ -107,7 +110,7 @@ static RES_ITEM dir_items[] = {
    {"tlskey",               store_dir,       ITEM(res_dir.tls_keyfile), 0, 0, 0},
    {"tlsdhfile",            store_dir,       ITEM(res_dir.tls_dhfile), 0, 0, 0},
    {"tlsallowedcn",         store_alist_str, ITEM(res_dir.tls_allowed_cns), 0, 0, 0},
-   {NULL, NULL, NULL, 0, 0, 0}
+   {NULL, NULL, {0}, 0, 0, 0}
 };
 
 /*
@@ -137,7 +140,7 @@ static RES_ITEM con_items[] = {
    {"tlskey",               store_dir,       ITEM(res_con.tls_keyfile), 0, 0, 0},
    {"tlsdhfile",            store_dir,       ITEM(res_con.tls_dhfile), 0, 0, 0},
    {"tlsallowedcn",         store_alist_str, ITEM(res_con.tls_allowed_cns), 0, 0, 0},
-   {NULL, NULL, NULL, 0, 0, 0}
+   {NULL, NULL, {0}, 0, 0, 0}
 };
 
 
@@ -166,7 +169,7 @@ static RES_ITEM cli_items[] = {
    {"tlscacertificatedir",  store_dir,       ITEM(res_client.tls_ca_certdir), 0, 0, 0},
    {"tlscertificate",       store_dir,       ITEM(res_client.tls_certfile), 0, 0, 0},
    {"tlskey",               store_dir,       ITEM(res_client.tls_keyfile), 0, 0, 0},
-   {NULL, NULL, NULL, 0, 0, 0}
+   {NULL, NULL, {0}, 0, 0, 0}
 };
 
 /* Storage daemon resource
@@ -193,7 +196,7 @@ static RES_ITEM store_items[] = {
    {"tlscacertificatedir",  store_dir,       ITEM(res_store.tls_ca_certdir), 0, 0, 0},
    {"tlscertificate",       store_dir,       ITEM(res_store.tls_certfile), 0, 0, 0},
    {"tlskey",               store_dir,       ITEM(res_store.tls_keyfile), 0, 0, 0},
-   {NULL, NULL, NULL, 0, 0, 0}
+   {NULL, NULL, {0}, 0, 0, 0}
 };
 
 /*
@@ -215,7 +218,7 @@ static RES_ITEM cat_items[] = {
    {"dbsocket", store_str,      ITEM(res_cat.db_socket),   0, 0, 0},
    /* Turned off for the moment */
    {"multipleconnections", store_bit, ITEM(res_cat.mult_db_connections), 0, 0, 0},
-   {NULL, NULL, NULL, 0, 0, 0}
+   {NULL, NULL, {0}, 0, 0, 0}
 };
 
 /*
@@ -233,7 +236,7 @@ RES_ITEM job_items[] = {
    {"pool",      store_res,     ITEM(res_job.pool),     R_POOL, ITEM_REQUIRED, 0},
    {"fullbackuppool",  store_res, ITEM(res_job.full_pool),   R_POOL, 0, 0},
    {"incrementalbackuppool",  store_res, ITEM(res_job.inc_pool), R_POOL, 0, 0},
-   {"differentialbackuppool", store_res, ITEM(res_job.dif_pool), R_POOL, 0, 0},
+   {"differentialbackuppool", store_res, ITEM(res_job.diff_pool), R_POOL, 0, 0},
    {"client",    store_res,     ITEM(res_job.client),   R_CLIENT, ITEM_REQUIRED, 0},
    {"fileset",   store_res,     ITEM(res_job.fileset),  R_FILESET, ITEM_REQUIRED, 0},
    {"schedule",  store_res,     ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
@@ -266,11 +269,11 @@ RES_ITEM job_items[] = {
    {"spooldata",   store_bool, ITEM(res_job.spool_data), 0, ITEM_DEFAULT, false},
    {"rerunfailedlevels",   store_bool, ITEM(res_job.rerun_failed_levels), 0, ITEM_DEFAULT, false},
    {"prefermountedvolumes", store_bool, ITEM(res_job.PreferMountedVolumes), 0, ITEM_DEFAULT, true},
-   {"runbeforejob", store_str,  ITEM(res_job.RunBeforeJob), 0, 0, 0},
-   {"runafterjob",  store_str,  ITEM(res_job.RunAfterJob),  0, 0, 0},
-   {"runafterfailedjob",  store_str,  ITEM(res_job.RunAfterFailedJob),  0, 0, 0},
-   {"clientrunbeforejob", store_str,  ITEM(res_job.ClientRunBeforeJob), 0, 0, 0},
-   {"clientrunafterjob",  store_str,  ITEM(res_job.ClientRunAfterJob),  0, 0, 0},
+   {"runbeforejob", store_short_runscript,  ITEM(res_job.RunScripts),  0, 0, 0},
+   {"runafterjob",  store_short_runscript,  ITEM(res_job.RunScripts),  0, 0, 0},
+   {"runafterfailedjob",  store_short_runscript,  ITEM(res_job.RunScripts),  0, 0, 0},
+   {"clientrunbeforejob", store_short_runscript,  ITEM(res_job.RunScripts),  0, 0, 0},
+   {"clientrunafterjob",  store_short_runscript,  ITEM(res_job.RunScripts),  0, 0, 0},
    {"maximumconcurrentjobs", store_pint, ITEM(res_job.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
    {"rescheduleonerror", store_bool, ITEM(res_job.RescheduleOnError), 0, ITEM_DEFAULT, false},
    {"rescheduleinterval", store_time, ITEM(res_job.RescheduleInterval), 0, ITEM_DEFAULT, 60 * 30},
@@ -279,7 +282,8 @@ RES_ITEM job_items[] = {
    {"writepartafterjob",   store_bool, ITEM(res_job.write_part_after_job), 0, ITEM_DEFAULT, false},
    {"selectionpattern", store_str, ITEM(res_job.selection_pattern), 0, 0, 0},
    {"selectiontype", store_migtype, ITEM(res_job.selection_type), 0, 0, 0},
-   {NULL, NULL, NULL, 0, 0, 0}
+   {"runscript", store_runscript, ITEM(res_job.RunScripts), 0, ITEM_NO_EQUALS, 0},
+   {NULL, NULL, {0}, 0, 0, 0}
 };
 
 /* FileSet resource
@@ -289,11 +293,11 @@ RES_ITEM job_items[] = {
 static RES_ITEM fs_items[] = {
    {"name",        store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
    {"description", store_str,  ITEM(res_fs.hdr.desc), 0, 0, 0},
-   {"include",     store_inc,  NULL,                  0, ITEM_NO_EQUALS, 0},
-   {"exclude",     store_inc,  NULL,                  1, ITEM_NO_EQUALS, 0},
+   {"include",     store_inc,  {0},                   0, ITEM_NO_EQUALS, 0},
+   {"exclude",     store_inc,  {0},                   1, ITEM_NO_EQUALS, 0},
    {"ignorefilesetchanges", store_bool, ITEM(res_fs.ignore_fs_changes), 0, ITEM_DEFAULT, false},
    {"enablevss",   store_bool, ITEM(res_fs.enable_vss), 0, ITEM_DEFAULT, false},
-   {NULL,          NULL,       NULL,                  0, 0, 0}
+   {NULL,          NULL,       {0},                  0, 0, 0}
 };
 
 /* Schedule -- see run_conf.c */
@@ -305,7 +309,7 @@ static RES_ITEM sch_items[] = {
    {"name",     store_name,  ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
    {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
    {"run",      store_run,   ITEM(res_sch.run),      0, 0, 0},
-   {NULL, NULL, NULL, 0, 0, 0}
+   {NULL, NULL, {0}, 0, 0, 0}
 };
 
 /* Pool resource
@@ -328,7 +332,6 @@ static RES_ITEM pool_items[] = {
    {"maximumvolumejobs", store_pint,  ITEM(res_pool.MaxVolJobs),    0, 0,       0},
    {"maximumvolumefiles", store_pint, ITEM(res_pool.MaxVolFiles),   0, 0,       0},
    {"maximumvolumebytes", store_size, ITEM(res_pool.MaxVolBytes),   0, 0,       0},
-   {"acceptanyvolume", store_bool,    ITEM(res_pool.accept_any_volume), 0, ITEM_DEFAULT, true},
    {"catalogfiles",    store_bool,    ITEM(res_pool.catalog_files),  0, ITEM_DEFAULT, true},
    {"volumeretention", store_time,    ITEM(res_pool.VolRetention),   0, ITEM_DEFAULT, 60*60*24*365},
    {"volumeuseduration", store_time,  ITEM(res_pool.VolUseDuration), 0, 0, 0},
@@ -339,7 +342,7 @@ static RES_ITEM pool_items[] = {
    {"storage",       store_alist_res, ITEM(res_pool.storage),  R_STORAGE, 0, 0},
    {"autoprune",       store_bool,    ITEM(res_pool.AutoPrune), 0, ITEM_DEFAULT, true},
    {"recycle",         store_bool,    ITEM(res_pool.Recycle),   0, ITEM_DEFAULT, true},
-   {NULL, NULL, NULL, 0, 0, 0}
+   {NULL, NULL, {0}, 0, 0, 0}
 };
 
 /*
@@ -353,7 +356,7 @@ static RES_ITEM counter_items[] = {
    {"maximum",         store_pint,    ITEM(res_counter.MaxValue),        0, ITEM_DEFAULT, INT32_MAX},
    {"wrapcounter",     store_res,     ITEM(res_counter.WrapCounter),     R_COUNTER, 0, 0},
    {"catalog",         store_res,     ITEM(res_counter.Catalog),         R_CATALOG, 0, 0},
-   {NULL, NULL, NULL, 0, 0, 0}
+   {NULL, NULL, {0}, 0, 0, 0}
 };
 
 
@@ -589,15 +592,6 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm
       if (res->res_job.RestoreBootstrap) {
          sendit(sock, _("  --> Bootstrap=%s\n"), NPRT(res->res_job.RestoreBootstrap));
       }
-      if (res->res_job.RunBeforeJob) {
-         sendit(sock, _("  --> RunBefore=%s\n"), NPRT(res->res_job.RunBeforeJob));
-      }
-      if (res->res_job.RunAfterJob) {
-         sendit(sock, _("  --> RunAfter=%s\n"), NPRT(res->res_job.RunAfterJob));
-      }
-      if (res->res_job.RunAfterFailedJob) {
-         sendit(sock, _("  --> RunAfterFailed=%s\n"), NPRT(res->res_job.RunAfterFailedJob));
-      }
       if (res->res_job.WriteBootstrap) {
          sendit(sock, _("  --> WriteBootstrap=%s\n"), NPRT(res->res_job.WriteBootstrap));
       }
@@ -608,6 +602,18 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm
             dump_resource(-R_STORAGE, (RES *)store, sendit, sock);
          }
       }
+      if (res->res_job.RunScripts) {
+        RUNSCRIPT *script;
+        foreach_alist(script, res->res_job.RunScripts) {
+           sendit(sock, _(" --> RunScript\n"));
+           sendit(sock, _("  --> Command=%s\n"), NPRT(script->command));
+           sendit(sock, _("  --> Target=%s\n"),  NPRT(script->target));
+           sendit(sock, _("  --> RunOnSuccess=%u\n"),  script->on_success);
+           sendit(sock, _("  --> RunOnFailure=%u\n"),  script->on_failure);
+           sendit(sock, _("  --> AbortJobOnError=%u\n"),  script->abort_on_error);
+           sendit(sock, _("  --> RunWhen=%u\n"),  script->when);
+        }
+      }
       if (res->res_job.pool) {
          sendit(sock, _("  --> "));
          dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
@@ -620,9 +626,9 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm
          sendit(sock, _("  --> "));
          dump_resource(-R_POOL, (RES *)res->res_job.inc_pool, sendit, sock);
       }
-      if (res->res_job.dif_pool) {
+      if (res->res_job.diff_pool) {
          sendit(sock, _("  --> "));
-         dump_resource(-R_POOL, (RES *)res->res_job.dif_pool, sendit, sock);
+         dump_resource(-R_POOL, (RES *)res->res_job.diff_pool, sendit, sock);
       }
       if (res->res_job.verify_job) {
          sendit(sock, _("  --> "));
@@ -792,9 +798,9 @@ next_run:
    case R_POOL:
       sendit(sock, _("Pool: name=%s PoolType=%s\n"), res->res_pool.hdr.name,
               res->res_pool.pool_type);
-      sendit(sock, _("      use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n"),
+      sendit(sock, _("      use_cat=%d use_once=%d cat_files=%d\n"),
               res->res_pool.use_catalog, res->res_pool.use_volume_once,
-              res->res_pool.accept_any_volume, res->res_pool.catalog_files);
+              res->res_pool.catalog_files);
       sendit(sock, _("      max_vols=%d auto_prune=%d VolRetention=%s\n"),
               res->res_pool.max_volumes, res->res_pool.AutoPrune,
               edit_utime(res->res_pool.VolRetention, ed1, sizeof(ed1)));
@@ -1096,21 +1102,6 @@ void free_resource(RES *sres, int type)
       if (res->res_job.WriteBootstrap) {
          free(res->res_job.WriteBootstrap);
       }
-      if (res->res_job.RunBeforeJob) {
-         free(res->res_job.RunBeforeJob);
-      }
-      if (res->res_job.RunAfterJob) {
-         free(res->res_job.RunAfterJob);
-      }
-      if (res->res_job.RunAfterFailedJob) {
-         free(res->res_job.RunAfterFailedJob);
-      }
-      if (res->res_job.ClientRunBeforeJob) {
-         free(res->res_job.ClientRunBeforeJob);
-      }
-      if (res->res_job.ClientRunAfterJob) {
-         free(res->res_job.ClientRunAfterJob);
-      }
       if (res->res_job.selection_pattern) {
          free(res->res_job.selection_pattern);
       }
@@ -1120,6 +1111,10 @@ void free_resource(RES *sres, int type)
       if (res->res_job.storage) {
          delete res->res_job.storage;
       }
+      if (res->res_job.RunScripts) {
+         free_runscripts(res->res_job.RunScripts);
+         delete res->res_job.RunScripts;
+      }
       break;
    case R_MSGS:
       if (res->res_msgs.mail_cmd) {
@@ -1251,10 +1246,11 @@ void save_resource(int type, RES_ITEM *items, int pass)
          res->res_job.pool       = res_all.res_job.pool;
          res->res_job.full_pool  = res_all.res_job.full_pool;
          res->res_job.inc_pool   = res_all.res_job.inc_pool;
-         res->res_job.dif_pool   = res_all.res_job.dif_pool;
+         res->res_job.diff_pool  = res_all.res_job.diff_pool;
          res->res_job.verify_job = res_all.res_job.verify_job;
          res->res_job.jobdefs    = res_all.res_job.jobdefs;
          res->res_job.run_cmds   = res_all.res_job.run_cmds;
+         res->res_job.RunScripts = res_all.res_job.RunScripts;
          break;
       case R_COUNTER:
          if ((res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name)) == NULL) {
@@ -1544,3 +1540,199 @@ void store_acl(LEX *lc, RES_ITEM *item, int index, int pass)
    }
    set_bit(index, res_all.hdr.item_present);
 }
+
+
+/* Store a runscript->when in a bit field */
+static void store_runscript_when(LEX *lc, RES_ITEM *item, int index, int pass)
+{
+   lex_get_token(lc, T_NAME);
+
+   if (strcasecmp(lc->str, "before") == 0) {
+      *(int *)(item->value) = SCRIPT_Before ;
+   } else if (strcasecmp(lc->str, "after") == 0) {
+      *(int *)(item->value) = SCRIPT_After;
+   } else if (strcasecmp(lc->str, "always") == 0) {
+      *(int *)(item->value) = SCRIPT_Any;
+   } else {
+      scan_err2(lc, _("Expect %s, got: %s"), "Before, After or Always", lc->str);
+   }
+   scan_to_eol(lc);
+}
+
+/* Store a runscript->target
+ * 
+ */
+static void store_runscript_target(LEX *lc, RES_ITEM *item, int index, int pass)
+{
+   lex_get_token(lc, T_STRING);
+
+   if (pass == 2) {
+      if (strcmp(lc->str, "%c") == 0) {
+         ((RUNSCRIPT*) item->value)->set_target(lc->str);
+      } else if (strcmp(lc->str, "yes") == 0) {
+         ((RUNSCRIPT*) item->value)->set_target("%c");
+      } else if (strcmp(lc->str, "no") == 0) {
+         /* store nothing, run on director */
+      } else {
+         RES *res = GetResWithName(R_CLIENT, lc->str);
+         if (res == NULL) {
+            scan_err3(lc, _("Could not find config Resource %s referenced on line %d : %s\n"),
+                      lc->str, lc->line_no, lc->line);
+         }
+
+         ((RUNSCRIPT*) item->value)->set_target(lc->str);
+      }
+   }
+   scan_to_eol(lc);
+}
+
+/* Store a runscript->command in a bit field
+ * 
+ */
+static void store_runscript_cmd(LEX *lc, RES_ITEM *item, int index, int pass)
+{
+   lex_get_token(lc, T_STRING);
+
+   if (pass == 2) {
+      ((RUNSCRIPT*) item->value)->set_command(lc->str);
+   }
+   scan_to_eol(lc);
+}
+
+static void store_short_runscript(LEX *lc, RES_ITEM *item, int index, int pass)
+{
+   lex_get_token(lc, T_STRING);
+   alist **runscripts = (alist **)(item->value) ;
+
+   if (pass == 2) {
+      RUNSCRIPT *script = new_runscript();
+
+      script->set_command(lc->str);
+
+      if (strcmp(item->name, "runbeforejob") == 0) {
+         script->when = SCRIPT_Before;
+         script->abort_on_error = true;
+
+      } else if (strcmp(item->name, "runafterjob") == 0) {
+         script->when = SCRIPT_After;
+         script->on_success = true;
+         script->on_failure = false;
+         
+      } else if (strcmp(item->name, "clientrunafterjob") == 0) {
+         script->when = SCRIPT_After;
+         script->set_target("%c");
+         script->on_success = true;
+         script->on_failure = false;
+
+      } else if (strcmp(item->name, "clientrunbeforejob") == 0) {
+         script->when = SCRIPT_Before;
+         script->set_target("%c");
+         script->abort_on_error = true;
+
+      } else if (strcmp(item->name, "runafterfailedjob") == 0) {
+         script->when = SCRIPT_After;
+         script->on_failure = true;
+         script->on_success = false;
+      }
+
+      if (*runscripts == NULL) {
+        *runscripts = New(alist(10, not_owned_by_alist));
+      }
+      
+      (*runscripts)->append(script);
+      script->debug();
+   }
+
+   scan_to_eol(lc);
+}
+
+static RUNSCRIPT  res_runscript;
+
+/*
+ * new RunScript items
+ *   name             handler         value                                code flags default_value
+ */
+static RES_ITEM runscript_items[] = {
+   {"command", store_runscript_cmd,   ITEM(res_runscript),           0,  ITEM_REQUIRED, 0}, 
+   {"target", store_runscript_target, ITEM(res_runscript),            0,  0, 0}, 
+   {"runsonsuccess",    store_bool,   ITEM(res_runscript.on_success), 0,  0, 0},
+   {"runsonfailure",    store_bool,   ITEM(res_runscript.on_failure), 0,  0, 0},
+   {"abortjobonerror", store_bool,    ITEM(res_runscript.abort_on_error), 0, 0,   0},
+   {"runswhen", store_runscript_when, ITEM(res_runscript.when),       0,  0, 0},
+   {"runsonclient", store_runscript_target, ITEM(res_runscript),       0,  0, 0}, /* TODO */
+   {NULL, NULL, {0}, 0, 0, 0}
+};
+
+/*
+ * Store RunScript info
+ *
+ *  Note, when this routine is called, we are inside a Job
+ *  resource.  We treat the RunScript like a sort of
+ *  mini-resource within the Job resource.
+ */
+static void store_runscript(LEX *lc, RES_ITEM *item, int index, int pass)
+{
+   int token, i;
+   alist **runscripts = (alist **)(item->value) ;
+
+   Dmsg1(200, "store_runscript: begin store_runscript pass=%i\n", pass);
+
+   res_runscript.reset_default();      /* setting on_success, on_failure, abort_on_error */
+   
+   token = lex_get_token(lc, T_SKIP_EOL);
+   
+   if (token != T_BOB) {
+      scan_err1(lc, _("Expecting open brace. Got %s"), lc->str);
+   }
+   
+   while ((token = lex_get_token(lc, T_SKIP_EOL)) != T_EOF) {
+      if (token == T_EOB) {
+        break;
+      }
+      if (token != T_IDENTIFIER) {
+        scan_err1(lc, _("Expecting keyword, got: %s\n"), lc->str);
+      }
+      for (i=0; runscript_items[i].name; i++) {
+        if (strcasecmp(runscript_items[i].name, lc->str) == 0) {
+           token = lex_get_token(lc, T_SKIP_EOL);
+           if (token != T_EQUALS) {
+              scan_err1(lc, _("expected an equals, got: %s"), lc->str);
+           }
+           
+           /* Call item handler */
+           runscript_items[i].handler(lc, &runscript_items[i], i, pass);
+           i = -1;
+           break;
+        }
+      }
+      
+      if (i >=0) {
+        scan_err1(lc, _("Keyword %s not permitted in this resource"), lc->str);
+      }
+   }
+
+   if (pass == 2) {
+      if (res_runscript.command == NULL) {
+         scan_err2(lc, _("%s item is required in %s resource, but not found.\n"),
+                   "command", "runscript");
+      }
+
+      /* run on client by default */
+      if (res_runscript.target == NULL) {
+         res_runscript.set_target("%c");
+      }
+
+      RUNSCRIPT *script = new_runscript();
+      memcpy(script, &res_runscript, sizeof(RUNSCRIPT));
+      
+      if (*runscripts == NULL) {
+        *runscripts = New(alist(10, not_owned_by_alist));
+      }
+      
+      (*runscripts)->append(script);
+      script->debug();
+   }
+
+   scan_to_eol(lc);
+   set_bit(index, res_all.hdr.item_present);
+}