2 This patch should cause all Job Log records to be migrated when the
3 Job is migrated. It fixes the second issue reported in bug #1171.
5 Apply it to Bacula 2.4.3 (possibly earlier versions)
9 patch -p0 <2.4.3-migrate.patch
10 ./configure <your-options>
15 Index: src/dird/migrate.c
16 ===================================================================
17 --- src/dird/migrate.c (revision 7926)
18 +++ src/dird/migrate.c (working copy)
22 migration_cleanup(jcr, jcr->JobStatus);
25 - UAContext *ua = new_ua_context(jcr);
26 - edit_uint64(jcr->previous_jr.JobId, jobid);
27 - /* Purge all old file records, but leave Job record */
28 - purge_files_from_jobs(ua, jobid);
29 - free_ua_context(ua);
34 @@ -1087,11 +1079,26 @@
35 edit_uint64(mig_jcr->jr.JobId, ec2));
36 db_sql_query(mig_jcr->db, query.c_str(), NULL, NULL);
38 - /* Now mark the previous job as migrated if it terminated normally */
39 - if (jcr->JobStatus == JS_Terminated) {
41 + * If we terminated a migration normally:
42 + * - mark the previous job as migrated
43 + * - move any Log records to the new JobId
44 + * - Purge the File records from the previous job
46 + if (jcr->JobType == JT_MIGRATE && jcr->JobStatus == JS_Terminated) {
47 + char old_jobid[50], new_jobid[50];
48 Mmsg(query, "UPDATE Job SET Type='%c' WHERE JobId=%s",
49 - (char)JT_MIGRATED_JOB, edit_uint64(jcr->previous_jr.JobId, ec1));
50 + (char)JT_MIGRATED_JOB, edit_uint64(jcr->previous_jr.JobId, new_jobid));
51 db_sql_query(mig_jcr->db, query.c_str(), NULL, NULL);
52 + UAContext *ua = new_ua_context(jcr);
53 + /* Move JobLog to new JobId */
54 + Mmsg(query, "UPDATE Log SET JobId=%s WHERE JobId=%s",
56 + edit_uint64(jcr->previous_jr.JobId, old_jobid));
57 + db_sql_query(mig_jcr->db, query.c_str(), NULL, NULL);
58 + /* Purge all old file records, but leave Job record */
59 + purge_files_from_jobs(ua, old_jobid);
60 + free_ua_context(ua);
63 if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
65 set_jcr_job_status(jcr, JS_ErrorTerminated);
69 update_bootstrap_file(mig_jcr);
71 if (!db_get_job_volume_names(mig_jcr, mig_jcr->db, mig_jcr->jr.JobId, &mig_jcr->VolumeName)) {