2 Bacula® - The Network Backup Solution
4 Copyright (C) 2002-2008 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
30 * This file contains all the SQL commands issued by the Director
32 * Kern Sibbald, July MMII
37 * Note, PostgreSQL imposes some constraints on using DISTINCT and GROUP BY
38 * for example, the following is illegal in PostgreSQL:
39 * SELECT DISTINCT JobId FROM temp ORDER BY StartTime ASC;
40 * because all the ORDER BY expressions must appear in the SELECT list!
47 const char *cleanup_created_job =
48 "UPDATE Job SET JobStatus='f', StartTime=SchedTime, EndTime=SchedTime "
49 "WHERE JobStatus = 'C'";
50 const char *cleanup_running_job =
51 "UPDATE Job SET JobStatus='f', EndTime=StartTime WHERE JobStatus = 'R'";
53 /* For sql_update.c db_update_stats */
54 const char *fill_jobhisto =
55 "INSERT INTO JobHisto ("
56 "JobId, Job, Name, Type, Level, ClientId, JobStatus, "
57 "SchedTime, StartTime, EndTime, RealEndTime, JobTDate, "
58 "VolSessionId, VolSessionTime, JobFiles, JobBytes, ReadBytes, "
59 "JobErrors, JobMissingFiles, PoolId, FileSetId, PriorJobId, "
60 "PurgedFiles, HasBase ) "
62 "JobId, Job, Name, Type, Level, ClientId, JobStatus, "
63 "SchedTime, StartTime, EndTime, RealEndTime, JobTDate, "
64 "VolSessionId, VolSessionTime, JobFiles, JobBytes, ReadBytes, "
65 "JobErrors, JobMissingFiles, PoolId, FileSetId, PriorJobId, "
66 "PurgedFiles, HasBase "
68 "WHERE JobStatus IN ('T','W','f','A','E') "
69 "AND JobId NOT IN (SELECT JobId FROM JobHisto) "
73 const char *list_pool = "SELECT * FROM Pool WHERE PoolId=%s";
75 /* For ua_dotcmds.c */
76 const char *client_backups =
77 "SELECT DISTINCT Job.JobId,Client.Name as Client,Level,StartTime,"
78 "JobFiles,JobBytes,VolumeName,MediaType,FileSet,Media.Enabled as Enabled"
79 " FROM Client,Job,JobMedia,Media,FileSet"
80 " WHERE Client.Name='%s'"
82 " AND Client.ClientId=Job.ClientId"
83 " AND JobStatus IN ('T','W') AND Type='B'"
84 " AND JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId"
85 " AND Job.FileSetId=FileSet.FileSetId"
86 " ORDER BY Job.StartTime";
89 /* ====== ua_prune.c */
91 const char *del_File = "DELETE FROM File WHERE JobId=%s";
92 const char *upd_Purged = "UPDATE Job Set PurgedFiles=1 WHERE JobId=%s";
93 const char *cnt_DelCand = "SELECT count(*) FROM DelCandidates";
94 const char *del_Job = "DELETE FROM Job WHERE JobId=%s";
95 const char *del_JobMedia = "DELETE FROM JobMedia WHERE JobId=%s";
96 const char *cnt_JobMedia = "SELECT count(*) FROM JobMedia WHERE MediaId=%s";
98 const char *sel_JobMedia =
99 "SELECT DISTINCT JobMedia.JobId FROM JobMedia,Job "
100 "WHERE MediaId=%s AND Job.JobId=JobMedia.JobId "
101 "AND Job.JobTDate<%s";
103 /* Count Select JobIds for File deletion */
104 const char *count_select_job =
105 "SELECT count(*) from Job "
111 /* Select JobIds for File deletion. */
112 const char *select_job =
113 "SELECT DISTINCT JobId from Job "
118 /* Delete temp tables and indexes */
119 const char *drop_deltabs[] = {
120 "DROP TABLE DelCandidates",
123 const char *create_delindex = "CREATE INDEX DelInx1 ON DelCandidates (JobId)";
125 /* Fill candidates table with all Jobs subject to being deleted.
126 * This is used for pruning Jobs (first the files, then the Jobs).
128 const char *insert_delcand =
129 "INSERT INTO DelCandidates "
130 "SELECT JobId,PurgedFiles,FileSetId,JobFiles,JobStatus FROM Job "
136 * Select Jobs from the DelCandidates table that have a
137 * more recent backup -- i.e. are not the only backup.
138 * This is the list of Jobs to delete for a Backup Job.
139 * At the same time, we select "orphanned" jobs
140 * (i.e. no files, ...) for deletion.
143 const char *select_backup_del =
144 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
145 "FROM Job,DelCandidates "
146 "WHERE (Job.JobTDate<%s AND ((DelCandidates.JobFiles=0) OR "
147 "(DelCandidates.JobStatus NOT IN ('T','W')))) OR "
149 "AND Job.ClientId=%s "
150 "AND Job.Level='F' AND Job.JobStatus IN ('T','W') AND Job.Type IN ('B','M') "
151 "AND Job.FileSetId=DelCandidates.FileSetId)";
153 /* Select Jobs from the DelCandidates table that have a
154 * more recent InitCatalog -- i.e. are not the only InitCatalog
155 * This is the list of Jobs to delete for a Verify Job.
157 const char *select_verify_del =
158 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
159 "FROM Job,DelCandidates "
160 "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
162 "AND Job.ClientId=%s "
163 "AND Job.Type='V' AND Job.Level='V' AND Job.JobStatus IN ('T','W') "
164 "AND Job.FileSetId=DelCandidates.FileSetId)";
167 /* Select Jobs from the DelCandidates table.
168 * This is the list of Jobs to delete for a Restore Job.
170 const char *select_restore_del =
171 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
172 "FROM Job,DelCandidates "
173 "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
175 "AND Job.ClientId=%s "
178 /* Select Jobs from the DelCandidates table.
179 * This is the list of Jobs to delete for an Admin Job.
181 const char *select_admin_del =
182 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
183 "FROM Job,DelCandidates "
184 "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
186 "AND Job.ClientId=%s "
190 * Select Jobs from the DelCandidates table.
191 * This is the list of Jobs to delete for an Migrate Job.
193 const char *select_migrate_del =
194 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
195 "FROM Job,DelCandidates "
196 "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
198 "AND Job.ClientId=%s "
202 * Select Jobs from the DelCandidates table.
203 * This is the list of Jobs to delete for an Copy Job.
205 const char *select_copy_del =
206 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
207 "FROM Job,DelCandidates "
208 "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
210 "AND Job.ClientId=%s "
216 const char *select_backup_del =
217 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
218 "FROM Job,DelCandidates "
219 "WHERE (Job.JobId=DelCandidates.JobId AND ((DelCandidates.JobFiles=0) OR "
220 "(DelCandidates.JobStatus NOT IN ('T','W')))) OR "
222 "AND Job.ClientId=%s "
223 "AND Job.Level='F' AND Job.JobStatus IN ('T','W') AND Job.Type IN ('B','M') "
224 "AND Job.FileSetId=DelCandidates.FileSetId)";
226 /* Select Jobs from the DelCandidates table that have a
227 * more recent InitCatalog -- i.e. are not the only InitCatalog
228 * This is the list of Jobs to delete for a Verify Job.
230 const char *select_verify_del =
231 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
232 "FROM Job,DelCandidates "
233 "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
235 "AND Job.ClientId=%s "
236 "AND Job.Type='V' AND Job.Level='V' AND Job.JobStatus IN ('T','W') "
237 "AND Job.FileSetId=DelCandidates.FileSetId)";
240 /* Select Jobs from the DelCandidates table.
241 * This is the list of Jobs to delete for a Restore Job.
243 const char *select_restore_del =
244 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
245 "FROM Job,DelCandidates "
246 "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
248 "AND Job.ClientId=%s "
251 /* Select Jobs from the DelCandidates table.
252 * This is the list of Jobs to delete for an Admin Job.
254 const char *select_admin_del =
255 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
256 "FROM Job,DelCandidates "
257 "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
259 "AND Job.ClientId=%s "
263 * Select Jobs from the DelCandidates table.
264 * This is the list of Jobs to delete for an Migrate Job.
266 const char *select_migrate_del =
267 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
268 "FROM Job,DelCandidates "
269 "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
271 "AND Job.ClientId=%s "
274 const char *select_copy_del =
275 "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
276 "FROM Job,DelCandidates "
277 "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus NOT IN ('T','W')) OR "
279 "AND Job.ClientId=%s "
285 /* ======= ua_restore.c */
286 const char *uar_count_files =
287 "SELECT JobFiles FROM Job WHERE JobId=%s";
289 /* List last 20 Jobs */
290 const char *uar_list_jobs =
291 "SELECT JobId,Client.Name as Client,StartTime,Level as "
292 "JobLevel,JobFiles,JobBytes "
293 "FROM Client,Job WHERE Client.ClientId=Job.ClientId AND JobStatus IN ('T','W') "
294 "AND Type='B' ORDER BY StartTime DESC LIMIT 20";
297 * Find all files for a particular JobId and insert them into
298 * the tree during a restore.
300 const char *uar_sel_files =
301 "SELECT Path.Path,Filename.Name,FileIndex,JobId,LStat "
302 "FROM File,Filename,Path "
303 "WHERE File.JobId IN (%s) AND Filename.FilenameId=File.FilenameId "
304 "AND Path.PathId=File.PathId";
306 const char *uar_del_temp = "DROP TABLE temp";
307 const char *uar_del_temp1 = "DROP TABLE temp1";
309 const char *uar_last_full =
310 "INSERT INTO temp1 SELECT Job.JobId,JobTdate "
311 "FROM Client,Job,JobMedia,Media,FileSet WHERE Client.ClientId=%s "
312 "AND Job.ClientId=%s "
313 "AND Job.StartTime<'%s' "
314 "AND Level='F' AND JobStatus IN ('T','W') AND Type='B' "
315 "AND JobMedia.JobId=Job.JobId "
316 "AND Media.Enabled=1 "
317 "AND JobMedia.MediaId=Media.MediaId "
318 "AND Job.FileSetId=FileSet.FileSetId "
319 "AND FileSet.FileSet='%s' "
321 "ORDER BY Job.JobTDate DESC LIMIT 1";
323 const char *uar_full =
324 "INSERT INTO temp SELECT Job.JobId,Job.JobTDate,"
325 "Job.ClientId,Job.Level,Job.JobFiles,Job.JobBytes,"
326 "StartTime,VolumeName,JobMedia.StartFile,VolSessionId,VolSessionTime "
327 "FROM temp1,Job,JobMedia,Media WHERE temp1.JobId=Job.JobId "
328 "AND Level='F' AND JobStatus IN ('T','W') AND Type='B' "
329 "AND Media.Enabled=1 "
330 "AND JobMedia.JobId=Job.JobId "
331 "AND JobMedia.MediaId=Media.MediaId";
333 const char *uar_dif =
334 "INSERT INTO temp SELECT Job.JobId,Job.JobTDate,Job.ClientId,"
335 "Job.Level,Job.JobFiles,Job.JobBytes,"
336 "Job.StartTime,Media.VolumeName,JobMedia.StartFile,"
337 "Job.VolSessionId,Job.VolSessionTime "
338 "FROM Job,JobMedia,Media,FileSet "
339 "WHERE Job.JobTDate>%s AND Job.StartTime<'%s' "
340 "AND Job.ClientId=%s "
341 "AND JobMedia.JobId=Job.JobId "
342 "AND Media.Enabled=1 "
343 "AND JobMedia.MediaId=Media.MediaId "
344 "AND Job.Level='D' AND JobStatus IN ('T','W') AND Type='B' "
345 "AND Job.FileSetId=FileSet.FileSetId "
346 "AND FileSet.FileSet='%s' "
348 "ORDER BY Job.JobTDate DESC LIMIT 1";
350 const char *uar_inc =
351 "INSERT INTO temp SELECT Job.JobId,Job.JobTDate,Job.ClientId,"
352 "Job.Level,Job.JobFiles,Job.JobBytes,"
353 "Job.StartTime,Media.VolumeName,JobMedia.StartFile,"
354 "Job.VolSessionId,Job.VolSessionTime "
355 "FROM Job,JobMedia,Media,FileSet "
356 "WHERE Job.JobTDate>%s AND Job.StartTime<'%s' "
357 "AND Job.ClientId=%s "
358 "AND Media.Enabled=1 "
359 "AND JobMedia.JobId=Job.JobId "
360 "AND JobMedia.MediaId=Media.MediaId "
361 "AND Job.Level='I' AND JobStatus IN ('T','W') AND Type='B' "
362 "AND Job.FileSetId=FileSet.FileSetId "
363 "AND FileSet.FileSet='%s' "
366 const char *uar_list_temp =
367 "SELECT DISTINCT JobId,Level,JobFiles,JobBytes,StartTime,VolumeName"
369 " ORDER BY StartTime ASC";
372 const char *uar_sel_jobid_temp =
373 "SELECT DISTINCT JobId,StartTime FROM temp ORDER BY StartTime ASC";
375 const char *uar_sel_all_temp1 = "SELECT * FROM temp1";
377 const char *uar_sel_all_temp = "SELECT * FROM temp";
381 /* Select FileSet names for this Client */
382 const char *uar_sel_fileset =
383 "SELECT DISTINCT FileSet.FileSet FROM Job,"
384 "Client,FileSet WHERE Job.FileSetId=FileSet.FileSetId "
385 "AND Job.ClientId=%s AND Client.ClientId=%s "
386 "ORDER BY FileSet.FileSet";
388 /* Find MediaType used by this Job */
389 const char *uar_mediatype =
390 "SELECT MediaType FROM JobMedia,Media WHERE JobMedia.JobId=%s "
391 "AND JobMedia.MediaId=Media.MediaId";
394 * Find JobId, FileIndex for a given path/file and date
395 * for use when inserting individual files into the tree.
397 const char *uar_jobid_fileindex =
398 "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client "
399 "WHERE Job.JobId=File.JobId "
400 "AND Job.StartTime<='%s' "
401 "AND Path.Path='%s' "
402 "AND Filename.Name='%s' "
403 "AND Client.Name='%s' "
404 "AND Job.ClientId=Client.ClientId "
405 "AND Path.PathId=File.PathId "
406 "AND Filename.FilenameId=File.FilenameId "
407 "AND JobStatus IN ('T','W') AND Type='B' "
408 "ORDER BY Job.StartTime DESC LIMIT 1";
410 const char *uar_jobids_fileindex =
411 "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client "
412 "WHERE Job.JobId IN (%s) "
413 "AND Job.JobId=File.JobId "
414 "AND Job.StartTime<='%s' "
415 "AND Path.Path='%s' "
416 "AND Filename.Name='%s' "
417 "AND Client.Name='%s' "
418 "AND Job.ClientId=Client.ClientId "
419 "AND Path.PathId=File.PathId "
420 "AND Filename.FilenameId=File.FilenameId "
421 "ORDER BY Job.StartTime DESC LIMIT 1";
423 /* Query to get list of files from table -- presuably built by an external program */
424 const char *uar_jobid_fileindex_from_table =
425 "SELECT JobId,FileIndex from %s";
430 * This file contains all the SQL commands issued by the Director
432 * Kern Sibbald, July MMII
437 * Note, PostgreSQL imposes some constraints on using DISTINCT and GROUP BY
438 * for example, the following is illegal in PostgreSQL:
439 * SELECT DISTINCT JobId FROM temp ORDER BY StartTime ASC;
440 * because all the ORDER BY expressions must appear in the SELECT list!
447 /* ====== ua_prune.c */
449 /* List of SQL commands to create temp table and indicies */
450 const char *create_deltabs[4] = {
452 "CREATE TEMPORARY TABLE DelCandidates ("
453 "JobId INTEGER UNSIGNED NOT NULL, "
454 "PurgedFiles TINYINT, "
455 "FileSetId INTEGER UNSIGNED, "
456 "JobFiles INTEGER UNSIGNED, "
457 "JobStatus BINARY(1))",
459 "CREATE TEMPORARY TABLE DelCandidates ("
460 "JobId INTEGER NOT NULL, "
461 "PurgedFiles SMALLINT, "
462 "FileSetId INTEGER, "
464 "JobStatus char(1))",
466 "CREATE TEMPORARY TABLE DelCandidates ("
467 "JobId INTEGER UNSIGNED NOT NULL, "
468 "PurgedFiles TINYINT, "
469 "FileSetId INTEGER UNSIGNED, "
470 "JobFiles INTEGER UNSIGNED, "
473 "CREATE TEMPORARY TABLE DelCandidates ("
474 "JobId INTEGER UNSIGNED NOT NULL, "
475 "PurgedFiles TINYINT, "
476 "FileSetId INTEGER UNSIGNED, "
477 "JobFiles INTEGER UNSIGNED, "
480 /* ======= ua_restore.c */
482 /* List Jobs where a particular file is saved */
483 const char *uar_file[4] = {
485 "SELECT Job.JobId as JobId,"
486 "CONCAT(Path.Path,Filename.Name) as Name, "
487 "StartTime,Type as JobType,JobStatus,JobFiles,JobBytes "
488 "FROM Client,Job,File,Filename,Path WHERE Client.Name='%s' "
489 "AND Client.ClientId=Job.ClientId "
490 "AND Job.JobId=File.JobId AND File.FileIndex > 0 "
491 "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId "
492 "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20",
494 "SELECT Job.JobId as JobId,"
495 "Path.Path||Filename.Name as Name, "
496 "StartTime,Type as JobType,JobStatus,JobFiles,JobBytes "
497 "FROM Client,Job,File,Filename,Path WHERE Client.Name='%s' "
498 "AND Client.ClientId=Job.ClientId "
499 "AND Job.JobId=File.JobId AND File.FileIndex > 0 "
500 "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId "
501 "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20",
503 "SELECT Job.JobId as JobId,"
504 "Path.Path||Filename.Name as Name, "
505 "StartTime,Type as JobType,JobStatus,JobFiles,JobBytes "
506 "FROM Client,Job,File,Filename,Path WHERE Client.Name='%s' "
507 "AND Client.ClientId=Job.ClientId "
508 "AND Job.JobId=File.JobId AND File.FileIndex > 0 "
509 "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId "
510 "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20",
512 "SELECT Job.JobId as JobId,"
513 "Path.Path||Filename.Name as Name, "
514 "StartTime,Type as JobType,JobStatus,JobFiles,JobBytes "
515 "FROM Client,Job,File,Filename,Path WHERE Client.Name='%s' "
516 "AND Client.ClientId=Job.ClientId "
517 "AND Job.JobId=File.JobId AND File.FileIndex > 0 "
518 "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId "
519 "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20"};
521 const char *uar_create_temp[4] = {
523 "CREATE TEMPORARY TABLE temp ("
524 "JobId INTEGER UNSIGNED NOT NULL,"
525 "JobTDate BIGINT UNSIGNED,"
526 "ClientId INTEGER UNSIGNED,"
528 "JobFiles INTEGER UNSIGNED,"
529 "JobBytes BIGINT UNSIGNED,"
532 "StartFile INTEGER UNSIGNED,"
533 "VolSessionId INTEGER UNSIGNED,"
534 "VolSessionTime INTEGER UNSIGNED)",
536 "CREATE TEMPORARY TABLE temp ("
537 "JobId INTEGER NOT NULL,"
546 "VolSessionId INTEGER,"
547 "VolSessionTime INTEGER)",
549 "CREATE TEMPORARY TABLE temp ("
550 "JobId INTEGER UNSIGNED NOT NULL,"
551 "JobTDate BIGINT UNSIGNED,"
552 "ClientId INTEGER UNSIGNED,"
554 "JobFiles INTEGER UNSIGNED,"
555 "JobBytes BIGINT UNSIGNED,"
558 "StartFile INTEGER UNSIGNED,"
559 "VolSessionId INTEGER UNSIGNED,"
560 "VolSessionTime INTEGER UNSIGNED)",
562 "CREATE TEMPORARY TABLE temp ("
563 "JobId INTEGER UNSIGNED NOT NULL,"
564 "JobTDate BIGINT UNSIGNED,"
565 "ClientId INTEGER UNSIGNED,"
567 "JobFiles INTEGER UNSIGNED,"
568 "JobBytes BIGINT UNSIGNED,"
571 "StartFile INTEGER UNSIGNED,"
572 "VolSessionId INTEGER UNSIGNED,"
573 "VolSessionTime INTEGER UNSIGNED)"};
575 const char *uar_create_temp1[4] = {
577 "CREATE TEMPORARY TABLE temp1 ("
578 "JobId INTEGER UNSIGNED NOT NULL,"
579 "JobTDate BIGINT UNSIGNED)",
581 "CREATE TEMPORARY TABLE temp1 ("
582 "JobId INTEGER NOT NULL,"
585 "CREATE TEMPORARY TABLE temp1 ("
586 "JobId INTEGER UNSIGNED NOT NULL,"
587 "JobTDate BIGINT UNSIGNED)",
589 "CREATE TEMPORARY TABLE temp1 ("
590 "JobId INTEGER UNSIGNED NOT NULL,"
591 "JobTDate BIGINT UNSIGNED)"};
593 /* Query to get all files in a directory -- no recursing
594 * Note, for PostgreSQL since it respects the "Single Value
595 * rule", the results of the SELECT will be unoptimized.
596 * I.e. the same file will be restored multiple times, once
597 * for each time it was backed up.
600 const char *uar_jobid_fileindex_from_dir[4] = {
602 "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client "
603 "WHERE Job.JobId IN (%s) "
604 "AND Job.JobId=File.JobId "
605 "AND Path.Path='%s' "
606 "AND Client.Name='%s' "
607 "AND Job.ClientId=Client.ClientId "
608 "AND Path.PathId=File.Pathid "
609 "AND Filename.FilenameId=File.FilenameId "
610 "GROUP BY File.FileIndex ",
612 "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client "
613 "WHERE Job.JobId IN (%s) "
614 "AND Job.JobId=File.JobId "
615 "AND Path.Path='%s' "
616 "AND Client.Name='%s' "
617 "AND Job.ClientId=Client.ClientId "
618 "AND Path.PathId=File.Pathid "
619 "AND Filename.FilenameId=File.FilenameId",
621 "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client "
622 "WHERE Job.JobId IN (%s) "
623 "AND Job.JobId=File.JobId "
624 "AND Path.Path='%s' "
625 "AND Client.Name='%s' "
626 "AND Job.ClientId=Client.ClientId "
627 "AND Path.PathId=File.Pathid "
628 "AND Filename.FilenameId=File.FilenameId "
629 "GROUP BY File.FileIndex ",
631 "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client "
632 "WHERE Job.JobId IN (%s) "
633 "AND Job.JobId=File.JobId "
634 "AND Path.Path='%s' "
635 "AND Client.Name='%s' "
636 "AND Job.ClientId=Client.ClientId "
637 "AND Path.PathId=File.Pathid "
638 "AND Filename.FilenameId=File.FilenameId "
639 "GROUP BY File.FileIndex "};