3 * Bacula Director -- Run Command
5 * Kern Sibbald, December MMI
11 Copyright (C) 2001, 2002 Kern Sibbald and John Walker
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.
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.
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,
34 /* Imported subroutines */
35 extern void run_job(JCR *jcr);
37 /* Imported variables */
38 extern struct s_jl joblevels[];
41 * For Backup and Verify Jobs
42 * run [job=]<job-name> level=<level-name>
45 * run <job-name> jobid=nn
48 int runcmd(UAContext *ua, char *cmd)
52 char *job_name, *level_name, *jid, *store_name;
53 char *where, *fileset_name, *client_name, *bootstrap;
82 Dmsg1(20, "run: %s\n", ua->UA_sock->msg);
84 for (i=1; i<ua->argc; i++) {
86 Dmsg2(200, "Doing arg %d = %s\n", i, ua->argk[i]);
87 for (j=0; !found && kw[j]; j++) {
88 if (strcasecmp(ua->argk[i], _(kw[j])) == 0) {
90 bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
93 Dmsg1(200, "Got keyword=%s\n", kw[j]);
97 bsendmsg(ua, _("Job name specified twice.\n"));
100 job_name = ua->argv[i];
105 bsendmsg(ua, _("JobId specified twice.\n"));
113 bsendmsg(ua, _("Client specified twice.\n"));
116 client_name = ua->argv[i];
119 case 3: /* fileset */
121 bsendmsg(ua, _("FileSet specified twice.\n"));
124 fileset_name = ua->argv[i];
129 bsendmsg(ua, _("Level specified twice.\n"));
132 level_name = ua->argv[i];
135 case 5: /* storage */
137 bsendmsg(ua, _("Storage specified twice.\n"));
140 store_name = ua->argv[i];
145 bsendmsg(ua, _("Where specified twice.\n"));
151 case 7: /* bootstrap */
153 bsendmsg(ua, _("Bootstrap specified twice.\n"));
156 bootstrap = ua->argv[i];
162 } /* end strcase compare */
163 } /* end keyword loop */
165 Dmsg1(200, "%s not found\n", ua->argk[i]);
167 * Special case for Job Name, it can be the first
168 * keyword that has no value.
170 if (!job_name && !ua->argv[i]) {
171 job_name = ua->argk[i]; /* use keyword as job name */
172 Dmsg1(200, "Set jobname=%s\n", job_name);
174 bsendmsg(ua, _("Invalid keyword: %s\n"), ua->argk[i]);
178 } /* end argc loop */
180 Dmsg0(20, "Done scan.\n");
183 job = (JOB *)GetResWithName(R_JOB, job_name);
185 bsendmsg(ua, _("Job %s: not found\n"), job_name);
186 job = select_job_resource(ua);
188 Dmsg1(20, "Found job=%s\n", job_name);
191 bsendmsg(ua, _("A job name must be specified.\n"));
192 job = select_job_resource(ua);
199 store = (STORE *)GetResWithName(R_STORAGE, store_name);
201 bsendmsg(ua, _("Storage %s not found.\n"), store_name);
202 store = select_storage_resource(ua);
205 store = job->storage; /* use default */
211 jcr = new_jcr(sizeof(JCR), dird_free_jcr);
212 set_jcr_defaults(jcr, job);
213 jcr->store = store; /* set possible new Storage */
216 Dmsg1(20, "JobType=%c\n", jcr->JobType);
217 switch (jcr->JobType) {
220 bsendmsg(ua, _("Run %s job\n\
227 jcr->fileset->hdr.name,
228 NPRT(jcr->client->hdr.name),
229 NPRT(jcr->store->hdr.name));
235 /* Look up level name and pull code */
237 for (i=0; joblevels[i].level_name; i++) {
238 if (strcasecmp(level_name, _(joblevels[i].level_name)) == 0) {
239 jcr->JobLevel = joblevels[i].level;
245 bsendmsg(ua, _("Level %s not valid.\n"), level_name);
251 bsendmsg(ua, _("Run %s job\n\
257 jcr->JobType==JT_BACKUP?_("Backup"):_("Verify"),
259 jcr->fileset->hdr.name,
260 level_to_str(jcr->JobLevel),
261 jcr->client->hdr.name,
262 jcr->store->hdr.name);
265 if (jcr->RestoreJobId == 0 && !jcr->RestoreBootstrap) {
267 jcr->RestoreJobId = atoi(jid);
269 if (!get_cmd(ua, _("Please enter a JobId for restore: "))) {
273 jcr->RestoreJobId = atoi(ua->cmd);
276 jcr->JobLevel = 'F'; /* default level */
277 Dmsg1(20, "JobId to restore=%d\n", jcr->RestoreJobId);
278 bsendmsg(ua, _("Run Restore job\n\
287 NPRT(jcr->RestoreBootstrap),
288 jcr->RestoreWhere?jcr->RestoreWhere:NPRT(job->RestoreWhere),
289 jcr->fileset->hdr.name,
290 jcr->client->hdr.name,
291 jcr->store->hdr.name,
292 jcr->RestoreJobId==0?"*None*":edit_uint64(jcr->RestoreJobId, ec1));
295 bsendmsg(ua, _("Unknown Job Type=%d\n"), jcr->JobType);
299 if (!get_cmd(ua, _("OK to run? (yes/mod/no): "))) {
301 return 0; /* do not run */
304 * At user request modify parameters of job to be run.
306 if (strcasecmp(ua->cmd, _("mod")) == 0) {
309 start_prompt(ua, _("Parameters to modify:\n"));
310 add_prompt(ua, _("Level")); /* 0 */
311 add_prompt(ua, _("Storage")); /* 1 */
312 add_prompt(ua, _("Job")); /* 2 */
313 add_prompt(ua, _("FileSet")); /* 3 */
314 add_prompt(ua, _("Client")); /* 4 */
315 if (jcr->JobType == JT_RESTORE) {
316 add_prompt(ua, _("Bootstrap")); /* 5 */
317 add_prompt(ua, _("Where")); /* 6 */
318 add_prompt(ua, _("JobId")); /* 7 */
320 switch (do_prompt(ua, _("Select parameter to modify"), NULL)) {
323 if (jcr->JobType == JT_BACKUP) {
324 start_prompt(ua, _("Levels:\n"));
325 add_prompt(ua, _("Full"));
326 add_prompt(ua, _("Incremental"));
327 add_prompt(ua, _("Differential"));
328 add_prompt(ua, _("Level"));
329 add_prompt(ua, _("Since"));
330 switch (do_prompt(ua, _("Select level"), NULL)) {
332 jcr->JobLevel = L_FULL;
335 jcr->JobLevel = L_INCREMENTAL;
338 jcr->JobLevel = L_DIFFERENTIAL;
341 jcr->JobLevel = L_LEVEL;
344 jcr->JobLevel = L_SINCE;
350 } else if (jcr->JobType == JT_VERIFY) {
351 start_prompt(ua, _("Levels:\n"));
352 add_prompt(ua, _("Initialize Catalog"));
353 add_prompt(ua, _("Verify Catalog"));
354 add_prompt(ua, _("Verify Volume"));
355 add_prompt(ua, _("Verify Volume Data"));
356 switch (do_prompt(ua, _("Select level"), NULL)) {
358 jcr->JobLevel = L_VERIFY_INIT;
361 jcr->JobLevel = L_VERIFY_CATALOG;
364 jcr->JobLevel = L_VERIFY_VOLUME_TO_CATALOG;
367 jcr->JobLevel = L_VERIFY_DATA;
374 bsendmsg(ua, _("Level not appropriate for this Job. Cannot be changed.\n"));
378 store = select_storage_resource(ua);
386 job = select_job_resource(ua);
389 set_jcr_defaults(jcr, job);
395 fileset = select_fs_resource(ua);
397 jcr->fileset = fileset;
402 client = select_client_resource(ua);
404 jcr->client = client;
410 if (!get_cmd(ua, _("Please enter the Bootstrap file name: "))) {
413 if (jcr->RestoreBootstrap) {
414 free(jcr->RestoreBootstrap);
415 jcr->RestoreBootstrap = NULL;
417 if (ua->cmd[0] != 0) {
418 jcr->RestoreBootstrap = bstrdup(ua->cmd);
419 fd = fopen(jcr->RestoreBootstrap, "r");
421 bsendmsg(ua, _("Warning cannot open %s: ERR=%s\n"),
422 jcr->RestoreBootstrap, strerror(errno));
423 free(jcr->RestoreBootstrap);
424 jcr->RestoreBootstrap = NULL;
432 if (!get_cmd(ua, _("Please enter path prefix (where) for restore: "))) {
435 /* ***FIXME*** allow drive:/ for Windows */
436 if (ua->cmd[0] != '/') {
437 bsendmsg(ua, _("Prefix must begin with a /\n"));
439 if (jcr->RestoreWhere) {
440 free(jcr->RestoreWhere);
442 jcr->RestoreWhere = bstrdup(ua->cmd);
447 jid = NULL; /* force reprompt */
448 jcr->RestoreJobId = 0;
449 if (jcr->RestoreBootstrap) {
450 bsendmsg(ua, _("You must set the bootstrap file to NULL to be able to specify a JobId.\n"));
456 bsendmsg(ua, _("Job not run.\n"));
458 return 0; /* error do no run Job */
460 if (strcasecmp(ua->cmd, _("yes")) != 0) {
461 bsendmsg(ua, _("Job not run.\n"));
463 return 0; /* do not run */
466 Dmsg1(200, "Calling run_job job=%x\n", jcr->job);