*
* Kern Sibbald, March 2000
*
- * Version $Id$
+ * Version $Id: sql_get.c 8918 2009-06-23 11:56:35Z ricozz $
*/
Mmsg(mdb->cmd,
"SELECT FileId, LStat, MD5 FROM File,Job WHERE "
"File.JobId=Job.JobId AND File.PathId=%s AND "
-"File.FilenameId=%s AND Job.Type='B' AND Job.JobStatus='T' AND "
+"File.FilenameId=%s AND Job.Type='B' AND Job.JobStatus IN ('T','W') AND "
"ClientId=%s ORDER BY StartTime DESC LIMIT 1",
edit_int64(fdbr->PathId, ed1),
edit_int64(fdbr->FilenameId, ed2),
Mmsg(mdb->cmd, "SELECT VolSessionId,VolSessionTime,"
"PoolId,StartTime,EndTime,JobFiles,JobBytes,JobTDate,Job,JobStatus,"
"Type,Level,ClientId,Name,PriorJobId,RealEndTime,JobId,FileSetId,"
-"SchedTime,RealEndTime "
+"SchedTime,RealEndTime,ReadBytes,HasBase "
"FROM Job WHERE Job='%s'", jr->Job);
} else {
Mmsg(mdb->cmd, "SELECT VolSessionId,VolSessionTime,"
"PoolId,StartTime,EndTime,JobFiles,JobBytes,JobTDate,Job,JobStatus,"
"Type,Level,ClientId,Name,PriorJobId,RealEndTime,JobId,FileSetId,"
-"SchedTime,RealEndTime "
+"SchedTime,RealEndTime,ReadBytes,HasBase "
"FROM Job WHERE JobId=%s",
edit_int64(jr->JobId, ed1));
}
jr->FileSetId = str_to_int64(row[17]);
bstrncpy(jr->cSchedTime, row[3]!=NULL?row[18]:"", sizeof(jr->cSchedTime));
bstrncpy(jr->cRealEndTime, row[3]!=NULL?row[19]:"", sizeof(jr->cRealEndTime));
+ jr->ReadBytes = str_to_int64(row[20]);
jr->StartTime = str_to_utime(jr->cStartTime);
jr->SchedTime = str_to_utime(jr->cSchedTime);
jr->EndTime = str_to_utime(jr->cEndTime);
jr->RealEndTime = str_to_utime(jr->cRealEndTime);
+ jr->HasBase = str_to_int64(row[21]);
sql_free_result(mdb);
db_unlock(mdb);
Mmsg(mdb->cmd,
"SELECT VolumeName,MediaType,FirstIndex,LastIndex,StartFile,"
"JobMedia.EndFile,StartBlock,JobMedia.EndBlock,Copy,"
-"Slot,StorageId"
+"Slot,StorageId,InChanger"
" FROM JobMedia,Media WHERE JobMedia.JobId=%s"
" AND JobMedia.MediaId=Media.MediaId ORDER BY VolIndex,JobMediaId",
edit_int64(JobId, ed1));
// Vols[i].Copy = str_to_uint64(row[8]);
Vols[i].Slot = str_to_uint64(row[9]);
StorageId = str_to_uint64(row[10]);
+ Vols[i].InChanger = str_to_uint64(row[11]);
Vols[i].Storage[0] = 0;
SId[i] = StorageId;
}
Mmsg(mdb->cmd,
"SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,"
"AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
-"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId FROM Pool WHERE Pool.PoolId=%s",
+"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId,ScratchPoolId FROM Pool WHERE Pool.PoolId=%s",
edit_int64(pdbr->PoolId, ed1));
} else { /* find by name */
Mmsg(mdb->cmd,
"SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,"
"AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
-"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId FROM Pool WHERE Pool.Name='%s'",
+"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId,ScratchPoolId FROM Pool WHERE Pool.Name='%s'",
pdbr->Name);
}
-
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 1) {
pdbr->LabelType = str_to_int64(row[15]);
bstrncpy(pdbr->LabelFormat, row[16]!=NULL?row[16]:"", sizeof(pdbr->LabelFormat));
pdbr->RecyclePoolId = str_to_int64(row[17]);
+ pdbr->ScratchPoolId = str_to_int64(row[18]);
ok = true;
}
}
/*
* 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);
#else
/*
* I am not sure that this works the same as the code in ua_restore.c
- * but it is very similar.
+ * but it is very similar. The accurate-test fails in a restore. Bad file count.
*/
Mmsg(buf, uar_sel_files, jobids);
#endif
return db_sql_query(mdb, buf.c_str(), result_handler, ctx);
}
+/*
+ * This procedure gets the base jobid list used by jobids,
+ * You can specify jobids == result to concat base jobids to current jobids
+ */
+bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, POOLMEM *result)
+{
+ POOL_MEM buf;
+ Mmsg(buf,
+ "SELECT DISTINCT BaseJobId "
+ " FROM Job JOIN BaseFiles USING (JobId) "
+ " WHERE Job.HasBase = 1 "
+ " AND JobId IN (%s) ", jobids);
+ return db_sql_query(mdb, buf.c_str(), db_get_int_handler, jobids);
+}
+
/* The decision do change an incr/diff was done before
* Full : do nothing
* 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), time(NULL) + 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 */
"SELECT JobId, StartTime, EndTime, JobTDate, PurgedFiles "
"FROM Job JOIN FileSet USING (FileSetId) "
"WHERE ClientId = %s "
- "AND Level='F' AND JobStatus='T' AND Type='B' "
+ "AND Level='F' AND JobStatus IN ('T','W') AND Type='B' "
"AND StartTime<'%s' "
"AND FileSet.FileSet=(SELECT FileSet FROM FileSet WHERE FileSetId = %s) "
"ORDER BY Job.JobTDate DESC LIMIT 1",
"SELECT JobId, StartTime, EndTime, JobTDate, PurgedFiles "
"FROM Job JOIN FileSet USING (FileSetId) "
"WHERE ClientId = %s "
- "AND Level='D' AND JobStatus='T' AND Type='B' "
+ "AND Level='D' AND JobStatus IN ('T','W') AND Type='B' "
"AND StartTime > (SELECT EndTime FROM btemp3%s ORDER BY EndTime DESC LIMIT 1) "
+ "AND StartTime < '%s' "
"AND FileSet.FileSet= (SELECT FileSet FROM FileSet WHERE FileSetId = %s) "
"ORDER BY Job.JobTDate DESC LIMIT 1 ",
jobid,
clientid,
jobid,
+ date,
filesetid);
if (!db_sql_query(mdb, query.c_str(), NULL, NULL)) {
"SELECT JobId, StartTime, EndTime, JobTDate, PurgedFiles "
"FROM Job JOIN FileSet USING (FileSetId) "
"WHERE ClientId = %s "
- "AND Level='I' AND JobStatus='T' AND Type='B' "
+ "AND Level='I' AND JobStatus IN ('T','W') AND Type='B' "
"AND StartTime > (SELECT EndTime FROM btemp3%s ORDER BY EndTime DESC LIMIT 1) "
+ "AND StartTime < '%s' "
"AND FileSet.FileSet= (SELECT FileSet FROM FileSet WHERE FileSetId = %s) "
"ORDER BY Job.JobTDate DESC ",
jobid,
clientid,
jobid,
+ date,
filesetid);
if (!db_sql_query(mdb, query.c_str(), NULL, NULL)) {
goto bail_out;
/* build a jobid list ie: 1,2,3,4 */
Mmsg(query, "SELECT JobId FROM btemp3%s ORDER by JobTDate", jobid);
db_sql_query(mdb, query.c_str(), db_get_int_handler, jobids);
- Dmsg1(1, "db_accurate_get_jobids=%s\n", jobids);
+ Dmsg1(10, "db_accurate_get_jobids=%s\n", jobids);
ret = true;
bail_out:
return ret;
}
+bool db_get_base_file_list(JCR *jcr, B_DB *mdb,
+ DB_RESULT_HANDLER *result_handler, void *ctx)
+{
+ POOL_MEM buf(PM_MESSAGE);
+
+ Mmsg(buf,
+ "SELECT Path, Name, FileIndex, JobId, LStat "
+ "FROM new_basefile%lld ORDER BY JobId, FileIndex ASC",
+ (uint64_t) jcr->JobId);
+
+ return db_sql_query(mdb, buf.c_str(), result_handler, ctx);
+}
+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(10, "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(10, "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"
*/