+ } else {
+ ua->send_msg(_("Run Restore job\n"
+ "JobName: %s\n"
+ "Bootstrap: %s\n"
+ "Where: %s\n"
+ "Replace: %s\n"
+ "FileSet: %s\n"
+ "Backup Client: %s\n"
+ "Restore Client: %s\n"
+ "Storage: %s\n"
+ "When: %s\n"
+ "Catalog: %s\n"
+ "Priority: %d\n"
+ "Plugin Options: %s\n"),
+ job->name(),
+ NPRT(jcr->RestoreBootstrap),
+ jcr->where?jcr->where:NPRT(job->RestoreWhere),
+ replace,
+ jcr->fileset->name(),
+ client_name,
+ jcr->client->name(),
+ jcr->rstore->name(),
+ bstrutime(dt, sizeof(dt), jcr->sched_time),
+ jcr->catalog->name(),
+ jcr->JobPriority,
+ NPRT(jcr->plugin_options));
+ }
+
+ } else {
+ if (ua->api) ua->signal(BNET_RUN_CMD);
+ ua->send_msg(_("Run Restore job\n"
+ "JobName: %s\n"
+ "Bootstrap: %s\n"),
+ job->name(),
+ NPRT(jcr->RestoreBootstrap));
+
+ /* RegexWhere is take before RestoreWhere */
+ if (jcr->RegexWhere || (job->RegexWhere && !jcr->where)) {
+ ua->send_msg(_("RegexWhere: %s\n"),
+ jcr->RegexWhere?jcr->RegexWhere:job->RegexWhere);
+ } else {
+ ua->send_msg(_("Where: %s\n"),
+ jcr->where?jcr->where:NPRT(job->RestoreWhere));
+ }
+
+ ua->send_msg(_("Replace: %s\n"
+ "Client: %s\n"
+ "Storage: %s\n"
+ "JobId: %s\n"
+ "When: %s\n"
+ "Catalog: %s\n"
+ "Priority: %d\n"
+ "Plugin Options: %s\n"),
+ replace,
+ jcr->client->name(),
+ jcr->rstore->name(),
+ jcr->RestoreJobId==0?"*None*":edit_uint64(jcr->RestoreJobId, ec1),
+ bstrutime(dt, sizeof(dt), jcr->sched_time),
+ jcr->catalog->name(),
+ jcr->JobPriority,
+ NPRT(jcr->plugin_options));
+ }
+ break;
+ case JT_COPY:
+ case JT_MIGRATE:
+ char *prt_type;
+ if (jcr->get_JobType() == JT_COPY) {
+ prt_type = _("Run Copy job\n");
+ } else {
+ prt_type = _("Run Migration job\n");
+ }
+ jcr->set_JobLevel(L_FULL); /* default level */
+ if (ua->api) ua->signal(BNET_RUN_CMD);
+ ua->send_msg("%s"
+ "JobName: %s\n"
+ "Bootstrap: %s\n"
+ "Client: %s\n"
+ "FileSet: %s\n"
+ "Pool: %s (From %s)\n"
+ "Read Storage: %s (From %s)\n"
+ "Write Storage: %s (From %s)\n"
+ "JobId: %s\n"
+ "When: %s\n"
+ "Catalog: %s\n"
+ "Priority: %d\n",
+ prt_type,
+ job->name(),
+ NPRT(jcr->RestoreBootstrap),
+ jcr->client->name(),
+ jcr->fileset->name(),
+ NPRT(jcr->pool->name()), jcr->pool_source,
+ jcr->rstore->name(), jcr->rstore_source,
+ jcr->wstore?jcr->wstore->name():"*None*", jcr->wstore_source,
+ jcr->MigrateJobId==0?"*None*":edit_uint64(jcr->MigrateJobId, ec1),
+ bstrutime(dt, sizeof(dt), jcr->sched_time),
+ jcr->catalog->name(),
+ jcr->JobPriority);
+ break;
+ default:
+ ua->error_msg(_("Unknown Job Type=%d\n"), jcr->get_JobType());
+ return false;
+ }
+ return true;
+}
+
+
+static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
+{
+ bool kw_ok;
+ int i, j;
+ static const char *kw[] = { /* command line arguments */
+ "job", /* Used in a switch() */
+ "jobid", /* 1 */
+ "client", /* 2 */
+ "fd",
+ "fileset", /* 4 */
+ "level", /* 5 */
+ "storage", /* 6 */
+ "sd", /* 7 */
+ "regexwhere", /* 8 where string as a bregexp */
+ "where", /* 9 */
+ "bootstrap", /* 10 */
+ "replace", /* 11 */
+ "when", /* 12 */
+ "priority", /* 13 */
+ "yes", /* 14 -- if you change this change YES_POS too */
+ "verifyjob", /* 15 */
+ "files", /* 16 number of files to restore */
+ "catalog", /* 17 override catalog */
+ "since", /* 18 since */
+ "cloned", /* 19 cloned */
+ "verifylist", /* 20 verify output list */
+ "migrationjob", /* 21 migration job name */
+ "pool", /* 22 */
+ "backupclient", /* 23 */
+ "restoreclient", /* 24 */
+ "pluginoptions", /* 25 */
+ "spooldata", /* 26 */
+ NULL};
+
+#define YES_POS 14
+
+ rc.catalog_name = NULL;
+ rc.job_name = NULL;
+ rc.pool_name = NULL;
+ rc.store_name = NULL;
+ rc.client_name = NULL;
+ rc.restore_client_name = NULL;
+ rc.fileset_name = NULL;
+ rc.verify_job_name = NULL;
+ rc.previous_job_name = NULL;
+ rc.spool_data_set = 0;
+
+
+ for (i=1; i<ua->argc; i++) {
+ Dmsg2(800, "Doing arg %d = %s\n", i, ua->argk[i]);
+ kw_ok = false;
+ /* Keep looking until we find a good keyword */
+ for (j=0; !kw_ok && kw[j]; j++) {
+ if (strcasecmp(ua->argk[i], kw[j]) == 0) {
+ /* Note, yes and run have no value, so do not fail */
+ if (!ua->argv[i] && j != YES_POS /*yes*/) {
+ ua->send_msg(_("Value missing for keyword %s\n"), ua->argk[i]);
+ return false;
+ }
+ Dmsg1(800, "Got keyword=%s\n", NPRT(kw[j]));
+ switch (j) {
+ case 0: /* job */
+ if (rc.job_name) {
+ ua->send_msg(_("Job name specified twice.\n"));
+ return false;
+ }
+ rc.job_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 1: /* JobId */
+ if (rc.jid && !rc.mod) {
+ ua->send_msg(_("JobId specified twice.\n"));
+ return false;
+ }
+ rc.jid = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 2: /* client */
+ case 3: /* fd */
+ if (rc.client_name) {
+ ua->send_msg(_("Client specified twice.\n"));
+ return false;
+ }
+ rc.client_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 4: /* fileset */
+ if (rc.fileset_name) {
+ ua->send_msg(_("FileSet specified twice.\n"));
+ return false;
+ }
+ rc.fileset_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 5: /* level */
+ if (rc.level_name) {
+ ua->send_msg(_("Level specified twice.\n"));
+ return false;
+ }
+ rc.level_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 6: /* storage */
+ case 7: /* sd */
+ if (rc.store_name) {
+ ua->send_msg(_("Storage specified twice.\n"));
+ return false;
+ }
+ rc.store_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 8: /* regexwhere */
+ if ((rc.regexwhere || rc.where) && !rc.mod) {
+ ua->send_msg(_("RegexWhere or Where specified twice.\n"));
+ return false;
+ }
+ rc.regexwhere = ua->argv[i];
+ if (!acl_access_ok(ua, Where_ACL, rc.regexwhere)) {
+ ua->send_msg(_("No authorization for \"regexwhere\" specification.\n"));
+ return false;
+ }
+ kw_ok = true;
+ break;
+ case 9: /* where */
+ if ((rc.where || rc.regexwhere) && !rc.mod) {
+ ua->send_msg(_("Where or RegexWhere specified twice.\n"));
+ return false;
+ }
+ rc.where = ua->argv[i];
+ if (!acl_access_ok(ua, Where_ACL, rc.where)) {
+ ua->send_msg(_("No authoriztion for \"where\" specification.\n"));
+ return false;
+ }
+ kw_ok = true;
+ break;
+ case 10: /* bootstrap */
+ if (rc.bootstrap && !rc.mod) {
+ ua->send_msg(_("Bootstrap specified twice.\n"));
+ return false;
+ }
+ rc.bootstrap = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 11: /* replace */
+ if (rc.replace && !rc.mod) {
+ ua->send_msg(_("Replace specified twice.\n"));
+ return false;
+ }
+ rc.replace = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 12: /* When */
+ if (rc.when && !rc.mod) {
+ ua->send_msg(_("When specified twice.\n"));
+ return false;
+ }
+ rc.when = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 13: /* Priority */
+ if (rc.Priority && !rc.mod) {
+ ua->send_msg(_("Priority specified twice.\n"));
+ return false;
+ }
+ rc.Priority = atoi(ua->argv[i]);
+ if (rc.Priority <= 0) {
+ ua->send_msg(_("Priority must be positive nonzero setting it to 10.\n"));
+ rc.Priority = 10;
+ }
+ kw_ok = true;
+ break;
+ case 14: /* yes */
+ kw_ok = true;
+ break;
+ case 15: /* Verify Job */
+ if (rc.verify_job_name) {
+ ua->send_msg(_("Verify Job specified twice.\n"));
+ return false;
+ }
+ rc.verify_job_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 16: /* files */
+ rc.files = atoi(ua->argv[i]);
+ kw_ok = true;
+ break;
+
+ case 17: /* catalog */
+ rc.catalog_name = ua->argv[i];
+ kw_ok = true;
+ break;
+
+ case 18: /* since */
+ rc.since = ua->argv[i];
+ kw_ok = true;
+ break;
+
+ case 19: /* cloned */
+ rc. cloned = true;
+ kw_ok = true;
+ break;
+
+ case 20: /* write verify list output */
+ rc.verify_list = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 21: /* Migration Job */
+ if (rc.previous_job_name) {
+ ua->send_msg(_("Migration Job specified twice.\n"));
+ return false;
+ }
+ rc.previous_job_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 22: /* pool */
+ if (rc.pool_name) {
+ ua->send_msg(_("Pool specified twice.\n"));
+ return false;
+ }
+ rc.pool_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 23: /* backupclient */
+ if (rc.client_name) {
+ ua->send_msg(_("Client specified twice.\n"));
+ return 0;
+ }
+ rc.client_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 24: /* restoreclient */
+ if (rc.restore_client_name && !rc.mod) {
+ ua->send_msg(_("Restore Client specified twice.\n"));
+ return false;
+ }
+ rc.restore_client_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 25: /* pluginoptions */
+ if (rc.plugin_options) {
+ ua->send_msg(_("Plugin Options specified twice.\n"));
+ return false;
+ }
+ rc.plugin_options = ua->argv[i];
+ if (!acl_access_ok(ua, PluginOptions_ACL, rc.plugin_options)) {
+ ua->send_msg(_("No authoriztion for \"PluginOptions\" specification.\n"));
+ return false;
+ }
+ kw_ok = true;
+ break;
+ case 26: /* spooldata */
+ if (rc.spool_data_set) {
+ ua->send_msg(_("Spool flag specified twice.\n"));
+ return false;
+ }
+ if (is_yesno(ua->argv[i], &rc.spool_data)) {
+ rc.spool_data_set = 1;
+ kw_ok = true;
+ } else {
+ ua->send_msg(_("Invalid spooldata flag.\n"));
+ }
+ break;
+ default:
+ break;
+ }
+ } /* end strcase compare */
+ } /* end keyword loop */
+ /*
+ * End of keyword for loop -- if not found, we got a bogus keyword
+ */
+ if (!kw_ok) {
+ Dmsg1(800, "%s not found\n", ua->argk[i]);
+ /*
+ * Special case for Job Name, it can be the first
+ * keyword that has no value.
+ */
+ if (!rc.job_name && !ua->argv[i]) {
+ rc.job_name = ua->argk[i]; /* use keyword as job name */
+ Dmsg1(800, "Set jobname=%s\n", rc.job_name);
+ } else {
+ ua->send_msg(_("Invalid keyword: %s\n"), ua->argk[i]);
+ return false;
+ }
+ }
+ } /* end argc loop */
+
+ Dmsg0(800, "Done scan.\n");
+
+ if (rc.catalog_name) {
+ rc.catalog = GetCatalogResWithName(rc.catalog_name);
+ if (rc.catalog == NULL) {
+ ua->error_msg(_("Catalog \"%s\" not found\n"), rc.catalog_name);
+ return false;
+ }
+ if (!acl_access_ok(ua, Catalog_ACL, rc.catalog->name())) {
+ ua->error_msg(_("No authorization. Catalog \"%s\".\n"), rc.catalog->name());
+ return false;
+ }
+ }
+ Dmsg1(800, "Using catalog=%s\n", NPRT(rc.catalog_name));
+
+ if (rc.job_name) {
+ /* Find Job */
+ rc.job = GetJobResWithName(rc.job_name);
+ if (!rc.job) {
+ if (*rc.job_name != 0) {
+ ua->send_msg(_("Job \"%s\" not found\n"), rc.job_name);
+ }
+ rc.job = select_job_resource(ua);
+ } else {
+ Dmsg1(800, "Found job=%s\n", rc.job_name);
+ }
+ } else if (!rc.job) {
+ ua->send_msg(_("A job name must be specified.\n"));
+ rc.job = select_job_resource(ua);
+ }
+ if (!rc.job) {
+ return false;
+ } else if (!acl_access_ok(ua, Job_ACL, rc.job->name())) {
+ ua->error_msg( _("No authorization. Job \"%s\".\n"), rc.job->name());
+ return false;
+ }
+
+ if (rc.pool_name) {
+ rc.pool = GetPoolResWithName(rc.pool_name);
+ if (!rc.pool) {
+ if (*rc.pool_name != 0) {
+ ua->warning_msg(_("Pool \"%s\" not found.\n"), rc.pool_name);
+ }
+ rc.pool = select_pool_resource(ua);
+ }
+ } else if (!rc.pool) {
+ rc.pool = rc.job->pool; /* use default */
+ }
+ if (!rc.pool) {
+ return false;
+ } else if (!acl_access_ok(ua, Pool_ACL, rc.pool->name())) {
+ ua->error_msg(_("No authorization. Pool \"%s\".\n"), rc.pool->name());
+ return false;
+ }
+ Dmsg1(100, "Using pool %s\n", rc.pool->name());
+
+ if (rc.spool_data_set) {
+ rc.job->spool_data = rc.spool_data;
+ }
+ Dmsg1(900, "Spooling data: %s\n", (rc.job->spool_data ? "Yes" : "No"));
+
+ if (rc.store_name) {
+ rc.store->store = GetStoreResWithName(rc.store_name);
+ pm_strcpy(rc.store->store_source, _("command line"));
+ if (!rc.store->store) {
+ if (*rc.store_name != 0) {
+ ua->warning_msg(_("Storage \"%s\" not found.\n"), rc.store_name);
+ }
+ rc.store->store = select_storage_resource(ua);
+ pm_strcpy(rc.store->store_source, _("user selection"));
+ }
+ } else if (!rc.store->store) {
+ get_job_storage(rc.store, rc.job, NULL); /* use default */
+ }
+ if (!rc.store->store) {
+ ua->error_msg(_("No storage specified.\n"));
+ return false;
+ } else if (!acl_access_ok(ua, Storage_ACL, rc.store->store->name())) {
+ ua->error_msg(_("No authorization. Storage \"%s\".\n"),
+ rc.store->store->name());
+ return false;
+ }
+ Dmsg1(800, "Using storage=%s\n", rc.store->store->name());
+
+ if (rc.client_name) {
+ rc.client = GetClientResWithName(rc.client_name);
+ if (!rc.client) {
+ if (*rc.client_name != 0) {
+ ua->warning_msg(_("Client \"%s\" not found.\n"), rc.client_name);
+ }
+ rc.client = select_client_resource(ua);
+ }
+ } else if (!rc.client) {
+ rc.client = rc.job->client; /* use default */
+ }
+ if (!rc.client) {
+ return false;
+ } else if (!acl_access_ok(ua, Client_ACL, rc.client->name())) {
+ ua->error_msg(_("No authorization. Client \"%s\".\n"),
+ rc.client->name());
+ return false;
+ }
+ Dmsg1(800, "Using client=%s\n", rc.client->name());
+
+ if (rc.restore_client_name) {
+ rc.client = GetClientResWithName(rc.restore_client_name);
+ if (!rc.client) {
+ if (*rc.restore_client_name != 0) {
+ ua->warning_msg(_("Restore Client \"%s\" not found.\n"), rc.restore_client_name);
+ }
+ rc.client = select_client_resource(ua);
+ }
+ } else if (!rc.client) {
+ rc.client = rc.job->client; /* use default */
+ }
+ if (!rc.client) {
+ return false;
+ } else if (!acl_access_ok(ua, Client_ACL, rc.client->name())) {
+ ua->error_msg(_("No authorization. Client \"%s\".\n"),
+ rc.client->name());
+ return false;
+ }
+ Dmsg1(800, "Using restore client=%s\n", rc.client->name());
+
+
+ if (rc.fileset_name) {
+ rc.fileset = GetFileSetResWithName(rc.fileset_name);
+ if (!rc.fileset) {
+ ua->send_msg(_("FileSet \"%s\" not found.\n"), rc.fileset_name);
+ rc.fileset = select_fileset_resource(ua);
+ }
+ } else if (!rc.fileset) {
+ rc.fileset = rc.job->fileset; /* use default */
+ }
+ if (!rc.fileset) {
+ return false;
+ } else if (!acl_access_ok(ua, FileSet_ACL, rc.fileset->name())) {
+ ua->send_msg(_("No authorization. FileSet \"%s\".\n"),
+ rc.fileset->name());
+ return false;
+ }
+
+ if (rc.verify_job_name) {
+ rc.verify_job = GetJobResWithName(rc.verify_job_name);
+ if (!rc.verify_job) {
+ ua->send_msg(_("Verify Job \"%s\" not found.\n"), rc.verify_job_name);
+ rc.verify_job = select_job_resource(ua);
+ }
+ } else if (!rc.verify_job) {
+ rc.verify_job = rc.job->verify_job;
+ }
+
+ if (rc.previous_job_name) {
+ rc.previous_job = GetJobResWithName(rc.previous_job_name);
+ if (!rc.previous_job) {
+ ua->send_msg(_("Migration Job \"%s\" not found.\n"), rc.previous_job_name);
+ rc.previous_job = select_job_resource(ua);
+ }
+ } else {
+ rc.previous_job = rc.job->verify_job;
+ }
+ return true;