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