sendit(sock, _(" --> "));
dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
}
- if (res->res_job.RestoreWhere) {
- if (res->res_job.where_use_regexp) {
- sendit(sock, _(" --> RegexWhere=%s\n"), NPRT(res->res_job.RestoreWhere));
- } else {
- sendit(sock, _(" --> Where=%s\n"), NPRT(res->res_job.RestoreWhere));
- }
+ if (res->res_job.RestoreWhere && !res->res_job.RegexWhere) {
+ sendit(sock, _(" --> Where=%s\n"), NPRT(res->res_job.RestoreWhere));
+ }
+ if (res->res_job.RegexWhere) {
+ sendit(sock, _(" --> RegexWhere=%s\n"), NPRT(res->res_job.RegexWhere));
}
if (res->res_job.RestoreBootstrap) {
sendit(sock, _(" --> Bootstrap=%s\n"), NPRT(res->res_job.RestoreBootstrap));
res->res_job.run_cmds = res_all.res_job.run_cmds;
res->res_job.RunScripts = res_all.res_job.RunScripts;
- if (res->res_job.strip_prefix ||
- res->res_job.add_suffix ||
- res->res_job.add_prefix)
+ if (!res->res_job.RegexWhere
+ &&
+ (res->res_job.strip_prefix ||
+ res->res_job.add_suffix ||
+ res->res_job.add_prefix))
{
- if (res->res_job.RestoreWhere) {
- free(res->res_job.RestoreWhere);
- }
int len = bregexp_get_build_where_size(res->res_job.strip_prefix,
res->res_job.add_prefix,
res->res_job.add_suffix);
- res->res_job.RestoreWhere = (char *) bmalloc (len * sizeof(char));
- bregexp_build_where(res->res_job.RestoreWhere, len,
+ res->res_job.RegexWhere = (char *) bmalloc (len * sizeof(char));
+ bregexp_build_where(res->res_job.RegexWhere, len,
res->res_job.strip_prefix,
res->res_job.add_prefix,
res->res_job.add_suffix);
- res->res_job.where_use_regexp = true;
-
/* TODO: test bregexp */
}
- if (res->res_job.RegexWhere) {
- if (res->res_job.RestoreWhere) {
- free(res->res_job.RestoreWhere);
- }
- res->res_job.RestoreWhere = bstrdup(res->res_job.RegexWhere);
- res->res_job.where_use_regexp = true;
+ if (res->res_job.RegexWhere && res->res_job.RestoreWhere) {
+ free(res->res_job.RestoreWhere);
+ res->res_job.RestoreWhere = NULL;
}
break;
}
/* Send restore command */
- char replace, *where, *cmd;
+ char replace, *where, *cmd=NULL;
char empty = '\0';
if (jcr->replace != 0) {
} else {
replace = REPLACE_ALWAYS; /* always replace */
}
- if (jcr->where) {
+
+ where = ∅ /* default */
+
+ if (jcr->RegexWhere) {
+ where = jcr->RegexWhere; /* override */
+ cmd = restorecmdR;
+ } else if (jcr->job->RegexWhere) {
+ where = jcr->job->RegexWhere; /* no override take from job */
+ cmd = restorecmdR;
+
+ } else if (jcr->where) {
where = jcr->where; /* override */
+ cmd = restorecmd;
} else if (jcr->job->RestoreWhere) {
where = jcr->job->RestoreWhere; /* no override take from job */
- } else {
- where = ∅ /* None */
- }
+ cmd = restorecmd;
+ }
jcr->prefix_links = jcr->job->PrefixLinks;
- if (jcr->where_use_regexp) {
- cmd = restorecmdR;
- } else {
- cmd = restorecmd;
- }
-
bash_spaces(where);
bnet_fsend(fd, cmd, replace, jcr->prefix_links, where);
unbash_spaces(where);
int restore_jobs;
uint32_t selected_files;
char *where;
+ char *RegexWhere;
RBSR *bsr;
POOLMEM *fname; /* filename only */
POOLMEM *path; /* path only */
JCR *jcr = ua->jcr;
char *escaped_bsr_name = NULL;
char *escaped_where_name = NULL;
- bool where_use_regexp = false;
char *strip_prefix, *add_prefix, *add_suffix, *regexp;
strip_prefix = add_prefix = add_suffix = regexp = NULL;
add_suffix = ua->argv[i];
}
- i = find_arg(ua, "where_use_regexp");
- if (i >= 0) {
- where_use_regexp = true;
- }
-
i = find_arg_with_value(ua, "regexwhere");
if (i >= 0) {
- where_use_regexp = true;
- rx.where = ua->argv[i];
+ rx.RegexWhere = ua->argv[i];
}
if (strip_prefix || add_suffix || add_prefix) {
regexp = (char *) bmalloc (len * sizeof(char));
bregexp_build_where(regexp, len, strip_prefix, add_prefix, add_suffix);
- where_use_regexp = true;
-
- rx.where = regexp;
+ rx.RegexWhere = regexp;
+ }
+
+ /* TODO: add acl for regexwhere ? */
+
+ if (rx.RegexWhere) {
+ if (!acl_access_ok(ua, Where_ACL, rx.RegexWhere)) {
+ ua->error_msg(_("\"RegexWhere\" specification not authorized.\n"));
+ goto bail_out;
+ }
}
if (rx.where) {
}
escaped_bsr_name = escape_filename(jcr->RestoreBootstrap);
- escaped_where_name = escape_filename(rx.where);
/* Build run command */
- if (rx.where) {
- if (!acl_access_ok(ua, Where_ACL, rx.where)) {
- ua->error_msg(_("\"where\" specification not authorized.\n"));
- goto bail_out;
- }
+ if (rx.RegexWhere) {
+ escaped_where_name = escape_filename(rx.RegexWhere);
+ Mmsg(ua->cmd,
+ "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s\""
+ " regexwhere=\"%s\" files=%d catalog=\"%s\"",
+ job->name(), rx.ClientName, rx.store?rx.store->name():"",
+ escaped_bsr_name ? escaped_bsr_name : jcr->RestoreBootstrap,
+ escaped_where_name ? escaped_where_name : rx.RegexWhere,
+ rx.selected_files, ua->catalog->name());
+ } else if (rx.where) {
+ escaped_where_name = escape_filename(rx.where);
Mmsg(ua->cmd,
"run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s\""
- " %swhere=\"%s\" files=%d catalog=\"%s\"",
+ " where=\"%s\" files=%d catalog=\"%s\"",
job->name(), rx.ClientName, rx.store?rx.store->name():"",
escaped_bsr_name ? escaped_bsr_name : jcr->RestoreBootstrap,
- where_use_regexp ? "regex" : "",
escaped_where_name ? escaped_where_name : rx.where,
rx.selected_files, ua->catalog->name());
+
} else {
Mmsg(ua->cmd,
"run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s\""
"strip_prefix", /* 15 */
"add_prefix", /* 16 */
"add_suffix", /* 17 */
- "where_use_regexp",/* 18 */
- "regexwhere", /* 19 like where + where_use_regexp */
+ "regexwhere", /* 18 */
NULL
};
{
JCR *jcr;
char *job_name, *level_name, *jid, *store_name, *pool_name;
- char *where, *fileset_name, *client_name, *bootstrap;
+ char *where, *fileset_name, *client_name, *bootstrap, *regexwhere;
const char *replace;
char *when, *verify_job_name, *catalog_name;
char *previous_job_name;
int Priority = 0;
int i, j, opt, files = 0;
bool kw_ok;
- bool where_use_regexp = false;
JOB *job = NULL;
JOB *verify_job = NULL;
JOB *previous_job = NULL;
store_name = NULL;
pool_name = NULL;
where = NULL;
+ regexwhere = NULL;
when = NULL;
client_name = NULL;
fileset_name = NULL;
kw_ok = true;
break;
case 8: /* regexwhere */
- case 9: /* where */
- /* TODO: this is ugly ... */
- where_use_regexp = (j == 9)?false:true;/*regexwhere or where ?*/
-
- if (where) {
- ua->send_msg(_("Where specified twice.\n"));
+ if (regexwhere || where) {
+ ua->send_msg(_("RegexWhere or Where specified twice.\n"));
+ return 0;
+ }
+ regexwhere = ua->argv[i];
+ if (!acl_access_ok(ua, Where_ACL, regexwhere)) {
+ ua->send_msg(_("Forbidden \"regexwhere\" specified.\n"));
+ return 0;
+ }
+ kw_ok = true;
+ break;
+ case 9: /* where */
+ if (where || regexwhere) {
+ ua->send_msg(_("Where or RegexWhere specified twice.\n"));
return 0;
}
where = ua->argv[i];
free(jcr->where);
}
jcr->where = bstrdup(where);
- jcr->where_use_regexp = where_use_regexp;
+ }
+
+ if (regexwhere) {
+ if (jcr->RegexWhere) {
+ free(jcr->RegexWhere);
+ }
+ jcr->RegexWhere = bstrdup(regexwhere);
}
if (when) {
if (!get_cmd(ua, _("Please enter path prefix for restore (/ for none): "))) {
break;
}
+ if (jcr->RegexWhere) { /* cannot use regexwhere and where */
+ free(jcr->RegexWhere);
+ jcr->RegexWhere = NULL;
+ }
if (jcr->where) {
free(jcr->where);
jcr->where = NULL;
ua->cmd[0] = 0;
}
jcr->where = bstrdup(ua->cmd);
- jcr->where_use_regexp = false;
goto try_again;
case 9:
/* File relocation */
jcr->where = NULL;
}
+ /* replace the existing regexwhere */
+ if (jcr->RegexWhere) {
+ bfree(jcr->RegexWhere);
+ jcr->RegexWhere = NULL;
+ }
+
if (rwhere) {
- jcr->where = bstrdup(rwhere);
+ jcr->RegexWhere = bstrdup(rwhere);
} else if (strip_prefix || add_prefix || add_suffix) {
int len = bregexp_get_build_where_size(strip_prefix, add_prefix, add_suffix);
- jcr->where = (char *) bmalloc(len*sizeof(char));
- bregexp_build_where(jcr->where, len, strip_prefix, add_prefix, add_suffix);
+ jcr->RegexWhere = (char *) bmalloc(len*sizeof(char));
+ bregexp_build_where(jcr->RegexWhere, len, strip_prefix, add_prefix, add_suffix);
}
- regs = get_bregexps(jcr->where);
+ regs = get_bregexps(jcr->RegexWhere);
if (regs) {
free_bregexps(regs);
delete regs;
- jcr->where_use_regexp = true;
} else {
- if (jcr->where) {
- bfree(jcr->where);
- jcr->where = NULL;
+ if (jcr->RegexWhere) {
+ bfree(jcr->RegexWhere);
+ jcr->RegexWhere = NULL;
}
ua->send_msg(_("Cannot use your regexp.\n"));
}
if (ua->api) ua->signal(BNET_RUN_CMD);
ua->send_msg(_("Run Restore job\n"
"JobName: %s\n"
- "Bootstrap: %s\n"
- "%s %s\n" /* Where or RegexWhere */
- "Replace: %s\n"
+ "Bootstrap: %s\n"),
+ job->name(),
+ NPRT(jcr->RestoreBootstrap));
+
+ /* RegexWhere is take before RestoreWhere */
+ if (jcr->RegexWhere || (job->RegexWhere && !jcr->where)) {
+ ua->send_msg(_("RegexWhere: %s\n"),
+ jcr->RegexWhere?jcr->RegexWhere:job->RegexWhere);
+ } else {
+ ua->send_msg(_("Where: %s\n"),
+ jcr->where?jcr->where:NPRT(job->RestoreWhere));
+ }
+
+ ua->send_msg(_("Replace: %s\n"
"FileSet: %s\n"
"Client: %s\n"
"Storage: %s\n"
"When: %s\n"
"Catalog: %s\n"
"Priority: %d\n"),
- job->name(),
- NPRT(jcr->RestoreBootstrap),
- jcr->where_use_regexp?"RegexWhere:":"Where: ",
- jcr->where?jcr->where:NPRT(job->RestoreWhere),
replace,
jcr->fileset->name(),
jcr->client->name(),
} else {
if (ua->api) ua->signal(BNET_RUN_CMD);
ua->send_msg(_("Run Restore job\n"
- "JobName: %s\n"
- "Bootstrap: %s\n"
- "%s %s\n" /* Where or RegexWhere */
- "Replace: %s\n"
- "Client: %s\n"
- "Storage: %s\n"
- "JobId: %s\n"
- "When: %s\n"
- "Catalog: %s\n"
- "Priority: %d\n"),
- job->name(),
- NPRT(jcr->RestoreBootstrap),
- jcr->where_use_regexp?"RegexWhere:":"Where: ",
- jcr->where?jcr->where:NPRT(job->RestoreWhere),
+ "JobName: %s\n"
+ "Bootstrap: %s\n"),
+ job->name(),
+ NPRT(jcr->RestoreBootstrap));
+
+ /* RegexWhere is take before RestoreWhere */
+ if (jcr->RegexWhere || (job->RegexWhere && !jcr->where)) {
+ ua->send_msg(_("RegexWhere: %s\n"),
+ jcr->RegexWhere?jcr->RegexWhere:job->RegexWhere);
+ } else {
+ ua->send_msg(_("Where: %s\n"),
+ jcr->where?jcr->where:NPRT(job->RestoreWhere));
+ }
+
+ ua->send_msg(_("Replace: %s\n"
+ "Client: %s\n"
+ "Storage: %s\n"
+ "JobId: %s\n"
+ "When: %s\n"
+ "Catalog: %s\n"
+ "Priority: %d\n"),
replace,
jcr->client->name(),
jcr->rstore->name(),
{
BSOCK *dir = jcr->dir_bsock;
BSOCK *sd = jcr->store_bsock;
- POOLMEM *where;
+ POOLMEM *args;
+ bool use_regexwhere=false;
int prefix_links;
char replace;
char ed1[50], ed2[50];
*/
Dmsg0(150, "restore command\n");
/* Pickup where string */
- where = get_memory(dir->msglen+1);
- *where = 0;
+ args = get_memory(dir->msglen+1);
+ *args = 0;
- if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, where) != 3) {
- if (sscanf(dir->msg, restorecmdR, &replace, &prefix_links, where) != 3){
+ if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, args) != 3) {
+ if (sscanf(dir->msg, restorecmdR, &replace, &prefix_links, args) != 3){
if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) {
pm_strcpy(jcr->errmsg, dir->msg);
Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
return 0;
}
- *where = 0;
+ *args = 0;
}
- jcr->where_use_regexp = true;
+ use_regexwhere = true;
}
/* Turn / into nothing */
- if (IsPathSeparator(where[0]) && where[1] == '\0') {
- where[0] = '\0';
+ if (IsPathSeparator(args[0]) && args[1] == '\0') {
+ args[0] = '\0';
}
- Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
- unbash_spaces(where);
- jcr->where = bstrdup(where);
+ Dmsg2(150, "Got replace %c, where=%s\n", replace, args);
+ unbash_spaces(args);
- if (jcr->where_use_regexp) {
- jcr->where_bregexp = get_bregexps(jcr->where);
+ if (use_regexwhere) {
+ jcr->where_bregexp = get_bregexps(args);
if (!jcr->where_bregexp) {
- Jmsg(jcr, M_FATAL, 0, _("Bad where regexp. where=%s\n"), jcr->where);
- free_pool_memory(where);
+ Jmsg(jcr, M_FATAL, 0, _("Bad where regexp. where=%s\n"), args);
+ free_pool_memory(args);
return 0;
}
+ } else {
+ jcr->where = bstrdup(args);
}
- free_pool_memory(where);
+
+ free_pool_memory(args);
jcr->replace = replace;
jcr->prefix_links = prefix_links;
MSGS *jcr_msgs; /* Copy of message resource -- actually used */
uint32_t ClientId; /* Client associated with Job */
char *where; /* prefix to restore files to */
- bool where_use_regexp; /* True if where is a bregexp */
+ char *RegexWhere; /* file relocation in restore */
alist *where_bregexp; /* BREGEXP alist for path manipulation */
int cached_pnl; /* cached path length */
POOLMEM *cached_path; /* cached path */
*
*/
- if (jcr->where[0] == 0) {
- pm_strcpy(attr->ofname, attr->fname);
- pm_strcpy(attr->olname, attr->lname);
-
- } else if (jcr->where_bregexp) {
+ if (jcr->where_bregexp) {
char *ret;
apply_bregexps(attr->fname, jcr->where_bregexp, &ret);
pm_strcpy(attr->ofname, ret);
}
}
+ } else if (jcr->where[0] == 0) {
+ pm_strcpy(attr->ofname, attr->fname);
+ pm_strcpy(attr->olname, attr->lname);
+
} else {
const char *fn;
int wherelen = strlen(jcr->where);
free(jcr->where);
jcr->where = NULL;
}
+ if (jcr->RegexWhere) {
+ free(jcr->RegexWhere);
+ jcr->RegexWhere = NULL;
+ }
if (jcr->where_bregexp) {
free_bregexps(jcr->where_bregexp);
delete jcr->where_bregexp;