]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/ua_run.c
More data spooling updates
[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, files = 0;
55    bool kw_ok;
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_("verifyjob"),                /* 15 */
79       N_("files"),                    /* 16 number of files to restore */
80       NULL};
81
82 #define YES_POS 14
83
84    if (!open_db(ua)) {
85       return 1;
86    }
87
88    job_name = NULL;
89    level_name = NULL;
90    jid = NULL;
91    store_name = NULL;
92    pool_name = NULL;
93    where = NULL;
94    when = NULL;
95    client_name = NULL;
96    fileset_name = NULL;
97    bootstrap = NULL;
98    replace = NULL;
99    verify_job_name = NULL;
100
101    for (i=1; i<ua->argc; i++) {
102       Dmsg2(200, "Doing arg %d = %s\n", i, ua->argk[i]);
103       kw_ok = false;
104       /* Keep looking until we find a good keyword */
105       for (j=0; !kw_ok && 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*/) {  
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                kw_ok = 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                kw_ok = 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                kw_ok = 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                kw_ok = 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                kw_ok = 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                kw_ok = 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                kw_ok = 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                kw_ok = 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                kw_ok = 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                kw_ok = 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                kw_ok = 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                kw_ok = true;
215                break;
216             case 14: /* yes */
217                kw_ok = true;
218                break;
219             case 15: /* 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                kw_ok = true;
226                break;
227             case 16: /* files */
228                files = atoi(ua->argv[i]);
229                kw_ok = true;
230                break;
231
232             default:
233                break;
234             }
235          } /* end strcase compare */
236       } /* end keyword loop */
237       /*
238        * End of keyword for loop -- if not found, we got a bogus keyword
239        */
240       if (!kw_ok) {
241          Dmsg1(200, "%s not found\n", ua->argk[i]);
242          /*
243           * Special case for Job Name, it can be the first
244           * keyword that has no value.
245           */
246          if (!job_name && !ua->argv[i]) {
247             job_name = ua->argk[i];   /* use keyword as job name */
248             Dmsg1(200, "Set jobname=%s\n", job_name);
249          } else {
250             bsendmsg(ua, _("Invalid keyword: %s\n"), ua->argk[i]);
251             return 1;
252          }
253       }
254    } /* end argc loop */
255              
256    Dmsg0(200, "Done scan.\n");
257
258    if (job_name) {
259       /* Find Job */
260       job = (JOB *)GetResWithName(R_JOB, job_name);
261       if (!job) {
262          if (*job_name != 0) {
263             bsendmsg(ua, _("Job \"%s\" not found\n"), job_name);
264          }
265          job = select_job_resource(ua);
266       } else {
267          Dmsg1(200, "Found job=%s\n", job_name);
268       }
269    } else {
270       bsendmsg(ua, _("A job name must be specified.\n"));
271       job = select_job_resource(ua);
272    }
273    if (!job) {
274       return 1;
275    }
276
277    if (store_name) {
278       store = (STORE *)GetResWithName(R_STORAGE, store_name);
279       if (!store) {
280          if (*store_name != 0) {
281             bsendmsg(ua, _("Storage \"%s\" not found.\n"), store_name);
282          }
283          store = select_storage_resource(ua);
284       }
285    } else {
286       store = job->storage;           /* use default */
287    }
288    if (!store) {
289       return 1;
290    }
291
292
293    if (pool_name) {
294       pool = (POOL *)GetResWithName(R_POOL, pool_name);
295       if (!pool) {
296          if (*pool_name != 0) {
297             bsendmsg(ua, _("Pool \"%s\" not found.\n"), pool_name);
298          }
299          pool = select_pool_resource(ua);
300       }
301    } else {
302       pool = job->pool;             /* use default */
303    }
304    if (!pool) {
305       return 1;
306    }
307
308    if (client_name) {
309       client = (CLIENT *)GetResWithName(R_CLIENT, client_name);
310       if (!client) {
311          if (*client_name != 0) {
312             bsendmsg(ua, _("Client \"%s\" not found.\n"), client_name);
313          }
314          client = select_client_resource(ua);
315       }
316    } else {
317       client = job->client;           /* use default */
318    }
319    if (!client) {
320       return 1;
321    }
322
323    if (fileset_name) {
324       fileset = (FILESET *)GetResWithName(R_FILESET, fileset_name);
325       if (!fileset) {
326          bsendmsg(ua, _("FileSet \"%s\" not found.\n"), fileset_name);
327          fileset = select_fileset_resource(ua);
328       }
329    } else {
330       fileset = job->fileset;           /* use default */
331    }
332    if (!fileset) {
333       return 1;
334    }
335
336    if (verify_job_name) {
337       verify_job = (JOB *)GetResWithName(R_JOB, verify_job_name);
338       if (!verify_job) {
339          bsendmsg(ua, _("Verify Job \"%s\" not found.\n"), verify_job_name);
340          verify_job = select_job_resource(ua);
341       }
342    } else {
343       verify_job = job->verify_job;
344    }
345
346    /*
347     * Create JCR to run job.  NOTE!!! after this point, free_jcr()
348     *  before returning.
349     */
350    jcr = new_jcr(sizeof(JCR), dird_free_jcr);
351    set_jcr_defaults(jcr, job);
352
353    jcr->store = store;
354    jcr->client = client;
355    jcr->fileset = fileset;
356    jcr->pool = pool;
357    jcr->ExpectedFiles = files;
358    if (where) {
359       if (jcr->where) {
360          free(jcr->where);
361       }
362       jcr->where = bstrdup(where);
363    }
364
365    if (when) {
366       jcr->sched_time = str_to_utime(when);
367       if (jcr->sched_time == 0) {
368          bsendmsg(ua, _("Invalid time, using current time.\n"));
369          jcr->sched_time = time(NULL);
370       }
371    }
372          
373    if (bootstrap) {
374       if (jcr->RestoreBootstrap) {
375          free(jcr->RestoreBootstrap);
376       }
377       jcr->RestoreBootstrap = bstrdup(bootstrap);
378    }
379
380    if (replace) {
381       jcr->replace = 0;
382       for (i=0; ReplaceOptions[i].name; i++) {
383          if (strcasecmp(replace, ReplaceOptions[i].name) == 0) {
384             jcr->replace = ReplaceOptions[i].token;
385          }
386       }
387       if (!jcr->replace) {
388          bsendmsg(ua, _("Invalid replace option: %s\n"), replace);
389          goto bail_out;
390       }
391    } else if (job->replace) {
392       jcr->replace = job->replace;
393    } else {
394       jcr->replace = REPLACE_ALWAYS;
395    }
396
397    if (Priority) {
398       jcr->JobPriority = Priority;
399    }
400
401 try_again:
402    replace = ReplaceOptions[0].name;
403    for (i=0; ReplaceOptions[i].name; i++) {
404       if (ReplaceOptions[i].token == jcr->replace) {
405          replace = ReplaceOptions[i].name;
406       }
407    }
408    if (level_name) {
409       /* Look up level name and pull code */
410       bool found = false;
411       for (i=0; joblevels[i].level_name; i++) {
412          if (strcasecmp(level_name, _(joblevels[i].level_name)) == 0) {
413             jcr->JobLevel = joblevels[i].level;
414             found = true;
415             break;
416          }
417       }
418       if (!found) { 
419          bsendmsg(ua, _("Level %s not valid.\n"), level_name);
420          goto bail_out;
421       }
422    }
423    level_name = NULL;
424    if (jid) {
425       jcr->RestoreJobId = atoi(jid);
426    }
427
428    /* Run without prompting? */
429    if (find_arg(ua, _("yes")) > 0) {
430       Dmsg1(200, "Calling run_job job=%x\n", jcr->job);
431       run_job(jcr);
432       free_jcr(jcr);                  /* release jcr */
433       bsendmsg(ua, _("Run command submitted.\n"));
434       return 1;
435    }
436
437    /*  
438     * Prompt User to see if all run job parameters are correct, and
439     *   allow him to modify them.
440     */
441    Dmsg1(20, "JobType=%c\n", jcr->JobType);
442    switch (jcr->JobType) {
443       char ec1[30];
444       char dt[MAX_TIME_LENGTH];
445    case JT_ADMIN:
446          bsendmsg(ua, _("Run %s job\n\
447 JobName:  %s\n\
448 FileSet:  %s\n\
449 Client:   %s\n\
450 Storage:  %s\n\
451 When:     %s\n\
452 Priority: %d\n"),
453                  _("Admin"),
454                  job->hdr.name,
455                  jcr->fileset->hdr.name,
456                  NPRT(jcr->client->hdr.name),
457                  NPRT(jcr->store->hdr.name), 
458                  bstrutime(dt, sizeof(dt), jcr->sched_time), 
459                  jcr->JobPriority);
460       jcr->JobLevel = L_FULL;
461       break;
462    case JT_BACKUP:
463    case JT_VERIFY:
464       if (jcr->JobType == JT_BACKUP) {
465          bsendmsg(ua, _("Run %s job\n\
466 JobName:  %s\n\
467 FileSet:  %s\n\
468 Level:    %s\n\
469 Client:   %s\n\
470 Storage:  %s\n\
471 Pool:     %s\n\
472 When:     %s\n\
473 Priority: %d\n"),
474                  _("Backup"),
475                  job->hdr.name,
476                  jcr->fileset->hdr.name,
477                  level_to_str(jcr->JobLevel),
478                  jcr->client->hdr.name,
479                  jcr->store->hdr.name,
480                  NPRT(jcr->pool->hdr.name), 
481                  bstrutime(dt, sizeof(dt), jcr->sched_time),
482                  jcr->JobPriority);
483       } else {  /* JT_VERIFY */
484          char *Name;
485          if (jcr->job->verify_job) {
486             Name = jcr->job->verify_job->hdr.name;
487          } else {
488             Name = "";
489          }
490          bsendmsg(ua, _("Run %s job\n\
491 JobName:     %s\n\
492 FileSet:     %s\n\
493 Level:       %s\n\
494 Client:      %s\n\
495 Storage:     %s\n\
496 Pool:        %s\n\
497 Verify Job:  %s\n\
498 When:        %s\n\
499 Priority:    %d\n"),
500               _("Verify"),
501               job->hdr.name,
502               jcr->fileset->hdr.name,
503               level_to_str(jcr->JobLevel),
504               jcr->client->hdr.name,
505               jcr->store->hdr.name,
506               NPRT(jcr->pool->hdr.name), 
507               Name,            
508               bstrutime(dt, sizeof(dt), jcr->sched_time),
509               jcr->JobPriority);
510       }
511       break;
512    case JT_RESTORE:
513       if (jcr->RestoreJobId == 0 && !jcr->RestoreBootstrap) {
514          if (jid) {
515             jcr->RestoreJobId = atoi(jid);
516          } else {
517             if (!get_pint(ua, _("Please enter a JobId for restore: "))) {
518                goto bail_out;
519             }  
520             jcr->RestoreJobId = ua->pint32_val;
521          }
522       }
523       jcr->JobLevel = L_FULL;      /* default level */
524       Dmsg1(20, "JobId to restore=%d\n", jcr->RestoreJobId);
525       if (jcr->RestoreJobId == 0) {
526          bsendmsg(ua, _("Run Restore job\n\
527 JobName:    %s\n\
528 Bootstrap:  %s\n\
529 Where:      %s\n\
530 Replace:    %s\n\
531 FileSet:    %s\n\
532 Client:     %s\n\
533 Storage:    %s\n\
534 When:       %s\n\
535 Priority:   %d\n"),
536               job->hdr.name,
537               NPRT(jcr->RestoreBootstrap),
538               jcr->where?jcr->where:NPRT(job->RestoreWhere),
539               replace,
540               jcr->fileset->hdr.name,
541               jcr->client->hdr.name,
542               jcr->store->hdr.name, 
543               bstrutime(dt, sizeof(dt), jcr->sched_time),
544               jcr->JobPriority);
545       } else {
546          bsendmsg(ua, _("Run Restore job\n\
547 JobName:    %s\n\
548 Bootstrap:  %s\n\
549 Where:      %s\n\
550 Replace:    %s\n\
551 FileSet:    %s\n\
552 Client:     %s\n\
553 Storage:    %s\n\
554 JobId:      %s\n\
555 When:       %s\n\
556 Priority:   %d\n"),
557               job->hdr.name,
558               NPRT(jcr->RestoreBootstrap),
559               jcr->where?jcr->where:NPRT(job->RestoreWhere),
560               replace,
561               jcr->fileset->hdr.name,
562               jcr->client->hdr.name,
563               jcr->store->hdr.name, 
564               jcr->RestoreJobId==0?"*None*":edit_uint64(jcr->RestoreJobId, ec1), 
565               bstrutime(dt, sizeof(dt), jcr->sched_time),
566               jcr->JobPriority);
567       }
568       break;
569    default:
570       bsendmsg(ua, _("Unknown Job Type=%d\n"), jcr->JobType);
571       goto bail_out;
572    }
573
574
575    if (!get_cmd(ua, _("OK to run? (yes/mod/no): "))) {
576       goto bail_out;
577    }
578    /*
579     * At user request modify parameters of job to be run.
580     */
581    if (ua->cmd[0] == 0) {
582       goto bail_out;
583    }
584    if (strncasecmp(ua->cmd, _("mod"), strlen(ua->cmd)) == 0) {
585       FILE *fd;
586
587       start_prompt(ua, _("Parameters to modify:\n"));
588       add_prompt(ua, _("Level"));            /* 0 */
589       add_prompt(ua, _("Storage"));          /* 1 */
590       add_prompt(ua, _("Job"));              /* 2 */
591       add_prompt(ua, _("FileSet"));          /* 3 */
592       add_prompt(ua, _("Client"));           /* 4 */
593       add_prompt(ua, _("When"));             /* 5 */
594       add_prompt(ua, _("Priority"));         /* 6 */
595       if (jcr->JobType == JT_BACKUP ||
596           jcr->JobType == JT_VERIFY) {
597          add_prompt(ua, _("Pool"));          /* 7 */
598          if (jcr->JobType == JT_VERIFY) {
599             add_prompt(ua, _("Verify Job"));  /* 8 */
600          }
601       } else if (jcr->JobType == JT_RESTORE) {
602          add_prompt(ua, _("Bootstrap"));     /* 7 */
603          add_prompt(ua, _("Where"));         /* 8 */
604          add_prompt(ua, _("Replace"));       /* 9 */
605          add_prompt(ua, _("JobId"));         /* 10 */
606       }
607       switch (do_prompt(ua, "", _("Select parameter to modify"), NULL, 0)) {
608       case 0:
609          /* Level */
610          if (jcr->JobType == JT_BACKUP) {
611             start_prompt(ua, _("Levels:\n"));
612             add_prompt(ua, _("Base"));
613             add_prompt(ua, _("Full"));
614             add_prompt(ua, _("Incremental"));
615             add_prompt(ua, _("Differential"));
616             add_prompt(ua, _("Since"));
617             switch (do_prompt(ua, "", _("Select level"), NULL, 0)) {
618             case 0:
619                jcr->JobLevel = L_BASE;
620                break;
621             case 1:
622                jcr->JobLevel = L_FULL;
623                break;
624             case 2:
625                jcr->JobLevel = L_INCREMENTAL;
626                break;
627             case 3:
628                jcr->JobLevel = L_DIFFERENTIAL;
629                break;
630             case 4:
631                jcr->JobLevel = L_SINCE;
632                break;
633             default:
634                break;
635             }
636             goto try_again;
637          } else if (jcr->JobType == JT_VERIFY) {
638             start_prompt(ua, _("Levels:\n"));
639             add_prompt(ua, _("Initialize Catalog"));
640             add_prompt(ua, _("Verify Catalog"));
641             add_prompt(ua, _("Verify Volume to Catalog"));
642             add_prompt(ua, _("Verify Disk to Catalog"));
643             add_prompt(ua, _("Verify Volume Data (not yet implemented)"));
644             switch (do_prompt(ua, "",  _("Select level"), NULL, 0)) {
645             case 0:
646                jcr->JobLevel = L_VERIFY_INIT;
647                break;
648             case 1:
649                jcr->JobLevel = L_VERIFY_CATALOG;
650                break;
651             case 2:
652                jcr->JobLevel = L_VERIFY_VOLUME_TO_CATALOG;
653                break;
654             case 3:
655                jcr->JobLevel = L_VERIFY_DISK_TO_CATALOG;
656                break;
657             case 4:
658                jcr->JobLevel = L_VERIFY_DATA;
659                break;
660             default:
661                break;
662             }
663             goto try_again;
664          } else {
665             bsendmsg(ua, _("Level not appropriate for this Job. Cannot be changed.\n"));
666          }
667          goto try_again;
668       case 1:
669          /* Storage */
670          store = select_storage_resource(ua);
671          if (store) {
672             jcr->store = store;
673             goto try_again;
674          }
675          break;
676       case 2:
677          /* Job */
678          job = select_job_resource(ua);
679          if (job) {
680             jcr->job = job;
681             set_jcr_defaults(jcr, job);
682             goto try_again;
683          }
684          break;
685       case 3:
686          /* FileSet */
687          fileset = select_fileset_resource(ua);
688          if (fileset) {
689             jcr->fileset = fileset;
690             goto try_again;
691          }      
692          break;
693       case 4:
694          /* Client */
695          client = select_client_resource(ua);
696          if (client) {
697             jcr->client = client;
698             goto try_again;
699          }
700          break;
701       case 5:
702          /* When */
703          if (!get_cmd(ua, _("Please enter desired start time as YYYY-MM-DD HH:MM:SS (return for now): "))) {
704             break;
705          }
706          if (ua->cmd[0] == 0) {
707             jcr->sched_time = time(NULL);
708          } else {
709             jcr->sched_time = str_to_utime(ua->cmd);
710             if (jcr->sched_time == 0) {
711                bsendmsg(ua, _("Invalid time, using current time.\n"));
712                jcr->sched_time = time(NULL);
713             }
714          }
715          goto try_again;
716       case 6:
717          /* Priority */
718          if (!get_pint(ua, _("Enter new Priority: "))) {
719             break;
720          }
721          if (ua->pint32_val == 0) {
722             bsendmsg(ua, _("Priority must be a positive integer.\n"));
723          } else {
724             jcr->JobPriority = ua->pint32_val;
725          }
726          goto try_again;
727       case 7:
728          /* Pool or Bootstrap depending on JobType */
729          if (jcr->JobType == JT_BACKUP ||
730              jcr->JobType == JT_VERIFY) {      /* Pool */
731             pool = select_pool_resource(ua);
732             if (pool) {
733                jcr->pool = pool;
734                goto try_again;
735             }
736             break;
737          }
738
739          /* Bootstrap */
740          if (!get_cmd(ua, _("Please enter the Bootstrap file name: "))) {
741             break;
742          }
743          if (jcr->RestoreBootstrap) {
744             free(jcr->RestoreBootstrap);
745             jcr->RestoreBootstrap = NULL;
746          }
747          if (ua->cmd[0] != 0) {
748             jcr->RestoreBootstrap = bstrdup(ua->cmd);
749             fd = fopen(jcr->RestoreBootstrap, "r");
750             if (!fd) {
751                bsendmsg(ua, _("Warning cannot open %s: ERR=%s\n"),
752                   jcr->RestoreBootstrap, strerror(errno));
753                free(jcr->RestoreBootstrap);
754                jcr->RestoreBootstrap = NULL;
755             } else {
756                fclose(fd);
757             }
758          }
759          goto try_again;
760       case 8:
761          /* Verify Job */
762          if (jcr->JobType == JT_VERIFY) {
763             JOB *job = select_job_resource(ua);
764             if (job) {
765                jcr->job->verify_job = job;
766             } else {
767                jcr->job->verify_job = NULL;
768             }
769             goto try_again;
770          }
771          /* Where */
772          if (!get_cmd(ua, _("Please enter path prefix for restore (/ for none): "))) {
773             break;
774          }
775          if (jcr->where) {
776             free(jcr->where);
777             jcr->where = NULL;
778          }
779          if (ua->cmd[0] == '/' && ua->cmd[1] == 0) {
780             ua->cmd[0] = 0;
781          }
782          jcr->where = bstrdup(ua->cmd);
783          goto try_again;
784       case 9:
785          /* Replace */
786          start_prompt(ua, _("Replace:\n"));
787          for (i=0; ReplaceOptions[i].name; i++) {
788             add_prompt(ua, ReplaceOptions[i].name);
789          }
790          opt = do_prompt(ua, "", _("Select replace option"), NULL, 0);
791          if (opt >=  0) {
792             jcr->replace = ReplaceOptions[opt].token;
793          }
794          goto try_again;
795       case 10:
796          /* JobId */
797          jid = NULL;                  /* force reprompt */
798          jcr->RestoreJobId = 0;
799          if (jcr->RestoreBootstrap) {
800             bsendmsg(ua, _("You must set the bootstrap file to NULL to be able to specify a JobId.\n"));
801          }
802          goto try_again;
803       default: 
804          goto try_again;
805       }
806       goto bail_out;
807    }
808
809    if (strncasecmp(ua->cmd, _("yes"), strlen(ua->cmd)) == 0) {
810       Dmsg1(200, "Calling run_job job=%x\n", jcr->job);
811       run_job(jcr);
812       free_jcr(jcr);                  /* release jcr */
813       bsendmsg(ua, _("Run command submitted.\n"));
814       return 1;
815    }
816
817 bail_out:
818    bsendmsg(ua, _("Job not run.\n"));
819    free_jcr(jcr);
820    return 0;                       /* do not run */
821 }