/* Job needs to be marked as terminated before running the after runscript */
jcr->setJobStatus(TermCode);
- run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+ run_scripts(jcr, jcr->job->RunScripts, "EndJob");
/* Runscript could have changed JobStatus,
* now check if it should be changed in the report or not */
/* Job needs to be marked as terminated before running the after runscript */
jcr->setJobStatus(TermCode);
- run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+ run_scripts(jcr, jcr->job->RunScripts, "EndJob");
/* Runscript could have changed JobStatus,
* now check if it should be changed in the report or not */
*(uint32_t *)(item->value) = SCRIPT_AfterVSS;
} else if (strcasecmp(lc->str, "aftersnapshot") == 0) {
*(uint32_t *)(item->value) = SCRIPT_AfterVSS;
+ } else if (strcasecmp(lc->str, "endjob") == 0) {
+ *(uint32_t *)(item->value) = SCRIPT_EndJob;
} else if (strcasecmp(lc->str, "always") == 0) {
*(uint32_t *)(item->value) = SCRIPT_Any;
} else {
- scan_err2(lc, _("Expect %s, got: %s"), "Before, After, AfterVSS or Always", lc->str);
+ scan_err2(lc, _("Expect %s, got: %s"), "Before, EndJob, After, AfterVSS or Always", lc->str);
}
scan_to_eol(lc);
}
result = send_runscript_with_old_proto(jcr, cmd->when, msg);
} else {
+ /* On the FileDaemon, EndJob is a synonym of After */
+ cmd->when = (cmd->when == SCRIPT_EndJob) ? SCRIPT_After : cmd->when;
fd->fsend(runscript, cmd->on_success,
cmd->on_failure,
cmd->fail_on_error,
break;
}
+ run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+
/* Send off any queued messages */
if (jcr->msg_queue && jcr->msg_queue->size() > 0) {
dequeue_messages(jcr);
db_sql_query(wjcr->db, query.c_str(), NULL, NULL);
}
}
- run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+ run_scripts(jcr, jcr->job->RunScripts, "EndJob");
/* Runscript could have changed JobStatus,
* now check if it should be changed in the report or not */
/* Job needs to be marked as terminated before running the after runscript */
jcr->setJobStatus(TermCode);
- run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+ run_scripts(jcr, jcr->job->RunScripts, "EndJob");
/* Runscript could have changed JobStatus,
* now check if it should be changed in the report or not */
/* Job needs to be marked as terminated before running the after runscript */
jcr->setJobStatus(TermCode);
- run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+ run_scripts(jcr, jcr->job->RunScripts, "EndJob");
/* Runscript could have changed JobStatus,
* now check if it should be changed in the report or not */
/* Job needs to be marked as terminated before running the after runscript */
jcr->setJobStatus(TermCode);
- run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+ run_scripts(jcr, jcr->job->RunScripts, "EndJob");
/* Runscript could have changed JobStatus,
* now check if it should be changed in the report or not */
#define JS_CloudUpload 'u' /* Cloud upload */
#define JS_CloudDownload 'w' /* Cloud download */
-/* Helper for more descriptive job status */
+/* Helper for more descriptive job status
+ * Edit jcr.c as well for the string mapping
+ */
enum {
JOB_TASK_ZERO = 0,
JOB_TASK_BEFORE_SCRIPT = 100,
+ JOB_TASK_ENDJOB_SCRIPT,
JOB_TASK_AFTER_SCRIPT
};
/* Mapping of operation code to operation description */
const struct job_task job_task_map[] = {
- { JOB_TASK_ZERO, "\0" },
- { JOB_TASK_BEFORE_SCRIPT, "executing Before Job Scripts" },
- { JOB_TASK_AFTER_SCRIPT, "executing After Job Scripts" }
+ { JOB_TASK_ZERO, "" },
+ { JOB_TASK_BEFORE_SCRIPT, _("executing Before Job Scripts") },
+ { JOB_TASK_ENDJOB_SCRIPT, _("executing End Job Scripts") },
+ { JOB_TASK_AFTER_SCRIPT, _("executing After Job Scripts") }
};
const uint32_t job_task_map_size = sizeof(job_task_map) / sizeof(job_task);
when = SCRIPT_Before;
} else if (bstrcmp(label, NT_("ClientAfterVSS"))) {
when = SCRIPT_AfterVSS;
+ } else if (bstrcmp(label, NT_("EndJob"))) {
+ when = SCRIPT_EndJob;
} else {
when = SCRIPT_After;
}
}
}
+ if ((script->when & SCRIPT_EndJob) && (when & SCRIPT_EndJob)) {
+ Dmsg1(0, "EndJob jobstatus=%c\n", jcr->JobStatus);
+ if ((script->on_success &&
+ (jcr->JobStatus == JS_Terminated || jcr->JobStatus == JS_Warnings))
+ || (script->on_failure &&
+ (job_canceled(jcr) || jcr->JobStatus == JS_Differences))
+ )
+ {
+ Dmsg4(200, "runscript: Run it because SCRIPT_EndJob (%s,%i,%i,%c)\n",
+ script->command, script->on_success, script->on_failure,
+ jcr->JobStatus );
+ /* Set job task code */
+ jcr->job_task = JOB_TASK_ENDJOB_SCRIPT;
+ runit = true;
+ }
+ }
+
if ((script->when & SCRIPT_After) && (when & SCRIPT_After)) {
if ((script->on_success &&
(jcr->JobStatus == JS_Terminated || jcr->JobStatus == JS_Warnings))
SCRIPT_After = (1<<0), /* AfterJob */
SCRIPT_Before = (1<<1), /* BeforeJob */
SCRIPT_AfterVSS = (1<<2), /* BeforeJob and After VSS */
+ SCRIPT_EndJob = (1<<3), /* Before AfterJob on the Director, take status in account */
SCRIPT_Any = SCRIPT_Before | SCRIPT_After
};