]> 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 f2e7b3abca538dfd7df1e4780affa02802fa0acb..1a9ae7a25eed9e651153d42e552bacc27da9d22b 100644 (file)
@@ -30,6 +30,9 @@
 #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";
@@ -44,7 +47,7 @@ char *sel_JobMedia = "SELECT JobId FROM JobMedia WHERE MediaId=%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";
 
@@ -59,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 "
@@ -99,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";
 
 
 
@@ -118,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 !!!!! */
@@ -176,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 "
@@ -191,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' "
@@ -213,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 =