*/
/*
- Copyright (C) 2002 Kern Sibbald and John Walker
+ Copyright (C) 2002-2003 Kern Sibbald and John Walker
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
#include "bacula.h"
#include "dird.h"
+/* For ua_cmds.c */
+char *list_pool = "SELECT * FROM Pool WHERE PoolId=%u";
+
/* ====== ua_prune.c */
char *cnt_File = "SELECT count(*) FROM File WHERE JobId=%u";
/* Select JobIds for File deletion. */
char *select_job =
"SELECT JobId from Job "
- "WHERE JobTDate < %s "
- "AND ClientId=%d "
+ "WHERE JobTDate<%s "
+ "AND ClientId=%u "
"AND PurgedFiles=0";
/* Delete temp tables and indexes */
"CREATE TABLE DelCandidates ("
"JobId INTEGER UNSIGNED NOT NULL, "
"PurgedFiles TINYINT, "
- "FileSetId INTEGER UNSIGNED)",
+ "FileSetId INTEGER UNSIGNED, "
+ "JobFiles INTEGER UNSIGNED, "
+#ifdef HAVE_MYSQL
+ "JobStatus BINARY(1))",
+#else
+ "JobStatus CHAR)",
+#endif
"CREATE INDEX DelInx1 ON DelCandidates (JobId)",
NULL};
-/* Fill candidates table with all Files subject to being deleted.
+/* Fill candidates table with all Jobs subject to being deleted.
* This is used for pruning Jobs (first the files, then the Jobs).
*/
char *insert_delcand =
"INSERT INTO DelCandidates "
- "SELECT JobId, PurgedFiles, FileSetId FROM Job "
- "WHERE JobTDate < %s "
- "AND ClientId=%d";
+ "SELECT JobId,PurgedFiles,FileSetId,JobFiles,JobStatus FROM Job "
+ "WHERE Type='%c' "
+ "AND JobTDate<%s "
+ "AND ClientId=%u";
-/* Select files from the DelCandidates table that have a
+/* Select Jobs from the DelCandidates table that have a
* more recent backup -- i.e. are not the only backup.
- * This is the list of files to delete for a Backup Job.
+ * This is the list of Jobs to delete for a Backup Job.
+ * At the same time, we select "orphanned" jobs
+ * (i.e. no files, ...) for deletion.
*/
char *select_backup_del =
"SELECT DelCandidates.JobId "
"FROM Job,DelCandidates "
- "WHERE Job.JobTDate >= %s "
- "AND Job.ClientId=%d "
- "AND Job.JobType='B' "
+ "WHERE (JobTDate<%s AND ((DelCandidates.JobFiles=0) OR "
+ "(DelCandidates.JobStatus!='T'))) OR "
+ "(Job.JobTDate>%s "
+ "AND Job.ClientId=%u "
+ "AND Job.Type='B' "
"AND Job.Level='F' "
"AND Job.JobStatus='T' "
- "AND Job.FileSetId=DelCandidates.FileSetId";
+ "AND Job.FileSetId=DelCandidates.FileSetId) "
+ "GROUP BY DelCandidates.JobId";
-/* Select files from the DelCandidates table that have a
+/* Select Jobs from the DelCandidates table that have a
* more recent InitCatalog -- i.e. are not the only InitCatalog
- * This is the list of files to delete for a Verify Job.
+ * This is the list of Jobs to delete for a Verify Job.
*/
char *select_verify_del =
"SELECT DelCandidates.JobId "
"FROM Job,DelCandidates "
- "WHERE Job.JobTDate >= %s "
- "AND Job.ClientId=%d "
- "AND Job.JobType='V' "
+ "WHERE Job.JobTDate>%s "
+ "AND Job.ClientId=%u "
+ "AND Job.Type='V' "
"AND Job.Level='V' "
"AND Job.JobStatus='T' "
- "AND Job.FileSetId=DelCandidates.FileSetId";
+ "AND Job.FileSetId=DelCandidates.FileSetId "
+ "GROUP BY DelCandidates.JobId";
-/* Select files from the DelCandidates table.
- * This is the list of files to delete for a Restore Job.
+/* Select Jobs from the DelCandidates table.
+ * This is the list of Jobs to delete for a Restore Job.
*/
char *select_restore_del =
"SELECT DelCandidates.JobId "
"FROM Job,DelCandidates "
- "WHERE Job.JobTDate >= %s "
- "AND Job.ClientId=%d "
- "AND Job.JobType='R'";
+ "WHERE Job.JobTDate>%s "
+ "AND Job.ClientId=%u "
+ "AND Job.Type='R' "
+ "GROUP BY DelCandidates.JobId";
/* ======= ua_restore.c */
+/* List last 20 Jobs */
char *uar_list_jobs =
- "SELECT JobId,Client.Name as Client,StartTime,Type as "
- "JobType,JobFiles,JobBytes "
+ "SELECT JobId,Client.Name as Client,StartTime,Level as "
+ "JobLevel,JobFiles,JobBytes "
"FROM Client,Job WHERE Client.ClientId=Job.ClientId AND JobStatus='T' "
- "LIMIT 20";
+ "AND Type='B' ORDER BY StartTime DESC LIMIT 20";
+#ifdef HAVE_MYSQL
+/* MYSQL IS NOT STANDARD SQL !!!!! */
+/* List Jobs where a particular file is saved */
char *uar_file =
"SELECT Job.JobId as JobId, Client.Name as Client, "
"CONCAT(Path.Path,Filename.Name) as Name, "
"AND JobStatus='T' AND Job.JobId=File.JobId "
"AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId "
"AND Filename.Name='%s' LIMIT 20";
+#else
+/* List Jobs where a particular file is saved */
+char *uar_file =
+ "SELECT Job.JobId as JobId, Client.Name as Client, "
+ "Path.Path||Filename.Name as Name, "
+ "StartTime,Type as JobType,JobFiles,JobBytes "
+ "FROM Client,Job,File,Filename,Path WHERE Client.ClientId=Job.ClientId "
+ "AND JobStatus='T' AND Job.JobId=File.JobId "
+ "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId "
+ "AND Filename.Name='%s' LIMIT 20";
+#endif
+
char *uar_sel_files =
"SELECT Path.Path,Filename.Name,FileIndex,JobId "
char *uar_create_temp1 =
"CREATE TABLE temp1 (JobId INTEGER UNSIGNED NOT NULL,"
- "JobTDate BIGINT UNSIGNED,"
- "ClientId INTEGER UNSIGNED)";
+ "JobTDate BIGINT UNSIGNED)";
char *uar_last_full =
- "INSERT INTO temp1 SELECT Job.JobId,JobTdate,Job.ClientId "
- "FROM Client,Job,JobMedia,Media WHERE Client.Name='%s' "
- "AND Client.ClientId=Job.ClientId "
+ "INSERT INTO temp1 SELECT Job.JobId,JobTdate "
+ "FROM Client,Job,JobMedia,Media WHERE Client.ClientId=%u "
+ "AND Job.ClientId=%u "
+ "AND Job.StartTime<'%s' "
"AND Level='F' AND JobStatus='T' "
"AND JobMedia.JobId=Job.JobId "
"AND JobMedia.MediaId=Media.MediaId "
+ "AND Job.FileSetId=%u "
"ORDER BY Job.JobTDate DESC LIMIT 1";
char *uar_full =
"AND JobMedia.JobId=Job.JobId "
"AND JobMedia.MediaId=Media.MediaId";
-char *uar_inc =
+char *uar_inc_dec =
"INSERT INTO temp SELECT Job.JobId,Job.JobTDate,Job.ClientId,"
"Job.Level,Job.JobFiles,Job.StartTime,Media.VolumeName,JobMedia.StartFile,"
"Job.VolSessionId,Job.VolSessionTime "
"FROM Job,JobMedia,Media "
- "WHERE Job.JobTDate>%d AND Job.ClientId=%u "
+ "WHERE Job.JobTDate>%s AND Job.StartTime<'%s' "
+ "AND Job.ClientId=%u "
"AND JobMedia.JobId=Job.JobId "
"AND JobMedia.MediaId=Media.MediaId "
- "AND Job.Level='I' AND JobStatus='T' "
+ "AND Job.Level IN ('I', 'D') AND JobStatus='T' "
+ "AND Job.FileSetId=%u "
"GROUP BY Job.JobId";
char *uar_list_temp =
"SELECT JobId,Level,JobFiles,StartTime,VolumeName,StartFile,"
- "VolSessionId,VolSessionTime FROM temp";
+ "VolSessionId,VolSessionTime FROM temp "
+ "GROUP by JobId ORDER BY StartTime ASC";
+
+
+char *uar_sel_jobid_temp = "SELECT JobId FROM temp";
+
+char *uar_sel_all_temp1 = "SELECT * FROM temp1";
+
+/* Select filesets for this Client */
+char *uar_sel_fileset =
+ "SELECT FileSet.FileSetId,FileSet.FileSet,FileSet.CreateTime FROM Job,"
+ "Client,FileSet WHERE Job.FileSetId=FileSet.FileSetId "
+ "AND Job.ClientId=%u AND Client.ClientId=%u "
+ "GROUP BY FileSet.FileSetId ORDER BY FileSet.CreateTime";
+
+/* Find MediaType used by this Job */
+char *uar_mediatype =
+ "SELECT MediaType FROM JobMedia,Media WHERE JobMedia.JobId=%u "
+ "AND JobMedia.MediaId=Media.MediaId";
-char *uar_sel_jobid_temp = "SELECT JobId from temp";
+/* Find JobId, FileIndex for a given path/file and date */
+char *uar_jobid_fileindex =
+ "SELECT Job.JobId, File.FileIndex FROM Job,File,Path,Filename,Client "
+ "WHERE Job.JobId=File.JobId "
+ "AND Job.StartTime<'%s' "
+ "AND Path.Path='%s' "
+ "AND Filename.Name='%s' "
+ "AND Client.Name='%s' "
+ "AND Path.PathId=File.PathId "
+ "AND Filename.FilenameId=File.FilenameId "
+ "ORDER BY Job.StartTime DESC LIMIT 1";
+