--- /dev/null
+
+ This patch can be applied to version 3.0.1 and should improve
+ error messages when a migration sql query is used and correct
+ the problem identified in bug #1303 with starting Job names
+ containing spaces.
+
+ Apply it to version 3.0.1 with:
+
+ cd <bacula-source>
+ patch -p0 <3.0.1-migrate-sql.patch
+ ./configure <your-options>
+ make
+ ...
+ make install
+
+
+
+Index: src/dird/migrate.c
+===================================================================
+--- src/dird/migrate.c (revision 8887)
++++ src/dird/migrate.c (working copy)
+@@ -481,6 +481,12 @@
+ {
+ idpkt *ids = (idpkt *)ctx;
+
++ /* Sanity check */
++ if (!row || !row[0]) {
++ Dmsg0(dbglevel, "dbid_hdlr error empty row\n");
++ return 1; /* stop calling us */
++ }
++
+ add_unique_id(ids, row[0]);
+ Dmsg3(dbglevel, "dbid_hdlr count=%d Ids=%p %s\n", ids->count, ids->list, ids->list);
+ return 0;
+@@ -847,9 +853,6 @@
+ JobId = 0;
+ stat = get_next_jobid_from_list(&p, &JobId);
+ Dmsg3(dbglevel, "get_jobid_no=%d stat=%d JobId=%u\n", i, stat, JobId);
+- jcr->MigrateJobId = JobId;
+- start_migration_job(jcr);
+- Dmsg0(dbglevel, "Back from start_migration_job\n");
+ if (stat < 0) {
+ Jmsg(jcr, M_FATAL, 0, _("Invalid JobId found.\n"));
+ goto bail_out;
+@@ -857,6 +860,9 @@
+ Jmsg(jcr, M_INFO, 0, _("No JobIds found to %s.\n"), jcr->get_ActionName(0));
+ goto ok_out;
+ }
++ jcr->MigrateJobId = JobId;
++ start_migration_job(jcr);
++ Dmsg0(dbglevel, "Back from start_migration_job\n");
+ }
+
+ /* Now get the last JobId and handle it in the current job */
+@@ -908,7 +914,7 @@
+ UAContext *ua = new_ua_context(jcr);
+ char ed1[50];
+ ua->batch = true;
+- Mmsg(ua->cmd, "run %s jobid=%s", jcr->job->hdr.name,
++ Mmsg(ua->cmd, "run job=\"%s\" jobid=%s", jcr->job->name(),
+ edit_uint64(jcr->MigrateJobId, ed1));
+ Dmsg2(dbglevel, "=============== %s cmd=%s\n", jcr->get_OperationName(), ua->cmd);
+ parse_ua_args(ua); /* parse command */