*
* Kern Sibbald, March 2000
*
- * Version $Id$
+ * Version $Id: sql_get.c 8918 2009-06-23 11:56:35Z ricozz $
*/
/*
* Find the last "accurate" backup state (that can take deleted files in account)
- * 1) Get all files with jobid in list (F subquery)
+ * 1) Get all files with jobid in list (F subquery)
+ * Get all files in BaseFiles with jobid in list
* 2) Take only the last version of each file (Temp subquery) => accurate list is ok
* 3) Join the result to file table to get fileindex, jobid and lstat information
*
"SELECT Path.Path, Filename.Name, File.FileIndex, File.JobId, File.LStat "
"FROM ( "
"SELECT max(FileId) as FileId, PathId, FilenameId "
- "FROM (SELECT FileId, PathId, FilenameId FROM File WHERE JobId IN (%s)) AS F "
+ "FROM (SELECT FileId, PathId, FilenameId FROM File WHERE JobId IN (%s) "
+ "UNION "
+ "SELECT File.FileId, PathId, FilenameId "
+ "FROM BaseFiles JOIN File USING (FileId) "
+ "WHERE BaseFiles.JobId IN (%s) "
+ ") AS F "
"GROUP BY PathId, FilenameId "
") AS Temp "
"JOIN Filename ON (Filename.FilenameId = Temp.FilenameId) "
"JOIN Path ON (Path.PathId = Temp.PathId) "
"JOIN File ON (File.FileId = Temp.FileId) "
-"WHERE File.FileIndex > 0 ORDER BY JobId, FileIndex ASC", /* Return sorted by JobId, */
- /* FileIndex for restore code */
- jobids);
+"WHERE File.FileIndex > 0 ORDER BY JobId, FileIndex ASC",/* Return sorted by JobId, */
+ /* FileIndex for restore code */
+ jobids, jobids);
+ Dmsg1(0, "q=%s\n", buf.c_str());
#else
/*
* I am not sure that this works the same as the code in ua_restore.c
* Differential : get the last full id
* Incremental : get the last full + last diff + last incr(s) ids
*
+ * If you specify jr->StartTime, it will be used to limit the search
+ * in the time. (usually now)
+ *
* TODO: look and merge from ua_restore.c
*/
bool db_accurate_get_jobids(JCR *jcr, B_DB *mdb,
char clientid[50], jobid[50], filesetid[50];
char date[MAX_TIME_LENGTH];
POOL_MEM query(PM_FNAME);
- bstrutime(date, sizeof(date), jr->JobTDate + 1);
+
+ /* Take the current time as upper limit if nothing else specified */
+ utime_t StartTime = (jr->StartTime)?jr->StartTime:time(NULL);
+
+ bstrutime(date, sizeof(date), StartTime + 1);
jobids[0]='\0';
/* First, find the last good Full backup for this job/client/fileset */
return ret;
}
+bool db_get_base_jobid(JCR *jcr, B_DB *mdb, JOB_DBR *jr, JobId_t *jobid)
+{
+ char date[MAX_TIME_LENGTH];
+ int64_t id = *jobid = 0;
+ POOL_MEM query(PM_FNAME);
+
+// char clientid[50], filesetid[50];
+
+ utime_t StartTime = (jr->StartTime)?jr->StartTime:time(NULL);
+ bstrutime(date, sizeof(date), StartTime + 1);
+
+ /* we can take also client name, fileset, etc... */
+
+ Mmsg(query,
+ "SELECT JobId, Job, StartTime, EndTime, JobTDate, PurgedFiles "
+ "FROM Job "
+// "JOIN FileSet USING (FileSetId) JOIN Client USING (ClientId) "
+ "WHERE Job.Name = '%s' "
+ "AND Level='B' AND JobStatus IN ('T','W') AND Type='B' "
+// "AND FileSet.FileSet= '%s' "
+// "AND Client.Name = '%s' "
+ "AND StartTime<'%s' "
+ "ORDER BY Job.JobTDate DESC LIMIT 1",
+ jr->Name,
+// edit_uint64(jr->ClientId, clientid),
+// edit_uint64(jr->FileSetId, filesetid));
+ date);
+
+ Dmsg1(1, "db_get_base_jobid q=%s\n", query.c_str());
+ if (!db_sql_query(mdb, query.c_str(), db_int64_handler, &id)) {
+ goto bail_out;
+ }
+ *jobid = (JobId_t) id;
+
+ Dmsg1(1, "db_get_base_jobid=%lld\n", id);
+ return true;
+
+bail_out:
+ return false;
+}
+
/*
* Use to build a string of int list from a query. "10,20,30"
*/