* find last Job start time Incremental and Differential saves.
*
* StartTime is returned in stime
+ * Job name is returned in job (MAX_NAME_LENGTH)
*
* Returns: 0 on failure
- * 1 on success, jr is unchanged, but stime is set
+ * 1 on success, jr is unchanged, but stime and job are set
*/
bool
-db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime)
+db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, char *job)
{
SQL_ROW row;
char ed1[50], ed2[50];
+ char esc_name[MAX_ESCAPE_NAME_LENGTH];
db_lock(mdb);
-
+ mdb->db_escape_string(jcr, esc_name, jr->Name, strlen(jr->Name));
pm_strcpy(stime, "0000-00-00 00:00:00"); /* default */
+ job[0] = 0;
+
/* If no Id given, we must find corresponding job */
if (jr->JobId == 0) {
/* Differential is since last Full backup */
Mmsg(mdb->cmd,
-"SELECT StartTime FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND "
+"SELECT StartTime, Job FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND "
"Level='%c' AND Name='%s' AND ClientId=%s AND FileSetId=%s "
"ORDER BY StartTime DESC LIMIT 1",
- jr->JobType, L_FULL, jr->Name,
+ jr->JobType, L_FULL, esc_name,
edit_int64(jr->ClientId, ed1), edit_int64(jr->FileSetId, ed2));
if (jr->JobLevel == L_DIFFERENTIAL) {
sql_free_result(mdb);
/* Now edit SQL command for Incremental Job */
Mmsg(mdb->cmd,
-"SELECT StartTime FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND "
+"SELECT StartTime, Job FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND "
"Level IN ('%c','%c','%c') AND Name='%s' AND ClientId=%s "
"AND FileSetId=%s ORDER BY StartTime DESC LIMIT 1",
- jr->JobType, L_INCREMENTAL, L_DIFFERENTIAL, L_FULL, jr->Name,
+ jr->JobType, L_INCREMENTAL, L_DIFFERENTIAL, L_FULL, esc_name,
edit_int64(jr->ClientId, ed1), edit_int64(jr->FileSetId, ed2));
} else {
Mmsg1(mdb->errmsg, _("Unknown level=%d\n"), jr->JobLevel);
}
} else {
Dmsg1(100, "Submitting: %s\n", mdb->cmd);
- Mmsg(mdb->cmd, "SELECT StartTime FROM Job WHERE Job.JobId=%s",
+ Mmsg(mdb->cmd, "SELECT StartTime, Job FROM Job WHERE Job.JobId=%s",
edit_int64(jr->JobId, ed1));
}
sql_free_result(mdb);
goto bail_out;
}
- Dmsg1(100, "Got start time: %s\n", row[0]);
+ Dmsg2(100, "Got start time: %s, job: %s\n", row[0], row[1]);
pm_strcpy(stime, row[0]);
+ bstrncpy(job, row[1], MAX_NAME_LENGTH);
sql_free_result(mdb);
* Find the last job start time for the specified JobLevel
*
* StartTime is returned in stime
+ * Job name is returned in job (MAX_NAME_LENGTH)
*
* Returns: false on failure
- * true on success, jr is unchanged, but stime is set
+ * true on success, jr is unchanged, but stime and job are set
*/
bool
-db_find_last_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, int JobLevel)
+db_find_last_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr,
+ POOLMEM **stime, char *job, int JobLevel)
{
SQL_ROW row;
char ed1[50], ed2[50];
+ char esc_name[MAX_ESCAPE_NAME_LENGTH];
db_lock(mdb);
-
+ mdb->db_escape_string(jcr, esc_name, jr->Name, strlen(jr->Name));
pm_strcpy(stime, "0000-00-00 00:00:00"); /* default */
+ job[0] = 0;
Mmsg(mdb->cmd,
-"SELECT StartTime FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND "
+"SELECT StartTime, Job FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND "
"Level='%c' AND Name='%s' AND ClientId=%s AND FileSetId=%s "
"ORDER BY StartTime DESC LIMIT 1",
- jr->JobType, JobLevel, jr->Name,
+ jr->JobType, JobLevel, esc_name,
edit_int64(jr->ClientId, ed1), edit_int64(jr->FileSetId, ed2));
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
Mmsg2(&mdb->errmsg, _("Query error for start time request: ERR=%s\nCMD=%s\n"),
}
Dmsg1(100, "Got start time: %s\n", row[0]);
pm_strcpy(stime, row[0]);
+ bstrncpy(job, row[1], MAX_NAME_LENGTH);
+
sql_free_result(mdb);
db_unlock(mdb);
return true;
{
SQL_ROW row;
char ed1[50], ed2[50];
+ char esc_name[MAX_ESCAPE_NAME_LENGTH];
db_lock(mdb);
+ mdb->db_escape_string(jcr, esc_name, jr->Name, strlen(jr->Name));
+
/* Differential is since last Full backup */
Mmsg(mdb->cmd,
"SELECT Level FROM Job WHERE JobStatus NOT IN ('T','W') AND "
"Type='%c' AND Level IN ('%c','%c') AND Name='%s' AND ClientId=%s "
"AND FileSetId=%s AND StartTime>'%s' "
"ORDER BY StartTime DESC LIMIT 1",
- jr->JobType, L_FULL, L_DIFFERENTIAL, jr->Name,
+ jr->JobType, L_FULL, L_DIFFERENTIAL, esc_name,
edit_int64(jr->ClientId, ed1), edit_int64(jr->FileSetId, ed2),
stime);
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
{
SQL_ROW row;
char ed1[50];
+ char esc_name[MAX_ESCAPE_NAME_LENGTH];
- /* Find last full */
db_lock(mdb);
+ /* Find last full */
Dmsg2(100, "JobLevel=%d JobType=%d\n", jr->JobLevel, jr->JobType);
if (jr->JobLevel == L_VERIFY_CATALOG) {
+ mdb->db_escape_string(jcr, esc_name, jr->Name, strlen(jr->Name));
Mmsg(mdb->cmd,
"SELECT JobId FROM Job WHERE Type='V' AND Level='%c' AND "
" JobStatus IN ('T','W') AND Name='%s' AND "
"ClientId=%s ORDER BY StartTime DESC LIMIT 1",
- L_VERIFY_INIT, jr->Name,
+ L_VERIFY_INIT, esc_name,
edit_int64(jr->ClientId, ed1));
} else if (jr->JobLevel == L_VERIFY_VOLUME_TO_CATALOG ||
jr->JobLevel == L_VERIFY_DISK_TO_CATALOG ||
jr->JobType == JT_BACKUP) {
if (Name) {
+ mdb->db_escape_string(jcr, esc_name, (char*)Name,
+ MIN(strlen(Name), sizeof(esc_name)));
Mmsg(mdb->cmd,
"SELECT JobId FROM Job WHERE Type='B' AND JobStatus IN ('T','W') AND "
-"Name='%s' ORDER BY StartTime DESC LIMIT 1", Name);
+"Name='%s' ORDER BY StartTime DESC LIMIT 1", esc_name);
} else {
Mmsg(mdb->cmd,
"SELECT JobId FROM Job WHERE Type='B' AND JobStatus IN ('T','W') AND "
SQL_ROW row = NULL;
int numrows;
const char *order;
-
+ char esc_type[MAX_ESCAPE_NAME_LENGTH];
+ char esc_status[MAX_ESCAPE_NAME_LENGTH];
char ed1[50];
db_lock(mdb);
+ mdb->db_escape_string(jcr, esc_type, mr->MediaType, strlen(mr->MediaType));
+ mdb->db_escape_string(jcr, esc_status, mr->VolStatus, strlen(mr->VolStatus));
+
if (item == -1) { /* find oldest volume */
/* Find oldest volume */
Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolJobs,VolFiles,VolBlocks,"
"FROM Media WHERE PoolId=%s AND MediaType='%s' AND VolStatus IN ('Full',"
"'Recycle','Purged','Used','Append') AND Enabled=1 "
"ORDER BY LastWritten LIMIT 1",
- edit_int64(mr->PoolId, ed1), mr->MediaType);
+ edit_int64(mr->PoolId, ed1), esc_type);
item = 1;
} else {
POOL_MEM changer(PM_FNAME);
"AND VolStatus='%s' "
"%s "
"%s LIMIT %d",
- edit_int64(mr->PoolId, ed1), mr->MediaType,
- mr->VolStatus, changer.c_str(), order, item);
+ edit_int64(mr->PoolId, ed1), esc_type,
+ esc_status, changer.c_str(), order, item);
}
Dmsg1(050, "fnextvol=%s\n", mdb->cmd);
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {