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,
* then move it to allocated memory when the resource
* scan is complete.
*/
+#if defined(_MSC_VER)
+extern "C" { // work around visual compiler mangling variables
+ URES res_all;
+}
+#else
URES res_all;
+#endif
int res_all_size = sizeof(res_all);
{"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}
};
/*
{"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}
};
{"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
{"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}
};
/*
{"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}
};
/*
{"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},
{"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},
{"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
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 */
{"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
{"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},
{"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}
};
/*
{"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}
};
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));
}
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);
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, _(" --> "));
for (j=0; j<incexe->num_opts; j++) {
FOPTS *fo = incexe->opts_list[j];
sendit(sock, " O %s\n", fo->opts);
+
+ bool enhanced_wild = false;
+ for (k=0; fo->opts[k]!='\0'; k++) {
+ if (fo->opts[k]=='W') {
+ enhanced_wild = true;
+ break;
+ }
+ }
+
for (k=0; k<fo->regex.size(); k++) {
sendit(sock, " R %s\n", fo->regex.get(k));
}
for (k=0; k<fo->wildfile.size(); k++) {
sendit(sock, " WF %s\n", fo->wildfile.get(k));
}
+ for (k=0; k<fo->wildbase.size(); k++) {
+ sendit(sock, " W%c %s\n", enhanced_wild ? 'B' : 'F', fo->wildbase.get(k));
+ }
for (k=0; k<fo->base.size(); k++) {
sendit(sock, " B %s\n", fo->base.get(k));
}
for (k=0; k<fo->fstype.size(); k++) {
sendit(sock, " X %s\n", fo->fstype.get(k));
}
+ for (k=0; k<fo->drivetype.size(); k++) {
+ sendit(sock, " XD %s\n", fo->drivetype.get(k));
+ }
if (fo->reader) {
sendit(sock, " D %s\n", fo->reader);
}
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)));
fopt->wild.destroy();
fopt->wilddir.destroy();
fopt->wildfile.destroy();
+ fopt->wildbase.destroy();
fopt->base.destroy();
fopt->fstype.destroy();
+ fopt->drivetype.destroy();
if (fopt->reader) {
free(fopt->reader);
}
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);
}
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) {
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) {
}
set_bit(index, res_all.hdr.item_present);
}
+
+/* We build RunScripts items here */
+static RUNSCRIPT res_runscript;
+
+/* 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);
+
+ /* TODO: remove all script->old_proto with bacula 1.42 */
+
+ 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->old_proto = true;
+ script->when = SCRIPT_After;
+ script->set_target("%c");
+ script->on_success = true;
+ script->on_failure = false;
+
+ } else if (strcmp(item->name, "clientrunbeforejob") == 0) {
+ script->old_proto = true;
+ 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);
+}
+
+/*
+ * new RunScript items
+ * name handler value code flags default_value
+ */
+static RES_ITEM runscript_items[] = {
+ {"command", store_runscript_cmd, {(char **)&res_runscript}, 0, ITEM_REQUIRED, 0},
+ {"target", store_runscript_target, {(char **)&res_runscript}, 0, 0, 0},
+ {"runsonsuccess", store_bool, {(char **)&res_runscript.on_success}, 0, 0, 0},
+ {"runsonfailure", store_bool, {(char **)&res_runscript.on_failure}, 0, 0, 0},
+ {"abortjobonerror", store_bool, {(char **)&res_runscript.abort_on_error}, 0, 0, 0},
+ {"runswhen", store_runscript_when, {(char **)&res_runscript.when}, 0, 0, 0},
+ {"runsonclient", store_runscript_target, {(char **)&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);
+}