*/
/*
- 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 "
+ "WHERE JobTDate<%s "
"AND ClientId=%u "
"AND PurgedFiles=0";
"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 "
+ "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 "
+ "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 "
"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=%u "
- "AND Job.Type='R'";
+ "AND Job.Type='R' "
+ "GROUP BY DelCandidates.JobId";
/* 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' "
- "AND Type='B' LIMIT 20";
+ "AND Type='B' ORDER BY StartTime DESC LIMIT 20";
#ifdef HAVE_MYSQL
/* MYSQL IS NOT STANDARD SQL !!!!! */
"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 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>%s 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 IN ('I', 'D') AND JobStatus='T' "
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";
/* Select filesets for this Client */
char *uar_sel_fileset =
- "SELECT FileSet.FileSetId,FileSet.FileSet,FileSet.MD5 FROM Job,"
+ "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";
+ "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";
+
+/* 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";
+