3 * Bacula Director -- Run Command
5 * Kern Sibbald, December MMI
9 Copyright (C) 2001, 2002 Kern Sibbald and John Walker
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of
14 the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public
22 License along with this program; if not, write to the Free
23 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32 /* Imported subroutines */
33 extern void run_job(JCR *jcr);
35 /* Imported variables */
36 extern struct s_jl joblevels[];
39 * For Backup and Verify Jobs
40 * run [job=]<job-name> level=<level-name>
43 * run <job-name> jobid=nn
46 int runcmd(UAContext *ua, char *cmd)
50 char *job_name, *level_name, *jid, *store_name;
51 char *where, *fileset_name, *client_name;
78 Dmsg1(20, "run: %s\n", ua->UA_sock->msg);
80 for (i=1; i<ua->argc; i++) {
82 Dmsg2(200, "Doing arg %d = %s\n", i, ua->argk[i]);
83 for (j=0; kw[j]; j++) {
84 if (strcasecmp(ua->argk[i], _(kw[j])) == 0) {
86 bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
89 Dmsg1(200, "Got keyword=%s\n", kw[j]);
93 bsendmsg(ua, _("Job name specified twice.\n"));
96 job_name = ua->argv[i];
101 bsendmsg(ua, _("JobId specified twice.\n"));
109 bsendmsg(ua, _("Client specified twice.\n"));
112 client_name = ua->argv[i];
115 case 3: /* fileset */
117 bsendmsg(ua, _("FileSet specified twice.\n"));
120 fileset_name = ua->argv[i];
125 bsendmsg(ua, _("Level specified twice.\n"));
128 level_name = ua->argv[i];
131 case 5: /* storage */
133 bsendmsg(ua, _("Storage specified twice.\n"));
136 store_name = ua->argv[i];
141 bsendmsg(ua, _("Where specified twice.\n"));
151 } /* end keyword loop */
153 Dmsg1(200, "%s not found\n", ua->argk[i]);
155 * Special case for Job Name, it can be the first
156 * keyword that has no value.
158 if (!job_name && !ua->argv[i]) {
159 job_name = ua->argk[i]; /* use keyword as job name */
160 Dmsg1(200, "Set jobname=%s\n", job_name);
162 bsendmsg(ua, _("Invalid keyword %s\n"), ua->argk[i]);
166 } /* end argc loop */
168 Dmsg0(20, "Done scan.\n");
171 job = (JOB *)GetResWithName(R_JOB, job_name);
173 bsendmsg(ua, _("Job %s: not found\n"), job_name);
174 job = select_job_resource(ua);
176 Dmsg1(20, "Found job=%s\n", job_name);
179 bsendmsg(ua, _("A job name must be specified.\n"));
180 job = select_job_resource(ua);
187 store = (STORE *)GetResWithName(R_STORAGE, store_name);
189 bsendmsg(ua, _("Storage %s not found.\n"), store_name);
190 store = select_storage_resource(ua);
193 store = job->storage; /* use default */
199 jcr = new_jcr(sizeof(JCR), dird_free_jcr);
200 set_jcr_defaults(jcr, job);
201 jcr->store = store; /* set possible new Storage */
204 Dmsg1(20, "JobType=%c\n", jcr->JobType);
205 switch (jcr->JobType) {
209 /* Look up level name and pull code */
212 for (i=0; joblevels[i].level_name; i++) {
213 if (strcasecmp(level_name, _(joblevels[i].level_name)) == 0) {
214 jcr->level = joblevels[i].level;
220 bsendmsg(ua, _("Level %s not valid.\n"), level_name);
226 bsendmsg(ua, _("Run %s job\n\
232 jcr->JobType==JT_BACKUP?_("Backup"):_("Verify"),
234 jcr->fileset->hdr.name,
235 level_to_str(jcr->level),
236 jcr->client->hdr.name,
237 jcr->store->hdr.name);
240 if (jcr->RestoreJobId == 0) {
242 jcr->RestoreJobId = atoi(jid);
244 if (!get_cmd(ua, _("Please enter a JobId for restore: "))) {
248 jcr->RestoreJobId = atoi(ua->cmd);
251 jcr->level = 'F'; /* ***FIXME*** */
252 Dmsg1(20, "JobId to restore=%d\n", jcr->RestoreJobId);
253 bsendmsg(ua, _("Run Restore job\n\
262 jcr->RestoreWhere?jcr->RestoreWhere:job->RestoreWhere,
264 level_to_str(jcr->level),
265 jcr->fileset->hdr.name,
266 jcr->client->hdr.name,
267 jcr->store->hdr.name);
270 bsendmsg(ua, _("Unknown Job Type=%d\n"), jcr->JobType);
274 if (!get_cmd(ua, _("OK to run? (yes/mod/no): "))) {
278 if (strcasecmp(ua->cmd, _("mod")) == 0) {
279 start_prompt(ua, _("Parameters to modify:\n"));
280 add_prompt(ua, _("Job"));
281 add_prompt(ua, _("Level"));
282 add_prompt(ua, _("FileSet"));
283 add_prompt(ua, _("Client"));
284 add_prompt(ua, _("Storage"));
285 if (jcr->JobType == JT_RESTORE) {
286 add_prompt(ua, _("Where"));
287 add_prompt(ua, _("JobId"));
289 switch (do_prompt(ua, _("Select parameter to modify"), NULL)) {
292 job = select_job_resource(ua);
295 set_jcr_defaults(jcr, job);
301 if (jcr->JobType == JT_BACKUP) {
302 start_prompt(ua, _("Levels:\n"));
303 add_prompt(ua, _("Full"));
304 add_prompt(ua, _("Incremental"));
305 add_prompt(ua, _("Differential"));
306 add_prompt(ua, _("Level"));
307 add_prompt(ua, _("Since"));
308 switch (do_prompt(ua, _("Select level"), NULL)) {
313 jcr->level = L_INCREMENTAL;
316 jcr->level = L_DIFFERENTIAL;
319 jcr->level = L_LEVEL;
322 jcr->level = L_SINCE;
328 } else if (jcr->JobType == JT_VERIFY) {
329 start_prompt(ua, _("Levels:\n"));
330 add_prompt(ua, _("Initialize Catalog"));
331 add_prompt(ua, _("Verify from Catalog"));
332 add_prompt(ua, _("Verify Volume"));
333 add_prompt(ua, _("Verify Volume Data"));
334 switch (do_prompt(ua, _("Select level"), NULL)) {
336 jcr->level = L_VERIFY_INIT;
339 jcr->level = L_VERIFY_CATALOG;
342 jcr->level = L_VERIFY_VOLUME;
345 jcr->level = L_VERIFY_DATA;
355 fileset = select_fs_resource(ua);
357 jcr->fileset = fileset;
362 client = select_client_resource(ua);
364 jcr->client = client;
369 store = select_storage_resource(ua);
377 if (!get_cmd(ua, _("Please enter path prefix (where) for restore: "))) {
380 if (ua->cmd[0] != '/') {
381 bsendmsg(ua, _("Prefix must begin with a /\n"));
383 if (jcr->RestoreWhere) {
384 free(jcr->RestoreWhere);
386 jcr->RestoreWhere = bstrdup(ua->cmd);
391 jid = NULL; /* force reprompt */
392 jcr->RestoreJobId = 0;
397 bsendmsg(ua, _("Job not run.\n"));
401 if (strcasecmp(ua->cmd, _("yes")) != 0) {
402 bsendmsg(ua, _("Job not run.\n"));
407 Dmsg1(200, "Calling run_job job=%x\n", jcr->job);