3 * This file contains all the SQL commands issued by the Director
5 * Kern Sibbald, July MMII
11 Copyright (C) 2002 Kern Sibbald and John Walker
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of
16 the License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public
24 License along with this program; if not, write to the Free
25 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
33 /* ====== ua_prune.c */
35 char *cnt_File = "SELECT count(*) FROM File WHERE JobId=%u";
36 char *del_File = "DELETE FROM File WHERE JobId=%u";
37 char *upd_Purged = "UPDATE Job Set PurgedFiles=1 WHERE JobId=%u";
38 char *cnt_DelCand = "SELECT count(*) FROM DelCandidates";
39 char *del_Job = "DELETE FROM Job WHERE JobId=%u";
40 char *del_JobMedia = "DELETE FROM JobMedia WHERE JobId=%u";
41 char *cnt_JobMedia = "SELECT count(*) FROM JobMedia WHERE MediaId=%u";
42 char *sel_JobMedia = "SELECT JobId FROM JobMedia WHERE MediaId=%u";
44 /* Select JobIds for File deletion. */
46 "SELECT JobId from Job "
47 "WHERE JobTDate < %s "
51 /* Delete temp tables and indexes */
52 char *drop_deltabs[] = {
53 "DROP TABLE DelCandidates",
57 /* List of SQL commands to create temp table and indicies */
58 char *create_deltabs[] = {
59 "CREATE TABLE DelCandidates ("
60 "JobId INTEGER UNSIGNED NOT NULL, "
61 "PurgedFiles TINYINT, "
62 "FileSetId INTEGER UNSIGNED)",
63 "CREATE INDEX DelInx1 ON DelCandidates (JobId)",
66 /* Fill candidates table with all Files subject to being deleted.
67 * This is used for pruning Jobs (first the files, then the Jobs).
69 char *insert_delcand =
70 "INSERT INTO DelCandidates "
71 "SELECT JobId, PurgedFiles, FileSetId FROM Job "
72 "WHERE JobTDate < %s "
75 /* Select files from the DelCandidates table that have a
76 * more recent backup -- i.e. are not the only backup.
77 * This is the list of files to delete for a Backup Job.
79 char *select_backup_del =
80 "SELECT DelCandidates.JobId "
81 "FROM Job,DelCandidates "
82 "WHERE Job.JobTDate >= %s "
83 "AND Job.ClientId=%d "
84 "AND Job.JobType='B' "
86 "AND Job.JobStatus='T' "
87 "AND Job.FileSetId=DelCandidates.FileSetId";
89 /* Select files from the DelCandidates table that have a
90 * more recent InitCatalog -- i.e. are not the only InitCatalog
91 * This is the list of files to delete for a Verify Job.
93 char *select_verify_del =
94 "SELECT DelCandidates.JobId "
95 "FROM Job,DelCandidates "
96 "WHERE Job.JobTDate >= %s "
97 "AND Job.ClientId=%d "
98 "AND Job.JobType='V' "
100 "AND Job.JobStatus='T' "
101 "AND Job.FileSetId=DelCandidates.FileSetId";
104 /* Select files from the DelCandidates table.
105 * This is the list of files to delete for a Restore Job.
107 char *select_restore_del =
108 "SELECT DelCandidates.JobId "
109 "FROM Job,DelCandidates "
110 "WHERE Job.JobTDate >= %s "
111 "AND Job.ClientId=%d "
112 "AND Job.JobType='R'";
116 /* ======= ua_restore.c */
118 /* List last 20 Jobs */
119 char *uar_list_jobs =
120 "SELECT JobId,Client.Name as Client,StartTime,Type as "
121 "JobType,JobFiles,JobBytes "
122 "FROM Client,Job WHERE Client.ClientId=Job.ClientId AND JobStatus='T' "
123 "AND Type='B' LIMIT 20";
126 /* MYSQL IS NOT STANDARD SQL !!!!! */
127 /* List Jobs where a particular file is saved */
129 "SELECT Job.JobId as JobId, Client.Name as Client, "
130 "CONCAT(Path.Path,Filename.Name) as Name, "
131 "StartTime,Type as JobType,JobFiles,JobBytes "
132 "FROM Client,Job,File,Filename,Path WHERE Client.ClientId=Job.ClientId "
133 "AND JobStatus='T' AND Job.JobId=File.JobId "
134 "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId "
135 "AND Filename.Name='%s' LIMIT 20";
137 /* List Jobs where a particular file is saved */
139 "SELECT Job.JobId as JobId, Client.Name as Client, "
140 "Path.Path||Filename.Name as Name, "
141 "StartTime,Type as JobType,JobFiles,JobBytes "
142 "FROM Client,Job,File,Filename,Path WHERE Client.ClientId=Job.ClientId "
143 "AND JobStatus='T' AND Job.JobId=File.JobId "
144 "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId "
145 "AND Filename.Name='%s' LIMIT 20";
149 char *uar_sel_files =
150 "SELECT Path.Path,Filename.Name,FileIndex,JobId "
151 "FROM File,Filename,Path "
152 "WHERE File.JobId=%d AND Filename.FilenameId=File.FilenameId "
153 "AND Path.PathId=File.PathId";
155 char *uar_del_temp = "DROP TABLE temp";
156 char *uar_del_temp1 = "DROP TABLE temp1";
158 char *uar_create_temp =
159 "CREATE TABLE temp (JobId INTEGER UNSIGNED NOT NULL,"
160 "JobTDate BIGINT UNSIGNED,"
161 "ClientId INTEGER UNSIGNED,"
163 "JobFiles INTEGER UNSIGNED,"
166 "StartFile INTEGER UNSIGNED,"
167 "VolSessionId INTEGER UNSIGNED,"
168 "VolSessionTime INTEGER UNSIGNED)";
170 char *uar_create_temp1 =
171 "CREATE TABLE temp1 (JobId INTEGER UNSIGNED NOT NULL,"
172 "JobTDate BIGINT UNSIGNED,"
173 "ClientId INTEGER UNSIGNED)";
175 char *uar_last_full =
176 "INSERT INTO temp1 SELECT Job.JobId,JobTdate,Job.ClientId "
177 "FROM Client,Job,JobMedia,Media WHERE Client.Name='%s' "
178 "AND Client.ClientId=Job.ClientId "
179 "AND Level='F' AND JobStatus='T' "
180 "AND JobMedia.JobId=Job.JobId "
181 "AND JobMedia.MediaId=Media.MediaId "
182 "AND Job.FileSetId=%u "
183 "ORDER BY Job.JobTDate DESC LIMIT 1";
186 "INSERT INTO temp SELECT Job.JobId,Job.JobTDate,"
187 " Job.ClientId,Job.Level,Job.JobFiles,"
188 " StartTime,VolumeName,JobMedia.StartFile,VolSessionId,VolSessionTime "
189 "FROM temp1,Job,JobMedia,Media WHERE temp1.JobId=Job.JobId "
190 "AND Level='F' AND JobStatus='T' "
191 "AND JobMedia.JobId=Job.JobId "
192 "AND JobMedia.MediaId=Media.MediaId";
195 "INSERT INTO temp SELECT Job.JobId,Job.JobTDate,Job.ClientId,"
196 "Job.Level,Job.JobFiles,Job.StartTime,Media.VolumeName,JobMedia.StartFile,"
197 "Job.VolSessionId,Job.VolSessionTime "
198 "FROM Job,JobMedia,Media "
199 "WHERE Job.JobTDate>%d AND Job.ClientId=%u "
200 "AND JobMedia.JobId=Job.JobId "
201 "AND JobMedia.MediaId=Media.MediaId "
202 "AND Job.Level='I' AND JobStatus='T' "
203 "AND Job.FileSetId=%u "
204 "GROUP BY Job.JobId";
206 char *uar_list_temp =
207 "SELECT JobId,Level,JobFiles,StartTime,VolumeName,StartFile,"
208 "VolSessionId,VolSessionTime FROM temp";
210 char *uar_sel_jobid_temp = "SELECT JobId FROM temp";
212 char *uar_sel_all_temp1 = "SELECT * FROM temp1";
214 /* Select filesets for this Client */
215 char *uar_sel_fileset =
216 "SELECT FileSet.FileSetId,FileSet.FileSet FROM Job,"
217 "Client,FileSet WHERE Job.FileSetId=FileSet.FileSetId "
218 "AND Job.ClientId=Client.ClientId AND Client.Name='%s' "
219 "GROUP BY FileSet.FileSetId";
221 /* Find MediaType used by this Job */
222 char *uar_mediatype =
223 "SELECT MediaType FROM JobMedia,Media WHERE JobMedia.JobId=%u "
224 "AND JobMedia.MediaId=Media.MediaId";