*
* Version $Id$
*/
-
/*
- Copyright (C) 2002-2004 Kern Sibbald and John Walker
+ Copyright (C) 2002-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
/* For ua_dotcmds.c */
const char *client_backups =
-"SELECT DISTINCT Job.JobId,Client.Name as Client,Level,StartTime,"
-"JobFiles,JobBytes,VolumeName,MediaType"
-" FROM Client,Job,JobMedia,Media"
-" WHERE Client.Name='%s'"
-" AND Client.ClientId=Job.ClientId"
-" AND JobStatus='T'"
-" AND JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId"
-" ORDER BY Job.StartTime";
+ "SELECT DISTINCT Job.JobId,Client.Name as Client,Level,StartTime,"
+ "JobFiles,JobBytes,VolumeName,MediaType,FileSet"
+ " FROM Client,Job,JobMedia,Media,FileSet"
+ " WHERE Client.Name='%s'"
+ " AND FileSet='%s'"
+ " AND Client.ClientId=Job.ClientId"
+ " AND JobStatus='T'"
+ " AND JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId"
+ " AND Job.FileSetId=FileSet.FileSetId"
+ " ORDER BY Job.StartTime";
/* ====== ua_prune.c */
-const char *cnt_File = "SELECT count(*) FROM File WHERE JobId=%s";
const char *del_File = "DELETE FROM File WHERE JobId=%s";
const char *upd_Purged = "UPDATE Job Set PurgedFiles=1 WHERE JobId=%s";
const char *cnt_DelCand = "SELECT count(*) FROM DelCandidates";
const char *del_Job = "DELETE FROM Job WHERE JobId=%s";
+const char *del_MAC = "DELETE FROM MAC WHERE JobId=%s";
const char *del_JobMedia = "DELETE FROM JobMedia WHERE JobId=%s";
const char *cnt_JobMedia = "SELECT count(*) FROM JobMedia WHERE MediaId=%s";
const char *sel_JobMedia = "SELECT JobId FROM JobMedia WHERE MediaId=%s";
/* List of SQL commands to create temp table and indicies */
const char *create_deltabs[] = {
- "CREATE TABLE DelCandidates ("
+ "CREATE TEMPORARY TABLE DelCandidates ("
#ifdef HAVE_MYSQL
"JobId INTEGER UNSIGNED NOT NULL, "
"PurgedFiles TINYINT, "
const char *uar_del_temp1 = "DROP TABLE temp1";
const char *uar_create_temp =
- "CREATE TABLE temp ("
+ "CREATE TEMPORARY TABLE temp ("
#ifdef HAVE_POSTGRESQL
"JobId INTEGER NOT NULL,"
"JobTDate BIGINT,"
#endif
const char *uar_create_temp1 =
- "CREATE TABLE temp1 ("
+ "CREATE TEMPORARY TABLE temp1 ("
#ifdef HAVE_POSTGRESQL
"JobId INTEGER NOT NULL,"
"JobTDate BIGINT)";
"AND FileSet.FileSet='%s' "
"%s";
+#ifdef HAVE_POSTGRESQL
+/* Note, the PostgreSQL will have a much uglier looking
+ * list since it cannot do GROUP BY of different values.
+ */
+const char *uar_list_temp =
+ "SELECT JobId,Level,JobFiles,JobBytes,StartTime,VolumeName,StartFile"
+ " FROM temp"
+ " ORDER BY StartTime,StartFile ASC";
+#else
const char *uar_list_temp =
"SELECT JobId,Level,JobFiles,JobBytes,StartTime,VolumeName,StartFile"
" FROM temp"
" GROUP BY JobId ORDER BY StartTime,StartFile ASC";
+#endif
const char *uar_sel_jobid_temp = "SELECT JobId FROM temp ORDER BY StartTime ASC";
"AND Filename.FilenameId=File.FilenameId "
"ORDER BY Job.StartTime DESC LIMIT 1";
-/* Query to get all files in a directory -- no recursing */
+/* Query to get all files in a directory -- no recursing
+ * Note, for PostgreSQL since it respects the "Single Value
+ * rule", the results of the SELECT will be unoptimized.
+ * I.e. the same file will be restored multiple times, once
+ * for each time it was backed up.
+ */
+
+#ifdef HAVE_POSTGRESQL
+const char *uar_jobid_fileindex_from_dir =
+ "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client "
+ "WHERE Job.JobId IN (%s) "
+ "AND Job.JobId=File.JobId "
+ "AND Path.Path='%s' "
+ "AND Client.Name='%s' "
+ "AND Job.ClientId=Client.ClientId "
+ "AND Path.PathId=File.Pathid "
+ "AND Filename.FilenameId=File.FilenameId";
+#else
const char *uar_jobid_fileindex_from_dir =
"SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client "
"WHERE Job.JobId IN (%s) "
"AND Path.PathId=File.Pathid "
"AND Filename.FilenameId=File.FilenameId "
"GROUP BY File.FileIndex ";
+#endif
+/* Query to get list of files from table -- presuably built by an external program */
+const char *uar_jobid_fileindex_from_table =
+ "SELECT JobId, FileIndex from %s";