Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
core: BareosDb::FindLastJobStartTimeForJobAndClient: take into accoun…
…t Running job

- Adding Created and Running jobs to the query will avoid the start
  of a second backup job for the same client while starttime is
  overdue.
  As we need to return a time_t and jobstatus = C doesn't have
  starttime set, now() is used with casting forced to expected
  timestamp without DST

Fix [BUG #1466]

Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
  • Loading branch information
bruno-at-bareos authored and pstorz committed Oct 28, 2022
1 parent dcc4830 commit 900f164
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions core/src/cats/sql_find.cc
Expand Up @@ -141,6 +141,19 @@ bool BareosDb::FindJobStartTime(JobControlRecord* jcr,
return true;
}

/**
* Find the last job start time for specified job and client
* used in RunOnIncomingConnectInterval.
*
* The tricky part is that we can have an actual job in state C not yet started
* this will return a starttime NULL due to following PostgreSQL rules.
*
* By default, null values sort as if larger than any non-null value; that is,
* NULLS FIRST is the default for DESC order, and NULLS LAST otherwise.
*
* To avoid this we use now()::timestamp. Casting is mandatory otherwise
* value has a DST.
*/
BareosDb::SqlFindResult BareosDb::FindLastJobStartTimeForJobAndClient(
JobControlRecord* jcr,
std::string job_basename,
Expand All @@ -161,10 +174,13 @@ BareosDb::SqlFindResult BareosDb::FindLastJobStartTimeForJobAndClient(
strcpy(stime_out.data(), default_time);

Mmsg(cmd,
"SELECT StartTime"
"SELECT "
" CASE WHEN StartTime is NULL THEN NOW()::timestamp "
" ELSE StartTime::timestamp "
"END"
" FROM Job"
" WHERE Job.Name='%s'"
" AND (Job.JobStatus='T' OR Job.JobStatus='W')"
" AND Job.JobStatus IN ('T','W','C','R')"
" AND Job.ClientId=(SELECT ClientId"
" FROM Client WHERE Client.Name='%s')"
" ORDER BY StartTime DESC LIMIT 1",
Expand Down

0 comments on commit 900f164

Please sign in to comment.