#include "bacula.h"
#include "cats.h"
+
+/* For sql_update.c db_update_stats */
+const char *fill_jobhisto =
+ "INSERT INTO JobHisto ("
+ "JobId, Job, Name, Type, Level, ClientId, JobStatus, "
+ "SchedTime, StartTime, EndTime, RealEndTime, JobTDate, "
+ "VolSessionId, VolSessionTime, JobFiles, JobBytes, ReadBytes, "
+ "JobErrors, JobMissingFiles, PoolId, FileSetId, PriorJobId, "
+ "PurgedFiles, HasBase ) "
+ "SELECT "
+ "JobId, Job, Name, Type, Level, ClientId, JobStatus, "
+ "SchedTime, StartTime, EndTime, RealEndTime, JobTDate, "
+ "VolSessionId, VolSessionTime, JobFiles, JobBytes, ReadBytes, "
+ "JobErrors, JobMissingFiles, PoolId, FileSetId, PriorJobId, "
+ "PurgedFiles, HasBase "
+ "FROM Job "
+ "WHERE JobStatus IN ('T','W','f','A','E') "
+ "AND JobId NOT IN (SELECT JobId FROM JobHisto) "
+ "AND JobTDate < %s ";
+
/* For ua_update.c */
const char *list_pool = "SELECT * FROM Pool WHERE PoolId=%s";
" WHERE Client.Name='%s'"
" AND FileSet='%s'"
" AND Client.ClientId=Job.ClientId"
- " AND JobStatus='T' AND Type='B'"
+ " AND JobStatus IN ('T','W') AND Type='B'"
" AND JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId"
" AND Job.FileSetId=FileSet.FileSetId"
" ORDER BY Job.StartTime";
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
"WHERE (Job.JobTDate<%s AND ((DelCandidates.JobFiles=0) OR "
- "(DelCandidates.JobStatus!='T'))) OR "
+ "(DelCandidates.JobStatus NOT IN ('T','W')))) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
- "AND Job.Level='F' AND Job.JobStatus='T' AND Job.Type IN ('B','M') "
+ "AND Job.Level='F' AND Job.JobStatus IN ('T','W') AND Job.Type IN ('B','M') "
"AND Job.FileSetId=DelCandidates.FileSetId)";
/* Select Jobs from the DelCandidates table that have a
const char *select_verify_del =
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
- "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR "
+ "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
- "AND Job.Type='V' AND Job.Level='V' AND Job.JobStatus='T' "
+ "AND Job.Type='V' AND Job.Level='V' AND Job.JobStatus IN ('T','W') "
"AND Job.FileSetId=DelCandidates.FileSetId)";
const char *select_restore_del =
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
- "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR "
+ "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
"AND Job.Type='R')";
const char *select_admin_del =
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
- "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR "
+ "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
"AND Job.Type='D')";
const char *select_migrate_del =
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
- "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR "
+ "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
"AND Job.Type='g')";
const char *select_copy_del =
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
- "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR "
+ "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
"AND Job.Type='C')";
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
"WHERE (Job.JobId=DelCandidates.JobId AND ((DelCandidates.JobFiles=0) OR "
- "(DelCandidates.JobStatus!='T'))) OR "
+ "(DelCandidates.JobStatus NOT IN ('T','W')))) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
- "AND Job.Level='F' AND Job.JobStatus='T' AND Job.Type IN ('B','M') "
+ "AND Job.Level='F' AND Job.JobStatus IN ('T','W') AND Job.Type IN ('B','M') "
"AND Job.FileSetId=DelCandidates.FileSetId)";
/* Select Jobs from the DelCandidates table that have a
const char *select_verify_del =
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
- "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus!='T') OR "
+ "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
- "AND Job.Type='V' AND Job.Level='V' AND Job.JobStatus='T' "
+ "AND Job.Type='V' AND Job.Level='V' AND Job.JobStatus IN ('T','W') "
"AND Job.FileSetId=DelCandidates.FileSetId)";
const char *select_restore_del =
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
- "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus!='T') OR "
+ "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
"AND Job.Type='R')";
const char *select_admin_del =
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
- "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus!='T') OR "
+ "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
"AND Job.Type='D')";
const char *select_migrate_del =
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
- "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus!='T') OR "
+ "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
"AND Job.Type='g')";
const char *select_copy_del =
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
- "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus!='T') OR "
+ "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
"(Job.JobTDate>%s "
"AND Job.ClientId=%s "
"AND Job.Type='C')";
const char *uar_list_jobs =
"SELECT JobId,Client.Name as Client,StartTime,Level as "
"JobLevel,JobFiles,JobBytes "
- "FROM Client,Job WHERE Client.ClientId=Job.ClientId AND JobStatus='T' "
+ "FROM Client,Job WHERE Client.ClientId=Job.ClientId AND JobStatus IN ('T','W') "
"AND Type='B' ORDER BY StartTime DESC LIMIT 20";
/*
"FROM Client,Job,JobMedia,Media,FileSet WHERE Client.ClientId=%s "
"AND Job.ClientId=%s "
"AND Job.StartTime<'%s' "
- "AND Level='F' AND JobStatus='T' AND Type='B' "
+ "AND Level='F' AND JobStatus IN ('T','W') AND Type='B' "
"AND JobMedia.JobId=Job.JobId "
"AND Media.Enabled=1 "
"AND JobMedia.MediaId=Media.MediaId "
"Job.ClientId,Job.Level,Job.JobFiles,Job.JobBytes,"
"StartTime,VolumeName,JobMedia.StartFile,VolSessionId,VolSessionTime "
"FROM temp1,Job,JobMedia,Media WHERE temp1.JobId=Job.JobId "
- "AND Level='F' AND JobStatus='T' AND Type='B' "
+ "AND Level='F' AND JobStatus IN ('T','W') AND Type='B' "
"AND Media.Enabled=1 "
"AND JobMedia.JobId=Job.JobId "
"AND JobMedia.MediaId=Media.MediaId";
"AND JobMedia.JobId=Job.JobId "
"AND Media.Enabled=1 "
"AND JobMedia.MediaId=Media.MediaId "
- "AND Job.Level='D' AND JobStatus='T' AND Type='B' "
+ "AND Job.Level='D' AND JobStatus IN ('T','W') AND Type='B' "
"AND Job.FileSetId=FileSet.FileSetId "
"AND FileSet.FileSet='%s' "
"%s"
"AND Media.Enabled=1 "
"AND JobMedia.JobId=Job.JobId "
"AND JobMedia.MediaId=Media.MediaId "
- "AND Job.Level='I' AND JobStatus='T' AND Type='B' "
+ "AND Job.Level='I' AND JobStatus IN ('T','W') AND Type='B' "
"AND Job.FileSetId=FileSet.FileSetId "
"AND FileSet.FileSet='%s' "
"%s";
/* ====== ua_prune.c */
/* List of SQL commands to create temp table and indicies */
-const char *create_deltabs[3] = {
+const char *create_deltabs[4] = {
/* MySQL */
"CREATE TEMPORARY TABLE DelCandidates ("
"JobId INTEGER UNSIGNED NOT NULL, "
"PurgedFiles TINYINT, "
"FileSetId INTEGER UNSIGNED, "
"JobFiles INTEGER UNSIGNED, "
+ "JobStatus CHAR)",
+ /* SQLite3 */
+ "CREATE TEMPORARY TABLE DelCandidates ("
+ "JobId INTEGER UNSIGNED NOT NULL, "
+ "PurgedFiles TINYINT, "
+ "FileSetId INTEGER UNSIGNED, "
+ "JobFiles INTEGER UNSIGNED, "
"JobStatus CHAR)"};
/* ======= ua_restore.c */
/* List Jobs where a particular file is saved */
-const char *uar_file[3] = {
+const char *uar_file[4] = {
/* Mysql */
"SELECT Job.JobId as JobId,"
"CONCAT(Path.Path,Filename.Name) as Name, "
"AND Client.ClientId=Job.ClientId "
"AND Job.JobId=File.JobId "
"AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId "
+ "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20",
+ /* SQLite3 */
+ "SELECT Job.JobId as JobId,"
+ "Path.Path||Filename.Name as Name, "
+ "StartTime,Type as JobType,JobStatus,JobFiles,JobBytes "
+ "FROM Client,Job,File,Filename,Path WHERE Client.Name='%s' "
+ "AND Client.ClientId=Job.ClientId "
+ "AND Job.JobId=File.JobId "
+ "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId "
"AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20"};
-const char *uar_create_temp[3] = {
+const char *uar_create_temp[4] = {
/* Mysql */
"CREATE TEMPORARY TABLE temp ("
"JobId INTEGER UNSIGNED NOT NULL,"
"VolumeName TEXT,"
"StartFile INTEGER UNSIGNED,"
"VolSessionId INTEGER UNSIGNED,"
+ "VolSessionTime INTEGER UNSIGNED)",
+ /* SQLite3 */
+ "CREATE TEMPORARY TABLE temp ("
+ "JobId INTEGER UNSIGNED NOT NULL,"
+ "JobTDate BIGINT UNSIGNED,"
+ "ClientId INTEGER UNSIGNED,"
+ "Level CHAR,"
+ "JobFiles INTEGER UNSIGNED,"
+ "JobBytes BIGINT UNSIGNED,"
+ "StartTime TEXT,"
+ "VolumeName TEXT,"
+ "StartFile INTEGER UNSIGNED,"
+ "VolSessionId INTEGER UNSIGNED,"
"VolSessionTime INTEGER UNSIGNED)"};
-const char *uar_create_temp1[3] = {
+const char *uar_create_temp1[4] = {
/* Mysql */
"CREATE TEMPORARY TABLE temp1 ("
"JobId INTEGER UNSIGNED NOT NULL,"
/* SQLite */
"CREATE TEMPORARY TABLE temp1 ("
"JobId INTEGER UNSIGNED NOT NULL,"
+ "JobTDate BIGINT UNSIGNED)",
+ /* SQLite3 */
+ "CREATE TEMPORARY TABLE temp1 ("
+ "JobId INTEGER UNSIGNED NOT NULL,"
"JobTDate BIGINT UNSIGNED)"};
/* Query to get all files in a directory -- no recursing
* for each time it was backed up.
*/
-const char *uar_jobid_fileindex_from_dir[3] = {
+const char *uar_jobid_fileindex_from_dir[4] = {
/* Mysql */
"SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client "
"WHERE Job.JobId IN (%s) "
"AND Job.ClientId=Client.ClientId "
"AND Path.PathId=File.Pathid "
"AND Filename.FilenameId=File.FilenameId "
+ "GROUP BY File.FileIndex ",
+ /* SQLite3 */
+ "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client "
+ "WHERE Job.JobId IN (%s) "
+ "AND Job.JobId=File.JobId "
+ "AND Path.Path='%s' "
+ "AND Client.Name='%s' "
+ "AND Job.ClientId=Client.ClientId "
+ "AND Path.PathId=File.Pathid "
+ "AND Filename.FilenameId=File.FilenameId "
"GROUP BY File.FileIndex "};