]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/ua_run.c
Nic's watchdog code + cleanup jcr locking/use_count
[bacula/bacula] / bacula / src / dird / ua_run.c
1 /*
2  *
3  *   Bacula Director -- Run Command
4  *
5  *     Kern Sibbald, December MMI
6  *
7  *   Version $Id$
8  */
9
10 /*
11    Copyright (C) 2001-2003 Kern Sibbald and John Walker
12
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of
16    the License, or (at your option) any later version.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    General Public License for more details.
22
23    You should have received a copy of the GNU General Public
24    License along with this program; if not, write to the Free
25    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26    MA 02111-1307, USA.
27
28  */
29
30 #include "bacula.h"
31 #include "dird.h"
32
33 /* Imported subroutines */
34
35 /* Imported variables */
36 extern struct s_jl joblevels[];
37 extern struct s_kw ReplaceOptions[];
38
39 /*
40  * For Backup and Verify Jobs
41  *     run [job=]<job-name> level=<level-name>
42  *
43  * For Restore Jobs
44  *     run <job-name> jobid=nn
45  *
46  */
47 int run_cmd(UAContext *ua, char *cmd)
48 {
49    JCR *jcr;
50    char *job_name, *level_name, *jid, *store_name, *pool_name;
51    char *where, *fileset_name, *client_name, *bootstrap, *replace;
52    char *when, *verify_job_name;
53    int Priority = 0;
54    int i, j, opt;
55    bool found;
56    JOB *job = NULL;
57    JOB *verify_job = NULL;
58    STORE *store = NULL;
59    CLIENT *client = NULL;
60    FILESET *fileset = NULL;
61    POOL *pool = NULL;
62    static char *kw[] = {              /* command line arguments */
63       N_("job"),                      /*  Used in a switch() */
64       N_("jobid"),                    /* 1 */
65       N_("client"),                   /* 2 */
66       N_("fd"), 
67       N_("fileset"),                  /* 4 */
68       N_("level"),                    /* 5 */
69       N_("storage"),                  /* 6 */
70       N_("sd"),                       /* 7 */
71       N_("pool"),                     /* 8 */
72       N_("where"),                    /* 9 */
73       N_("bootstrap"),                /* 10 */
74       N_("replace"),                  /* 11 */
75       N_("when"),                     /* 12 */
76       N_("priority"),                 /* 13 */
77       N_("yes"),          /* 14 -- if you change this change YES_POS too */
78       N_("run"),          /* 15 -- if you change this change RUN_POS too */
79       N_("verifyjob"),                /* 16 */
80       NULL};
81
82 #define YES_POS 14
83 #define RUN_POS 15
84
85    if (!open_db(ua)) {
86       return 1;
87    }
88
89    job_name = NULL;
90    level_name = NULL;
91    jid = NULL;
92    store_name = NULL;
93    pool_name = NULL;
94    where = NULL;
95    when = NULL;
96    client_name = NULL;
97    fileset_name = NULL;
98    bootstrap = NULL;
99    replace = NULL;
100    verify_job_name = NULL;
101
102    for (i=1; i<ua->argc; i++) {
103       found = false;
104       Dmsg2(200, "Doing arg %d = %s\n", i, ua->argk[i]);
105       for (j=0; !found && kw[j]; j++) {
106          if (strcasecmp(ua->argk[i], _(kw[j])) == 0) {
107             /* Note, yes and run have no value, so do not err */
108             if (!ua->argv[i] && (j != YES_POS /*yes*/ && j != RUN_POS)) {  
109                bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
110                return 1;
111             }
112             Dmsg1(200, "Got keyword=%s\n", kw[j]);
113             switch (j) {
114             case 0: /* job */
115                if (job_name) {
116                   bsendmsg(ua, _("Job name specified twice.\n"));
117                   return 1;
118                }
119                job_name = ua->argv[i];
120                found = true;
121                break;
122             case 1: /* JobId */
123                if (jid) {
124                   bsendmsg(ua, _("JobId specified twice.\n"));
125                   return 1;
126                }
127                jid = ua->argv[i];
128                found = true;
129                break;
130             case 2: /* client */
131             case 3: /* fd */
132                if (client_name) {
133                   bsendmsg(ua, _("Client specified twice.\n"));
134                   return 1;
135                }
136                client_name = ua->argv[i];
137                found = true;
138                break;
139             case 4: /* fileset */
140                if (fileset_name) {
141                   bsendmsg(ua, _("FileSet specified twice.\n"));
142                   return 1;
143                }
144                fileset_name = ua->argv[i];
145                found = true;
146                break;
147             case 5: /* level */
148                if (level_name) {
149                   bsendmsg(ua, _("Level specified twice.\n"));
150                   return 1;
151                }
152                level_name = ua->argv[i];
153                found = true;
154                break;
155             case 6: /* storage */
156             case 7: /* sd */
157                if (store_name) {
158                   bsendmsg(ua, _("Storage specified twice.\n"));
159                   return 1;
160                }
161                store_name = ua->argv[i];
162                found = true;
163                break;
164             case 8: /* pool */
165                if (pool_name) {
166                   bsendmsg(ua, _("Pool specified twice.\n"));
167                   return 1;
168                }
169                pool_name = ua->argv[i];
170                found = true;
171                break;
172             case 9: /* where */
173                if (where) {
174                   bsendmsg(ua, _("Where specified twice.\n"));
175                   return 1;
176                }
177                where = ua->argv[i];
178                found = true;
179                break;
180             case 10: /* bootstrap */
181                if (bootstrap) {
182                   bsendmsg(ua, _("Bootstrap specified twice.\n"));
183                   return 1;
184                }
185                bootstrap = ua->argv[i];
186                found = true;
187                break;
188             case 11: /* replace */
189                if (replace) {
190                   bsendmsg(ua, _("Replace specified twice.\n"));
191                   return 1;
192                }
193                replace = ua->argv[i];
194                found = true;
195                break;
196             case 12: /* When */
197                if (when) {
198                   bsendmsg(ua, _("When specified twice.\n"));
199                   return 1;
200                }
201                when = ua->argv[i];
202                found = true;
203                break;
204             case 13:  /* Priority */
205                if (Priority) {
206                   bsendmsg(ua, _("Priority specified twice.\n"));
207                   return 1;
208                }
209                Priority = atoi(ua->argv[i]);
210                if (Priority <= 0) {
211                   bsendmsg(ua, _("Priority must be positive nonzero setting it to 10.\n"));
212                   Priority = 10;
213                }
214                break;
215             case 14: /* yes */
216             case 15: /* run */
217                found = true;
218                break;
219             case 16: /* Verify Job */
220                if (verify_job_name) {
221                   bsendmsg(ua, _("Verify Job specified twice.\n"));
222                   return 1;
223                }
224                verify_job_name = ua->argv[i];
225                found = true;
226                break;
227
228             default:
229                break;
230             }
231          } /* end strcase compare */
232       } /* end keyword loop */
233       if (!found) {
234          Dmsg1(200, "%s not found\n", ua->argk[i]);
235          /*
236           * Special case for Job Name, it can be the first
237           * keyword that has no value.
238           */
239          if (!job_name && !ua->argv[i]) {
240             job_name = ua->argk[i];   /* use keyword as job name */
241             Dmsg1(200, "Set jobname=%s\n", job_name);
242          } else {
243             bsendmsg(ua, _("Invalid keyword: %s\n"), ua->argk[i]);
244             return 1;
245          }
246       }
247    } /* end argc loop */
248              
249    Dmsg0(200, "Done scan.\n");
250
251    if (job_name) {
252       /* Find Job */
253       job = (JOB *)GetResWithName(R_JOB, job_name);
254       if (!job) {
255          bsendmsg(ua, _("Job \"%s\" not found\n"), job_name);
256          job = select_job_resource(ua);
257       } else {
258          Dmsg1(200, "Found job=%s\n", job_name);
259       }
260    } else {
261       bsendmsg(ua, _("A job name must be specified.\n"));
262       job = select_job_resource(ua);
263    }
264    if (!job) {
265       return 1;
266    }
267
268    if (store_name) {
269       store = (STORE *)GetResWithName(R_STORAGE, store_name);
270       if (!store) {
271          bsendmsg(ua, _("Storage \"%s\" not found.\n"), store_name);
272          store = select_storage_resource(ua);
273       }
274    } else {
275       store = job->storage;           /* use default */
276    }
277    if (!store) {
278       return 1;
279    }
280
281
282    if (pool_name) {
283       pool = (POOL *)GetResWithName(R_POOL, pool_name);
284       if (!pool) {
285          bsendmsg(ua, _("Pool \"%s\" not found.\n"), pool_name);
286          pool = get_pool_resource(ua);
287       }
288    } else {
289       pool = job->pool;             /* use default */
290    }
291
292    if (client_name) {
293       client = (CLIENT *)GetResWithName(R_CLIENT, client_name);
294       if (!client) {
295          bsendmsg(ua, _("Client \"%s\" not found.\n"), client_name);
296          client = select_client_resource(ua);
297       }
298    } else {
299       client = job->client;           /* use default */
300    }
301    if (!client) {
302       return 1;
303    }
304
305    if (fileset_name) {
306       fileset = (FILESET *)GetResWithName(R_FILESET, fileset_name);
307       if (!fileset) {
308          bsendmsg(ua, _("FileSet \"%s\" not found.\n"), fileset_name);
309          fileset = select_fileset_resource(ua);
310       }
311    } else {
312       fileset = job->fileset;           /* use default */
313    }
314    if (!fileset) {
315       return 1;
316    }
317
318    if (verify_job_name) {
319       verify_job = (JOB *)GetResWithName(R_JOB, verify_job_name);
320       if (!verify_job) {
321          bsendmsg(ua, _("Verify Job \"%s\" not found.\n"), verify_job_name);
322          verify_job = select_job_resource(ua);
323       }
324    } else {
325       verify_job = job->verify_job;
326    }
327
328    /*
329     * Create JCR to run job.  NOTE!!! after this point, free_jcr()
330     *  before returning.
331     */
332    jcr = new_jcr(sizeof(JCR), dird_free_jcr);
333    set_jcr_defaults(jcr, job);
334
335    jcr->store = store;
336    jcr->client = client;
337    jcr->fileset = fileset;
338    jcr->pool = pool;
339    if (where) {
340       if (jcr->where) {
341          free(jcr->where);
342       }
343       jcr->where = bstrdup(where);
344    }
345
346    if (when) {
347       jcr->sched_time = str_to_utime(when);
348       if (jcr->sched_time == 0) {
349          bsendmsg(ua, _("Invalid time, using current time.\n"));
350          jcr->sched_time = time(NULL);
351       }
352    }
353          
354    if (bootstrap) {
355       if (jcr->RestoreBootstrap) {
356          free(jcr->RestoreBootstrap);
357       }
358       jcr->RestoreBootstrap = bstrdup(bootstrap);
359    }
360
361    if (replace) {
362       jcr->replace = 0;
363       for (i=0; ReplaceOptions[i].name; i++) {
364          if (strcasecmp(replace, ReplaceOptions[i].name) == 0) {
365             jcr->replace = ReplaceOptions[i].token;
366          }
367       }
368       if (!jcr->replace) {
369          bsendmsg(ua, _("Invalid replace option: %s\n"), replace);
370          goto bail_out;
371       }
372    } else if (job->replace) {
373       jcr->replace = job->replace;
374    } else {
375       jcr->replace = REPLACE_ALWAYS;
376    }
377
378    if (Priority) {
379       jcr->JobPriority = Priority;
380    }
381
382 try_again:
383    replace = ReplaceOptions[0].name;
384    for (i=0; ReplaceOptions[i].name; i++) {
385       if (ReplaceOptions[i].token == jcr->replace) {
386          replace = ReplaceOptions[i].name;
387       }
388    }
389    Dmsg1(20, "JobType=%c\n", jcr->JobType);
390    switch (jcr->JobType) {
391       char ec1[30];
392       char dt[MAX_TIME_LENGTH];
393    case JT_ADMIN:
394          bsendmsg(ua, _("Run %s job\n\
395 JobName:  %s\n\
396 FileSet:  %s\n\
397 Client:   %s\n\
398 Storage:  %s\n\
399 When:     %s\n\
400 Priority: %d\n"),
401                  _("Admin"),
402                  job->hdr.name,
403                  jcr->fileset->hdr.name,
404                  NPRT(jcr->client->hdr.name),
405                  NPRT(jcr->store->hdr.name), 
406                  bstrutime(dt, sizeof(dt), jcr->sched_time), 
407                  jcr->JobPriority);
408       jcr->JobLevel = L_FULL;
409       break;
410    case JT_BACKUP:
411    case JT_VERIFY:
412       if (level_name) {
413          /* Look up level name and pull code */
414          found = 0;
415          for (i=0; joblevels[i].level_name; i++) {
416             if (strcasecmp(level_name, _(joblevels[i].level_name)) == 0) {
417                jcr->JobLevel = joblevels[i].level;
418                found = 1;
419                break;
420             }
421          }
422          if (!found) { 
423             bsendmsg(ua, _("Level %s not valid.\n"), level_name);
424             goto bail_out;
425          }
426       }
427       level_name = NULL;
428       if (jcr->JobType == JT_BACKUP) {
429          bsendmsg(ua, _("Run %s job\n\
430 JobName:  %s\n\
431 FileSet:  %s\n\
432 Level:    %s\n\
433 Client:   %s\n\
434 Storage:  %s\n\
435 Pool:     %s\n\
436 When:     %s\n\
437 Priority: %d\n"),
438                  _("Backup"),
439                  job->hdr.name,
440                  jcr->fileset->hdr.name,
441                  level_to_str(jcr->JobLevel),
442                  jcr->client->hdr.name,
443                  jcr->store->hdr.name,
444                  NPRT(jcr->pool->hdr.name), 
445                  bstrutime(dt, sizeof(dt), jcr->sched_time),
446                  jcr->JobPriority);
447       } else {  /* JT_VERIFY */
448          char *Name;
449          if (jcr->job->verify_job) {
450             Name = jcr->job->verify_job->hdr.name;
451          } else {
452             Name = "";
453          }
454          bsendmsg(ua, _("Run %s job\n\
455 JobName:     %s\n\
456 FileSet:     %s\n\
457 Level:       %s\n\
458 Client:      %s\n\
459 Storage:     %s\n\
460 Pool:        %s\n\
461 Verify Job:  %s\n\
462 When:        %s\n\
463 Priority:    %d\n"),
464               _("Verify"),
465               job->hdr.name,
466               jcr->fileset->hdr.name,
467               level_to_str(jcr->JobLevel),
468               jcr->client->hdr.name,
469               jcr->store->hdr.name,
470               NPRT(jcr->pool->hdr.name), 
471               Name,            
472               bstrutime(dt, sizeof(dt), jcr->sched_time),
473               jcr->JobPriority);
474       }
475       break;
476    case JT_RESTORE:
477       if (jcr->RestoreJobId == 0 && !jcr->RestoreBootstrap) {
478          if (jid) {
479             jcr->RestoreJobId = atoi(jid);
480          } else {
481             if (!get_pint(ua, _("Please enter a JobId for restore: "))) {
482                goto bail_out;
483             }  
484             jcr->RestoreJobId = ua->pint32_val;
485          }
486       }
487       jcr->JobLevel = L_FULL;      /* default level */
488       Dmsg1(20, "JobId to restore=%d\n", jcr->RestoreJobId);
489       if (jcr->RestoreJobId == 0) {
490          bsendmsg(ua, _("Run Restore job\n\
491 JobName:    %s\n\
492 Bootstrap:  %s\n\
493 Where:      %s\n\
494 Replace:    %s\n\
495 FileSet:    %s\n\
496 Client:     %s\n\
497 Storage:    %s\n\
498 When:       %s\n\
499 Priority:   %d\n"),
500               job->hdr.name,
501               NPRT(jcr->RestoreBootstrap),
502               jcr->where?jcr->where:NPRT(job->RestoreWhere),
503               replace,
504               jcr->fileset->hdr.name,
505               jcr->client->hdr.name,
506               jcr->store->hdr.name, 
507               bstrutime(dt, sizeof(dt), jcr->sched_time),
508               jcr->JobPriority);
509       } else {
510          bsendmsg(ua, _("Run Restore job\n\
511 JobName:    %s\n\
512 Bootstrap:  %s\n\
513 Where:      %s\n\
514 Replace:    %s\n\
515 FileSet:    %s\n\
516 Client:     %s\n\
517 Storage:    %s\n\
518 JobId:      %s\n\
519 When:       %s\n\
520 Priority:   %d\n"),
521               job->hdr.name,
522               NPRT(jcr->RestoreBootstrap),
523               jcr->where?jcr->where:NPRT(job->RestoreWhere),
524               replace,
525               jcr->fileset->hdr.name,
526               jcr->client->hdr.name,
527               jcr->store->hdr.name, 
528               jcr->RestoreJobId==0?"*None*":edit_uint64(jcr->RestoreJobId, ec1), 
529               bstrutime(dt, sizeof(dt), jcr->sched_time),
530               jcr->JobPriority);
531       }
532       break;
533    default:
534       bsendmsg(ua, _("Unknown Job Type=%d\n"), jcr->JobType);
535       goto bail_out;
536    }
537
538    /* Run without prompting? */
539    if (find_arg(ua, _("yes")) > 0) {
540       Dmsg1(200, "Calling run_job job=%x\n", jcr->job);
541       run_job(jcr);
542       free_jcr(jcr);                  /* release jcr */
543       bsendmsg(ua, _("Run command submitted.\n"));
544       return 1;
545    }
546
547    if (!get_cmd(ua, _("OK to run? (yes/mod/no): "))) {
548       goto bail_out;
549    }
550    /*
551     * At user request modify parameters of job to be run.
552     */
553    if (ua->cmd[0] == 0) {
554       goto bail_out;
555    }
556    if (strncasecmp(ua->cmd, _("mod"), strlen(ua->cmd)) == 0) {
557       FILE *fd;
558
559       start_prompt(ua, _("Parameters to modify:\n"));
560       add_prompt(ua, _("Level"));            /* 0 */
561       add_prompt(ua, _("Storage"));          /* 1 */
562       add_prompt(ua, _("Job"));              /* 2 */
563       add_prompt(ua, _("FileSet"));          /* 3 */
564       add_prompt(ua, _("Client"));           /* 4 */
565       add_prompt(ua, _("When"));             /* 5 */
566       add_prompt(ua, _("Priority"));         /* 6 */
567       if (jcr->JobType == JT_BACKUP ||
568           jcr->JobType == JT_VERIFY) {
569          add_prompt(ua, _("Pool"));          /* 7 */
570          if (jcr->JobType == JT_VERIFY) {
571             add_prompt(ua, _("Verify Job"));  /* 8 */
572          }
573       } else if (jcr->JobType == JT_RESTORE) {
574          add_prompt(ua, _("Bootstrap"));     /* 7 */
575          add_prompt(ua, _("Where"));         /* 8 */
576          add_prompt(ua, _("Replace"));       /* 9 */
577          add_prompt(ua, _("JobId"));         /* 10 */
578       }
579       switch (do_prompt(ua, "", _("Select parameter to modify"), NULL, 0)) {
580       case 0:
581          /* Level */
582          if (jcr->JobType == JT_BACKUP) {
583             start_prompt(ua, _("Levels:\n"));
584             add_prompt(ua, _("Base"));
585             add_prompt(ua, _("Full"));
586             add_prompt(ua, _("Incremental"));
587             add_prompt(ua, _("Differential"));
588             add_prompt(ua, _("Since"));
589             switch (do_prompt(ua, "", _("Select level"), NULL, 0)) {
590             case 0:
591                jcr->JobLevel = L_BASE;
592                break;
593             case 1:
594                jcr->JobLevel = L_FULL;
595                break;
596             case 2:
597                jcr->JobLevel = L_INCREMENTAL;
598                break;
599             case 3:
600                jcr->JobLevel = L_DIFFERENTIAL;
601                break;
602             case 4:
603                jcr->JobLevel = L_SINCE;
604                break;
605             default:
606                break;
607             }
608             goto try_again;
609          } else if (jcr->JobType == JT_VERIFY) {
610             start_prompt(ua, _("Levels:\n"));
611             add_prompt(ua, _("Initialize Catalog"));
612             add_prompt(ua, _("Verify Catalog"));
613             add_prompt(ua, _("Verify Volume to Catalog"));
614             add_prompt(ua, _("Verify Disk to Catalog"));
615             add_prompt(ua, _("Verify Volume Data (not yet implemented)"));
616             switch (do_prompt(ua, "",  _("Select level"), NULL, 0)) {
617             case 0:
618                jcr->JobLevel = L_VERIFY_INIT;
619                break;
620             case 1:
621                jcr->JobLevel = L_VERIFY_CATALOG;
622                break;
623             case 2:
624                jcr->JobLevel = L_VERIFY_VOLUME_TO_CATALOG;
625                break;
626             case 3:
627                jcr->JobLevel = L_VERIFY_DISK_TO_CATALOG;
628                break;
629             case 4:
630                jcr->JobLevel = L_VERIFY_DATA;
631                break;
632             default:
633                break;
634             }
635             goto try_again;
636          } else {
637             bsendmsg(ua, _("Level not appropriate for this Job. Cannot be changed.\n"));
638          }
639          goto try_again;
640       case 1:
641          /* Storage */
642          store = select_storage_resource(ua);
643          if (store) {
644             jcr->store = store;
645             goto try_again;
646          }
647          break;
648       case 2:
649          /* Job */
650          job = select_job_resource(ua);
651          if (job) {
652             jcr->job = job;
653             set_jcr_defaults(jcr, job);
654             goto try_again;
655          }
656          break;
657       case 3:
658          /* FileSet */
659          fileset = select_fileset_resource(ua);
660          if (fileset) {
661             jcr->fileset = fileset;
662             goto try_again;
663          }      
664          break;
665       case 4:
666          /* Client */
667          client = select_client_resource(ua);
668          if (client) {
669             jcr->client = client;
670             goto try_again;
671          }
672          break;
673       case 5:
674          /* When */
675          if (!get_cmd(ua, _("Please enter desired start time as YYYY-MM-DD HH:MM:SS (return for now): "))) {
676             break;
677          }
678          if (ua->cmd[0] == 0) {
679             jcr->sched_time = time(NULL);
680          } else {
681             jcr->sched_time = str_to_utime(ua->cmd);
682             if (jcr->sched_time == 0) {
683                bsendmsg(ua, _("Invalid time, using current time.\n"));
684                jcr->sched_time = time(NULL);
685             }
686          }
687          goto try_again;
688       case 6:
689          /* Priority */
690          if (!get_pint(ua, _("Enter new Priority: "))) {
691             break;
692          }
693          if (ua->pint32_val == 0) {
694             bsendmsg(ua, _("Priority must be a positive integer.\n"));
695          } else {
696             jcr->JobPriority = ua->pint32_val;
697          }
698          goto try_again;
699       case 7:
700          /* Pool or Bootstrap depending on JobType */
701          if (jcr->JobType == JT_BACKUP ||
702              jcr->JobType == JT_VERIFY) {      /* Pool */
703             pool = select_pool_resource(ua);
704             if (pool) {
705                jcr->pool = pool;
706                goto try_again;
707             }
708             break;
709          }
710
711          /* Bootstrap */
712          if (!get_cmd(ua, _("Please enter the Bootstrap file name: "))) {
713             break;
714          }
715          if (jcr->RestoreBootstrap) {
716             free(jcr->RestoreBootstrap);
717             jcr->RestoreBootstrap = NULL;
718          }
719          if (ua->cmd[0] != 0) {
720             jcr->RestoreBootstrap = bstrdup(ua->cmd);
721             fd = fopen(jcr->RestoreBootstrap, "r");
722             if (!fd) {
723                bsendmsg(ua, _("Warning cannot open %s: ERR=%s\n"),
724                   jcr->RestoreBootstrap, strerror(errno));
725                free(jcr->RestoreBootstrap);
726                jcr->RestoreBootstrap = NULL;
727             } else {
728                fclose(fd);
729             }
730          }
731          goto try_again;
732       case 8:
733          /* Verify Job */
734          if (jcr->JobType == JT_VERIFY) {
735             JOB *job = select_job_resource(ua);
736             if (job) {
737                jcr->job->verify_job = job;
738             } else {
739                jcr->job->verify_job = NULL;
740             }
741             goto try_again;
742          }
743          /* Where */
744          if (!get_cmd(ua, _("Please enter path prefix for restore (/ for none): "))) {
745             break;
746          }
747          if (jcr->where) {
748             free(jcr->where);
749             jcr->where = NULL;
750          }
751          if (ua->cmd[0] == '/' && ua->cmd[1] == 0) {
752             ua->cmd[0] = 0;
753          }
754          jcr->where = bstrdup(ua->cmd);
755          goto try_again;
756       case 9:
757          /* Replace */
758          start_prompt(ua, _("Replace:\n"));
759          for (i=0; ReplaceOptions[i].name; i++) {
760             add_prompt(ua, ReplaceOptions[i].name);
761          }
762          opt = do_prompt(ua, "", _("Select replace option"), NULL, 0);
763          if (opt >=  0) {
764             jcr->replace = ReplaceOptions[opt].token;
765          }
766          goto try_again;
767       case 10:
768          /* JobId */
769          jid = NULL;                  /* force reprompt */
770          jcr->RestoreJobId = 0;
771          if (jcr->RestoreBootstrap) {
772             bsendmsg(ua, _("You must set the bootstrap file to NULL to be able to specify a JobId.\n"));
773          }
774          goto try_again;
775       default: 
776          goto try_again;
777       }
778       goto bail_out;
779    }
780
781    if (strncasecmp(ua->cmd, _("yes"), strlen(ua->cmd)) == 0) {
782       Dmsg1(200, "Calling run_job job=%x\n", jcr->job);
783       run_job(jcr);
784       free_jcr(jcr);                  /* release jcr */
785       bsendmsg(ua, _("Run command submitted.\n"));
786       return 1;
787    }
788
789 bail_out:
790    bsendmsg(ua, _("Job not run.\n"));
791    free_jcr(jcr);
792    return 0;                       /* do not run */
793 }