]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/sql_cmds.c
Add new files
[bacula/bacula] / bacula / src / dird / sql_cmds.c
index 84a73ff53b74b67eb23fdfc00b3d98db60e0d7ea..1a9ae7a25eed9e651153d42e552bacc27da9d22b 100644 (file)
@@ -62,37 +62,46 @@ char *create_deltabs[] = {
    "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.
  */
 char *select_backup_del =
    "SELECT DelCandidates.JobId "
    "FROM Job,DelCandidates "
-   "WHERE Job.JobTDate>%s "
+   "WHERE (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 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 "
@@ -102,18 +111,20 @@ char *select_verify_del =
    "AND Job.Type='V' "
    "AND Job.Level='V' "
    "AND Job.JobStatus='T' "
-   "AND Job.FileSetId=DelCandidates.FileSetId";
+   "AND Job.FileSetId=DelCandidates.FileSetId "
+   "GROUP BY 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 JobId";
 
 
 
@@ -121,10 +132,10 @@ char *select_restore_del =
 
 /* 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 LIMIT 20";
 
 #ifdef HAVE_MYSQL
 /*  MYSQL IS NOT STANDARD SQL !!!!! */
@@ -179,6 +190,7 @@ char *uar_last_full =
    "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 "
@@ -194,12 +206,13 @@ 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>%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' "
@@ -216,10 +229,10 @@ char *uar_sel_all_temp1 = "SELECT * FROM temp1";
 
 /* 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.FileSetId";
 
 /* Find MediaType used by this Job */
 char *uar_mediatype =