]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/file_relocation.patch
ebl add restore command line options
[bacula/bacula] / bacula / patches / testing / file_relocation.patch
1 Index: src/dird/ua_restore.c
2 ===================================================================
3 --- src/dird/ua_restore.c       (révision 4466)
4 +++ src/dird/ua_restore.c       (copie de travail)
5 @@ -43,8 +43,8 @@
6  
7  #include "bacula.h"
8  #include "dird.h"
9 +#include "lib/breg.h"
10  
11 -
12  /* Imported functions */
13  extern void print_bsr(UAContext *ua, RBSR *bsr);
14  
15 @@ -83,6 +83,10 @@
16     JCR *jcr = ua->jcr;
17     char *escaped_bsr_name = NULL;
18     char *escaped_where_name = NULL;
19 +   bool where_use_regexp = false;
20 +   bool have_to_free_where = false;
21 +   char *strip_prefix, *add_prefix, *add_suffix;
22 +   strip_prefix = add_prefix = add_suffix = NULL;
23  
24     memset(&rx, 0, sizeof(rx));
25     rx.path = get_pool_memory(PM_FNAME);
26 @@ -94,6 +98,41 @@
27     i = find_arg_with_value(ua, "where");
28     if (i >= 0) {
29        rx.where = ua->argv[i];
30 +   }
31 +
32 +   i = find_arg_with_value(ua, "strip_prefix");
33 +   if (i >= 0) {
34 +      strip_prefix = ua->argv[i];
35 +   }
36 +
37 +   i = find_arg_with_value(ua, "add_prefix");
38 +   if (i >= 0) {
39 +      add_prefix = ua->argv[i];
40 +   }
41 +
42 +   i = find_arg_with_value(ua, "add_suffix");
43 +   if (i >= 0) {
44 +      add_suffix = ua->argv[i];
45 +   }
46 +
47 +   i = find_arg(ua, "where_use_regexp");
48 +   if (i >= 0) {
49 +      where_use_regexp = true;
50 +   }
51 +
52 +   i = find_arg_with_value(ua, "rwhere");
53 +   if (i >= 0) {
54 +      where_use_regexp = true;
55 +      rx.where = ua->argv[i];
56 +   }
57 +
58 +   if (strip_prefix || add_suffix || add_prefix) {
59 +      where_use_regexp = true;
60 +      have_to_free_where = true;
61 +      rx.where = bregexp_build_where(strip_prefix, add_prefix, add_suffix);
62 +   }
63 +
64 +   if (rx.where) {
65        if (!acl_access_ok(ua, Where_ACL, rx.where)) {
66           ua->error_msg(_("\"where\" specification not authorized.\n"));
67           goto bail_out;
68 @@ -195,9 +234,10 @@
69  
70        Mmsg(ua->cmd,
71            "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s\""
72 -          " where=\"%s\" files=%d catalog=\"%s\"",
73 +          " %swhere=\"%s\" files=%d catalog=\"%s\"",
74            job->name(), rx.ClientName, rx.store?rx.store->name():"",
75            escaped_bsr_name ? escaped_bsr_name : jcr->RestoreBootstrap,
76 +         where_use_regexp ? "r" : "",
77            escaped_where_name ? escaped_where_name : rx.where,
78            rx.selected_files, ua->catalog->name());
79     } else {
80 @@ -216,6 +256,10 @@
81     if (escaped_where_name != NULL) {
82        bfree(escaped_where_name);
83     }
84 +   
85 +   if (have_to_free_where) {
86 +      free_pool_memory(rx.where);
87 +   }
88  
89     if (find_arg(ua, NT_("yes")) > 0) {
90        pm_strcat(ua->cmd, " yes");    /* pass it on to the run command */
91 @@ -235,6 +279,10 @@
92        bfree(escaped_where_name);
93     }
94  
95 +   if (have_to_free_where) {
96 +      free_pool_memory(rx.where);
97 +   }
98 +
99     free_rx(&rx);
100     return 0;
101  
102 @@ -331,23 +379,28 @@
103  
104     const char *kw[] = {
105         /* These keywords are handled in a for loop */
106 -      "jobid",     /* 0 */
107 -      "current",   /* 1 */
108 -      "before",    /* 2 */
109 -      "file",      /* 3 */
110 -      "directory", /* 4 */
111 -      "select",    /* 5 */
112 -      "pool",      /* 6 */
113 -      "all",       /* 7 */
114 +      "jobid",       /* 0 */
115 +      "current",     /* 1 */
116 +      "before",      /* 2 */
117 +      "file",        /* 3 */
118 +      "directory",   /* 4 */
119 +      "select",      /* 5 */
120 +      "pool",        /* 6 */
121 +      "all",         /* 7 */
122  
123        /* The keyword below are handled by individual arg lookups */
124 -      "client",    /* 8 */
125 -      "storage",   /* 9 */
126 -      "fileset",   /* 10 */
127 -      "where",     /* 11 */
128 -      "yes",       /* 12 */
129 -      "bootstrap", /* 13 */
130 -      "done",      /* 14 */
131 +      "client",       /* 8 */
132 +      "storage",      /* 9 */
133 +      "fileset",      /* 10 */
134 +      "where",        /* 11 */
135 +      "yes",          /* 12 */
136 +      "bootstrap",    /* 13 */
137 +      "done",         /* 14 */
138 +      "strip_prefix", /* 15 */
139 +      "add_prefix",   /* 16 */
140 +      "add_suffix",   /* 17 */
141 +      "where_use_regexp",/* 18 */
142 +      "rwhere",       /* 19 like where + where_use_regexp */
143        NULL
144     };
145  
146 Index: src/dird/restore.c
147 ===================================================================
148 --- src/dird/restore.c  (révision 4466)
149 +++ src/dird/restore.c  (copie de travail)
150 @@ -50,8 +50,9 @@
151  #include "dird.h"
152  
153  /* Commands sent to File daemon */
154 -static char restorecmd[]   = "restore replace=%c prelinks=%d where=%s\n";
155 -static char storaddr[]     = "storage address=%s port=%d ssl=0\n";
156 +static char restorecmd[]        = "restore replace=%c prelinks=%d where=%s\n";
157 +static char restorecmdR[] = "restore replace=%c prelinks=%d rwhere=%s\n";
158 +static char storaddr[]   = "storage address=%s port=%d ssl=0\n";
159  
160  /* Responses received from File daemon */
161  static char OKrestore[]   = "2000 OK restore\n";
162 @@ -172,7 +173,7 @@
163     }
164  
165     /* Send restore command */
166 -   char replace, *where;
167 +   char replace, *where, *cmd;
168     char empty = '\0';
169  
170     if (jcr->replace != 0) {
171 @@ -189,9 +190,17 @@
172     } else {
173        where = ∅                 /* None */
174     }
175 +   
176     jcr->prefix_links = jcr->job->PrefixLinks;
177 +
178 +   if (jcr->where_use_regexp) {
179 +      cmd = restorecmdR;
180 +   } else {
181 +      cmd = restorecmd;
182 +   }
183 +
184     bash_spaces(where);
185 -   bnet_fsend(fd, restorecmd, replace, jcr->prefix_links, where);
186 +   bnet_fsend(fd, cmd, replace, jcr->prefix_links, where);
187     unbash_spaces(where);
188  
189     if (!response(jcr, fd, OKrestore, "Restore", DISPLAY_ERROR)) {
190 Index: src/dird/dird_conf.c
191 ===================================================================
192 --- src/dird/dird_conf.c        (révision 4466)
193 +++ src/dird/dird_conf.c        (copie de travail)
194 @@ -52,6 +52,7 @@
195  
196  #include "bacula.h"
197  #include "dird.h"
198 +#include "lib/breg.h"
199  
200  /* Define the first and last resource ID record
201   * types. Note, these should be unique for each
202 @@ -268,6 +269,10 @@
203     {"run",       store_alist_str, ITEM(res_job.run_cmds), 0, 0, 0},
204     /* Root of where to restore files */
205     {"where",    store_dir,      ITEM(res_job.RestoreWhere), 0, 0, 0},
206 +   {"whereuseregexp", store_bool, ITEM(res_job.where_use_regexp), 0, 0, 0},
207 +   {"stripprefix",    store_str,  ITEM(res_job.strip_prefix), 0, 0, 0},
208 +   {"addprefix",    store_str,  ITEM(res_job.add_prefix), 0, 0, 0},
209 +   {"addsuffix",    store_str,  ITEM(res_job.add_suffix), 0, 0, 0},
210     /* Where to find bootstrap during restore */
211     {"bootstrap",store_dir,      ITEM(res_job.RestoreBootstrap), 0, 0, 0},
212     /* Where to write bootstrap file during backup */
213 @@ -611,6 +616,9 @@
214        if (res->res_job.RestoreWhere) {
215           sendit(sock, _("  --> Where=%s\n"), NPRT(res->res_job.RestoreWhere));
216        }
217 +      if (res->res_job.where_use_regexp) {
218 +         sendit(sock, _("  --> RWhere=%u\n"), res->res_job.where_use_regexp);
219 +      }
220        if (res->res_job.RestoreBootstrap) {
221           sendit(sock, _("  --> Bootstrap=%s\n"), NPRT(res->res_job.RestoreBootstrap));
222        }
223 @@ -1143,6 +1151,15 @@
224        if (res->res_job.RestoreWhere) {
225           free(res->res_job.RestoreWhere);
226        }
227 +      if (res->res_job.strip_prefix) {
228 +         free(res->res_job.strip_prefix);
229 +      }
230 +      if (res->res_job.add_prefix) {
231 +         free(res->res_job.add_prefix);
232 +      }
233 +      if (res->res_job.add_suffix) {
234 +         free(res->res_job.add_suffix);
235 +      }
236        if (res->res_job.RestoreBootstrap) {
237           free(res->res_job.RestoreBootstrap);
238        }
239 @@ -1299,6 +1316,19 @@
240           res->res_job.jobdefs    = res_all.res_job.jobdefs;
241           res->res_job.run_cmds   = res_all.res_job.run_cmds;
242           res->res_job.RunScripts = res_all.res_job.RunScripts;
243 +        if (res->res_job.strip_prefix ||
244 +            res->res_job.add_suffix   ||
245 +            res->res_job.add_prefix)
246 +        {
247 +           if (res->res_job.RestoreWhere) {
248 +              free(res->res_job.RestoreWhere);
249 +           }
250 +           res->res_job.where_use_regexp = true;
251 +           res->res_job.RestoreWhere=bregexp_build_where(res->res_job.strip_prefix,
252 +                                                         res->res_job.add_prefix,
253 +                                                         res->res_job.add_suffix);
254 +           /* TODO: test bregexp */
255 +        }
256           break;
257        case R_COUNTER:
258           if ((res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name)) == NULL) {
259 Index: src/dird/ua_run.c
260 ===================================================================
261 --- src/dird/ua_run.c   (révision 4466)
262 +++ src/dird/ua_run.c   (copie de travail)
263 @@ -71,6 +71,7 @@
264     int Priority = 0;
265     int i, j, opt, files = 0;
266     bool kw_ok;
267 +   bool where_use_regexp = false;
268     JOB *job = NULL;
269     JOB *verify_job = NULL;
270     JOB *previous_job = NULL;
271 @@ -87,7 +88,7 @@
272        "level",                        /* 5 */
273        "storage",                      /* 6 */
274        "sd",                           /* 7 */
275 -      "pool",                         /* 8 */
276 +      "rwhere",                       /* 8 where string as a bregexp */
277        "where",                        /* 9 */
278        "bootstrap",                    /* 10 */
279        "replace",                      /* 11 */
280 @@ -101,6 +102,7 @@
281        "cloned",                       /* 19 cloned */
282        "verifylist",                   /* 20 verify output list */
283        "migrationjob",                 /* 21 migration job name */
284 +      "pool",                         /* 22 */
285        NULL};
286  
287  #define YES_POS 14
288 @@ -188,14 +190,8 @@
289                 store_name = ua->argv[i];
290                 kw_ok = true;
291                 break;
292 -            case 8: /* pool */
293 -               if (pool_name) {
294 -                  ua->send_msg(_("Pool specified twice.\n"));
295 -                  return 0;
296 -               }
297 -               pool_name = ua->argv[i];
298 -               kw_ok = true;
299 -               break;
300 +           case 8:
301 +              where_use_regexp = true;
302              case 9: /* where */
303                 if (where) {
304                    ua->send_msg(_("Where specified twice.\n"));
305 @@ -287,8 +283,15 @@
306                 previous_job_name = ua->argv[i];
307                 kw_ok = true;
308                 break;
309 +            case 22: /* pool */
310 +               if (pool_name) {
311 +                  ua->send_msg(_("Pool specified twice.\n"));
312 +                  return 0;
313 +               }
314 +               pool_name = ua->argv[i];
315 +               kw_ok = true;
316 +               break;
317  
318 -
319              default:
320                 break;
321              }
322 @@ -478,6 +481,7 @@
323           free(jcr->where);
324        }
325        jcr->where = bstrdup(where);
326 +      jcr->where_use_regexp = where_use_regexp;
327     }
328  
329     if (when) {
330 Index: src/dird/dird_conf.h
331 ===================================================================
332 --- src/dird/dird_conf.h        (révision 4466)
333 +++ src/dird/dird_conf.h        (copie de travail)
334 @@ -356,6 +356,10 @@
335     int   Priority;                    /* Job priority */
336     int   RestoreJobId;                /* What -- JobId to restore */
337     char *RestoreWhere;                /* Where on disk to restore -- directory */
338 +   char *strip_prefix;                /* remove prefix from filename  */
339 +   char *add_prefix;                  /* add prefix to filename  */
340 +   char *add_suffix;                  /* add suffix to filename -- .old */
341 +   bool  where_use_regexp;            /* true if RestoreWhere is a BREGEXP */
342     char *RestoreBootstrap;            /* Bootstrap file */
343     alist *RunScripts;                 /* Run {client} program {after|before} Job */
344     union {
345 Index: src/filed/job.c
346 ===================================================================
347 --- src/filed/job.c     (révision 4467)
348 +++ src/filed/job.c     (copie de travail)
349 @@ -36,6 +36,7 @@
350  
351  #include "bacula.h"
352  #include "filed.h"
353 +#include "lib/breg.h"
354  
355  #if defined(WIN32_VSS)
356  #include "vss.h"
357 @@ -115,6 +116,7 @@
358  static char sessioncmd[]  = "session %127s %ld %ld %ld %ld %ld %ld\n";
359  static char restorecmd[]  = "restore replace=%c prelinks=%d where=%s\n";
360  static char restorecmd1[] = "restore replace=%c prelinks=%d where=\n";
361 +static char restorecmdR[] = "restore replace=%c prelinks=%d rwhere=%s\n";
362  static char verifycmd[]   = "verify level=%30s";
363  static char estimatecmd[] = "estimate listing=%d";
364  static char runbefore[]   = "RunBeforeJob %s";
365 @@ -1586,12 +1588,15 @@
366     *where = 0;
367  
368     if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, where) != 3) {
369 -      if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) {
370 -         pm_strcpy(jcr->errmsg, dir->msg);
371 -         Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
372 -         return 0;
373 +      if (sscanf(dir->msg, restorecmdR, &replace, &prefix_links, where) != 3){
374 +        if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) {
375 +           pm_strcpy(jcr->errmsg, dir->msg);
376 +           Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
377 +           return 0;
378 +        }
379 +        *where = 0;
380        }
381 -      *where = 0;
382 +      jcr->where_use_regexp = true;
383     }
384     /* Turn / into nothing */
385     if (IsPathSeparator(where[0]) && where[1] == '\0') {
386 @@ -1601,6 +1606,15 @@
387     Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
388     unbash_spaces(where);
389     jcr->where = bstrdup(where);
390 +
391 +   if (jcr->where_use_regexp) {
392 +      jcr->where_bregexp = get_bregexps(jcr->where);
393 +      if (!jcr->where_bregexp) {
394 +        Jmsg(jcr, M_FATAL, 0, _("Bad where regexp. where=%s\n"), jcr->where);
395 +        free_pool_memory(where);
396 +        return 0;
397 +      }
398 +   }
399     free_pool_memory(where);
400     jcr->replace = replace;
401     jcr->prefix_links = prefix_links;
402 Index: src/jcr.h
403 ===================================================================
404 --- src/jcr.h   (révision 4466)
405 +++ src/jcr.h   (copie de travail)
406 @@ -173,6 +173,8 @@
407     MSGS *jcr_msgs;                    /* Copy of message resource -- actually used */
408     uint32_t ClientId;                 /* Client associated with Job */
409     char *where;                       /* prefix to restore files to */
410 +   bool where_use_regexp;             /* True if where is a bregexp */
411 +   alist *where_bregexp;              /* BREGEXP alist for path manipulation */
412     int cached_pnl;                    /* cached path length */
413     POOLMEM *cached_path;              /* cached path */
414     bool prefix_links;                 /* Prefix links with Where path */
415 Index: src/lib/Makefile.in
416 ===================================================================
417 --- src/lib/Makefile.in (révision 4466)
418 +++ src/lib/Makefile.in (copie de travail)
419 @@ -32,7 +32,7 @@
420           res.c rwlock.c scan.c serial.c sha1.c \
421           signal.c smartall.c rblist.c tls.c tree.c \
422           util.c var.c watchdog.c workq.c btimers.c \
423 -         address_conf.c pythonlib.c
424 +         address_conf.c pythonlib.c breg.c
425  
426  
427  LIBOBJS = attr.o base64.o berrno.o bsys.o bget_msg.o \
428 @@ -45,7 +45,7 @@
429           res.o rwlock.o scan.o serial.o sha1.o \
430           signal.o smartall.o rblist.o tls.o tree.o \
431           util.o var.o watchdog.o workq.o btimers.o \
432 -         address_conf.o pythonlib.o
433 +         address_conf.o pythonlib.o breg.o
434  
435  
436  EXTRAOBJS = @OBJLIST@
437 Index: src/lib/attr.c
438 ===================================================================
439 --- src/lib/attr.c      (révision 4466)
440 +++ src/lib/attr.c      (copie de travail)
441 @@ -35,8 +35,8 @@
442  
443  #include "bacula.h"
444  #include "jcr.h"
445 +#include "lib/breg.h"
446  
447 -
448  ATTR *new_attr()
449  {
450     ATTR *attr = (ATTR *)malloc(sizeof(ATTR));
451 @@ -148,9 +148,30 @@
452      *   every filename if a prefix is supplied.
453      *
454      */
455 +
456     if (jcr->where[0] == 0) {
457        pm_strcpy(attr->ofname, attr->fname);
458        pm_strcpy(attr->olname, attr->lname);
459 +
460 +   } else if (jcr->where_bregexp) { 
461 +      char *ret;
462 +      apply_bregexps(attr->fname, jcr->where_bregexp, &ret);
463 +      pm_strcpy(attr->ofname, ret);
464 +
465 +      if (attr->type == FT_LNKSAVED || attr->type == FT_LNK) {
466 +         /* Always add prefix to hard links (FT_LNKSAVED) and
467 +          *  on user request to soft links
468 +          */
469 +
470 +        if ((attr->type == FT_LNKSAVED || jcr->prefix_links)) {
471 +           apply_bregexps(attr->lname, jcr->where_bregexp, &ret);
472 +           pm_strcpy(attr->olname, ret);
473 +
474 +        } else {
475 +           pm_strcpy(attr->olname, attr->lname);
476 +        }
477 +      }
478 +      
479     } else {
480        const char *fn;
481        int wherelen = strlen(jcr->where);
482 Index: src/lib/jcr.c
483 ===================================================================
484 --- src/lib/jcr.c       (révision 4466)
485 +++ src/lib/jcr.c       (copie de travail)
486 @@ -56,6 +56,9 @@
487  /* External variables we reference */
488  extern time_t watchdog_time;
489  
490 +/* External referenced functions */
491 +void free_bregexps(alist *bregexps);
492 +
493  /* Forward referenced functions */
494  extern "C" void timeout_handler(int sig);
495  static void jcr_timeout_check(watchdog_t *self);
496 @@ -381,6 +384,11 @@
497        free(jcr->where);
498        jcr->where = NULL;
499     }
500 +   if (jcr->where_bregexp) {
501 +      free_bregexps(jcr->where_bregexp);
502 +      delete jcr->where_bregexp;
503 +      jcr->where_bregexp = NULL;
504 +   }
505     if (jcr->cached_path) {
506        free_pool_memory(jcr->cached_path);
507        jcr->cached_path = NULL;
508 Index: patches/testing/file_relocation.patch
509 ===================================================================
510 --- patches/testing/file_relocation.patch       (révision 4514)
511 +++ patches/testing/file_relocation.patch       (copie de travail)
512 @@ -12,17 +12,18 @@
513   /* Imported functions */
514   extern void print_bsr(UAContext *ua, RBSR *bsr);
515   
516 -@@ -83,6 +83,9 @@
517 +@@ -83,6 +83,10 @@
518      JCR *jcr = ua->jcr;
519      char *escaped_bsr_name = NULL;
520      char *escaped_where_name = NULL;
521  +   bool where_use_regexp = false;
522 ++   bool have_to_free_where = false;
523  +   char *strip_prefix, *add_prefix, *add_suffix;
524  +   strip_prefix = add_prefix = add_suffix = NULL;
525   
526      memset(&rx, 0, sizeof(rx));
527      rx.path = get_pool_memory(PM_FNAME);
528 -@@ -94,6 +97,29 @@
529 +@@ -94,6 +98,41 @@
530      i = find_arg_with_value(ua, "where");
531      if (i >= 0) {
532         rx.where = ua->argv[i];
533 @@ -43,8 +44,20 @@
534  +      add_suffix = ua->argv[i];
535  +   }
536  +
537 ++   i = find_arg(ua, "where_use_regexp");
538 ++   if (i >= 0) {
539 ++      where_use_regexp = true;
540 ++   }
541 ++
542 ++   i = find_arg_with_value(ua, "rwhere");
543 ++   if (i >= 0) {
544 ++      where_use_regexp = true;
545 ++      rx.where = ua->argv[i];
546 ++   }
547 ++
548  +   if (strip_prefix || add_suffix || add_prefix) {
549  +      where_use_regexp = true;
550 ++      have_to_free_where = true;
551  +      rx.where = bregexp_build_where(strip_prefix, add_prefix, add_suffix);
552  +   }
553  +
554 @@ -52,7 +65,7 @@
555         if (!acl_access_ok(ua, Where_ACL, rx.where)) {
556            ua->error_msg(_("\"where\" specification not authorized.\n"));
557            goto bail_out;
558 -@@ -195,9 +221,10 @@
559 +@@ -195,9 +234,10 @@
560   
561         Mmsg(ua->cmd,
562             "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s\""
563 @@ -64,28 +77,72 @@
564             escaped_where_name ? escaped_where_name : rx.where,
565             rx.selected_files, ua->catalog->name());
566      } else {
567 -@@ -216,6 +243,10 @@
568 +@@ -216,6 +256,10 @@
569      if (escaped_where_name != NULL) {
570         bfree(escaped_where_name);
571      }
572  +   
573 -+   if (where_use_regexp) {
574 ++   if (have_to_free_where) {
575  +      free_pool_memory(rx.where);
576  +   }
577   
578      if (find_arg(ua, NT_("yes")) > 0) {
579         pm_strcat(ua->cmd, " yes");    /* pass it on to the run command */
580 -@@ -235,6 +266,10 @@
581 +@@ -235,6 +279,10 @@
582         bfree(escaped_where_name);
583      }
584   
585 -+   if (where_use_regexp) {
586 ++   if (have_to_free_where) {
587  +      free_pool_memory(rx.where);
588  +   }
589  +
590      free_rx(&rx);
591      return 0;
592   
593 +@@ -331,23 +379,28 @@
594
595 +    const char *kw[] = {
596 +        /* These keywords are handled in a for loop */
597 +-      "jobid",     /* 0 */
598 +-      "current",   /* 1 */
599 +-      "before",    /* 2 */
600 +-      "file",      /* 3 */
601 +-      "directory", /* 4 */
602 +-      "select",    /* 5 */
603 +-      "pool",      /* 6 */
604 +-      "all",       /* 7 */
605 ++      "jobid",       /* 0 */
606 ++      "current",     /* 1 */
607 ++      "before",      /* 2 */
608 ++      "file",        /* 3 */
609 ++      "directory",   /* 4 */
610 ++      "select",      /* 5 */
611 ++      "pool",        /* 6 */
612 ++      "all",         /* 7 */
613
614 +       /* The keyword below are handled by individual arg lookups */
615 +-      "client",    /* 8 */
616 +-      "storage",   /* 9 */
617 +-      "fileset",   /* 10 */
618 +-      "where",     /* 11 */
619 +-      "yes",       /* 12 */
620 +-      "bootstrap", /* 13 */
621 +-      "done",      /* 14 */
622 ++      "client",       /* 8 */
623 ++      "storage",      /* 9 */
624 ++      "fileset",      /* 10 */
625 ++      "where",        /* 11 */
626 ++      "yes",          /* 12 */
627 ++      "bootstrap",    /* 13 */
628 ++      "done",         /* 14 */
629 ++      "strip_prefix", /* 15 */
630 ++      "add_prefix",   /* 16 */
631 ++      "add_suffix",   /* 17 */
632 ++      "where_use_regexp",/* 18 */
633 ++      "rwhere",       /* 19 like where + where_use_regexp */
634 +       NULL
635 +    };
636
637  Index: src/dird/restore.c
638  ===================================================================
639  --- src/dird/restore.c (révision 4466)
640 @@ -134,15 +191,26 @@
641  ===================================================================
642  --- src/dird/dird_conf.c       (révision 4466)
643  +++ src/dird/dird_conf.c       (copie de travail)
644 -@@ -268,6 +268,7 @@
645 +@@ -52,6 +52,7 @@
646
647 + #include "bacula.h"
648 + #include "dird.h"
649 ++#include "lib/breg.h"
650
651 + /* Define the first and last resource ID record
652 +  * types. Note, these should be unique for each
653 +@@ -268,6 +269,10 @@
654      {"run",       store_alist_str, ITEM(res_job.run_cmds), 0, 0, 0},
655      /* Root of where to restore files */
656      {"where",    store_dir,      ITEM(res_job.RestoreWhere), 0, 0, 0},
657  +   {"whereuseregexp", store_bool, ITEM(res_job.where_use_regexp), 0, 0, 0},
658 ++   {"stripprefix",    store_str,  ITEM(res_job.strip_prefix), 0, 0, 0},
659 ++   {"addprefix",    store_str,  ITEM(res_job.add_prefix), 0, 0, 0},
660 ++   {"addsuffix",    store_str,  ITEM(res_job.add_suffix), 0, 0, 0},
661      /* Where to find bootstrap during restore */
662      {"bootstrap",store_dir,      ITEM(res_job.RestoreBootstrap), 0, 0, 0},
663      /* Where to write bootstrap file during backup */
664 -@@ -611,6 +612,9 @@
665 +@@ -611,6 +616,9 @@
666         if (res->res_job.RestoreWhere) {
667            sendit(sock, _("  --> Where=%s\n"), NPRT(res->res_job.RestoreWhere));
668         }
669 @@ -152,6 +220,42 @@
670         if (res->res_job.RestoreBootstrap) {
671            sendit(sock, _("  --> Bootstrap=%s\n"), NPRT(res->res_job.RestoreBootstrap));
672         }
673 +@@ -1143,6 +1151,15 @@
674 +       if (res->res_job.RestoreWhere) {
675 +          free(res->res_job.RestoreWhere);
676 +       }
677 ++      if (res->res_job.strip_prefix) {
678 ++         free(res->res_job.strip_prefix);
679 ++      }
680 ++      if (res->res_job.add_prefix) {
681 ++         free(res->res_job.add_prefix);
682 ++      }
683 ++      if (res->res_job.add_suffix) {
684 ++         free(res->res_job.add_suffix);
685 ++      }
686 +       if (res->res_job.RestoreBootstrap) {
687 +          free(res->res_job.RestoreBootstrap);
688 +       }
689 +@@ -1299,6 +1316,19 @@
690 +          res->res_job.jobdefs    = res_all.res_job.jobdefs;
691 +          res->res_job.run_cmds   = res_all.res_job.run_cmds;
692 +          res->res_job.RunScripts = res_all.res_job.RunScripts;
693 ++       if (res->res_job.strip_prefix ||
694 ++           res->res_job.add_suffix   ||
695 ++           res->res_job.add_prefix)
696 ++       {
697 ++          if (res->res_job.RestoreWhere) {
698 ++             free(res->res_job.RestoreWhere);
699 ++          }
700 ++          res->res_job.where_use_regexp = true;
701 ++          res->res_job.RestoreWhere=bregexp_build_where(res->res_job.strip_prefix,
702 ++                                                        res->res_job.add_prefix,
703 ++                                                        res->res_job.add_suffix);
704 ++          /* TODO: test bregexp */
705 ++       }
706 +          break;
707 +       case R_COUNTER:
708 +          if ((res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name)) == NULL) {
709  Index: src/dird/ua_run.c
710  ===================================================================
711  --- src/dird/ua_run.c  (révision 4466)
712 @@ -227,10 +331,13 @@
713  ===================================================================
714  --- src/dird/dird_conf.h       (révision 4466)
715  +++ src/dird/dird_conf.h       (copie de travail)
716 -@@ -356,6 +356,7 @@
717 +@@ -356,6 +356,10 @@
718      int   Priority;                    /* Job priority */
719      int   RestoreJobId;                /* What -- JobId to restore */
720      char *RestoreWhere;                /* Where on disk to restore -- directory */
721 ++   char *strip_prefix;                /* remove prefix from filename  */
722 ++   char *add_prefix;                  /* add prefix to filename  */
723 ++   char *add_suffix;                  /* add suffix to filename -- .old */
724  +   bool  where_use_regexp;            /* true if RestoreWhere is a BREGEXP */
725      char *RestoreBootstrap;            /* Bootstrap file */
726      alist *RunScripts;                 /* Run {client} program {after|before} Job */
727 @@ -398,30 +505,3 @@
728      if (jcr->cached_path) {
729         free_pool_memory(jcr->cached_path);
730         jcr->cached_path = NULL;
731 -Index: patches/testing/breg.c
732 -===================================================================
733 ---- patches/testing/breg.c     (révision 4510)
734 -+++ patches/testing/breg.c     (copie de travail)
735 -@@ -393,19 +393,19 @@
736
737 -    *str_tmp = *ret = '\0';
738 -    
739 --   if (*strip_prefix) {
740 -+   if (strip_prefix) {
741 -       len += bsnprintf(ret, str_size - len, "!%s!!",
742 -                      bregexp_escape_string(str_tmp, strip_prefix, sep));
743 -    }
744
745 --   if (*add_suffix) {
746 -+   if (add_suffix) {
747 -       if (len) ret[len++] = ',';
748
749 -       len += bsnprintf(ret + len,  str_size - len, "!([^/])$!$1%s!",
750 -                      bregexp_escape_string(str_tmp, add_suffix, sep));
751 -    }
752
753 --   if (*add_prefix) {
754 -+   if (add_prefix) {
755 -       if (len) ret[len++] = ',';
756
757 -       len += bsnprintf(ret + len, str_size - len, "!^!%s!",