From: Robert Nelson Date: Sat, 5 Aug 2006 10:29:01 +0000 (+0000) Subject: A better fix for the WIN32_VSS bug that Kern discovered. X-Git-Tag: Release-2.0.0~665 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=887d2df8482ff61393b5a2fb78c46f862ba95e30;p=bacula%2Fbacula A better fix for the WIN32_VSS bug that Kern discovered. Create a separate DLL for each database interface. Then rename it to bacula_cats.dll during installation. Move sql_cmd.c from src/dird to src/cats. Create a header file for the constants exported from sql_cmd.c. Removed local extern definitions from cats *.c files, put them in sql_cmd.h. Added Windows version of the database scripts. In some cases these scripts are placeholders and more work is needed to make them execute. Eliminated the need to install the database dlls in a client only installation. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3240 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index a4a839b6bb..4debd4f444 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -71,6 +71,7 @@ void InitWinAPIWrapper(); #define OSDependentInit() InitWinAPIWrapper() #undef ENABLE_NLS + #if defined(BUILDING_DLL) # define DLL_IMP_EXP _declspec(dllexport) #elif defined(USING_DLL) @@ -79,9 +80,16 @@ void InitWinAPIWrapper(); # define DLL_IMP_EXP #endif +#if defined(USING_CATS) +# define CATS_IMP_EXP _declspec(dllimport) +#else +# define CATS_IMP_EXP +#endif + #else #define DLL_IMP_EXP +#define CATS_IMP_EXP #define OSDependentInit() #define tape_open open diff --git a/bacula/src/cats/Makefile.in b/bacula/src/cats/Makefile.in index 0a3495610e..564d503ce1 100644 --- a/bacula/src/cats/Makefile.in +++ b/bacula/src/cats/Makefile.in @@ -25,12 +25,12 @@ SVROBJS = cats.o sql.o LIBSRCS = mysql.c bdb.c bdb_create.c bdb_get.c bdb_update.c \ bdb_delete.c bdb_find.c bdb_list.c \ - sql.c sql_create.c sql_delete.c sql_find.c \ + sql.c sql_cmds.c sql_create.c sql_delete.c sql_find.c \ sql_get.c sql_list.c sql_update.c sqlite.c \ postgresql.c LIBOBJS = mysql.o bdb.o bdb_create.o bdb_get.o bdb_update.o \ bdb_delete.o bdb_find.o bdb_list.o \ - sql.o sql_create.o sql_delete.o sql_find.o \ + sql.o sql_cmds.o sql_create.o sql_delete.o sql_find.o \ sql_get.o sql_list.o sql_update.o sqlite.o \ postgresql.o diff --git a/bacula/src/cats/bdb.c b/bacula/src/cats/bdb.c index 3aa57c220d..ddf659fd37 100644 --- a/bacula/src/cats/bdb.c +++ b/bacula/src/cats/bdb.c @@ -39,10 +39,6 @@ uint32_t bacula_db_version = 0; -/* Forward referenced functions */ - -extern const char *working_directory; - /* List of open databases */ static BQUEUE db_list = {&db_list, &db_list}; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; diff --git a/bacula/src/cats/bdb_update.c b/bacula/src/cats/bdb_update.c index 35fa610a89..c6ee9fd57e 100755 --- a/bacula/src/cats/bdb_update.c +++ b/bacula/src/cats/bdb_update.c @@ -41,8 +41,6 @@ #ifdef HAVE_BACULA_DB -/* Forward referenced functions */ - /* ----------------------------------------------------------------------- * * Bacula specific defines and subroutines @@ -217,5 +215,9 @@ int db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) return 1; } +void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) +{ + return; +} #endif /* HAVE_BACULA_DB */ diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index 1d47ae6d06..2eda36734b 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -795,16 +795,24 @@ struct db_int64_ctx { #include "protos.h" #include "jcr.h" +#include "sql_cmds.h" /* * Some functions exported by sql.c for use within the * cats directory. */ -void list_result(B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type type); +void list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type type); void list_dashes(B_DB *mdb, DB_LIST_HANDLER *send, void *ctx); int get_sql_record_max(JCR *jcr, B_DB *mdb); bool check_tables_version(JCR *jcr, B_DB *mdb); void _db_unlock(const char *file, int line, B_DB *mdb); void _db_lock(const char *file, int line, B_DB *mdb); +void print_dashes(B_DB *mdb); +void print_result(B_DB *mdb); +int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd); +int InsertDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd); +int DeleteDB(const char *file, int line, JCR *jcr, B_DB *db, char *delete_cmd); +int UpdateDB(const char *file, int line, JCR *jcr, B_DB *db, char *update_cmd); +void split_path_and_file(JCR *jcr, B_DB *mdb, const char *fname); #endif /* __SQL_H_ */ diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c new file mode 100644 index 0000000000..1525fffb75 --- /dev/null +++ b/bacula/src/cats/sql_cmds.c @@ -0,0 +1,395 @@ +/* + * + * This file contains all the SQL commands issued by the Director + * + * Kern Sibbald, July MMII + * + * Version $Id$ + */ +/* + 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 + 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 + the file LICENSE for additional details. + + */ + +#include "bacula.h" +#include "cats.h" + +/* For ua_cmds.c */ +const char *list_pool = "SELECT * FROM Pool WHERE PoolId=%s"; + +/* For ua_dotcmds.c */ +const char *client_backups = + "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 Type='B'" + " AND JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId" + " AND Job.FileSetId=FileSet.FileSetId" + " ORDER BY Job.StartTime"; + + +/* ====== ua_prune.c */ + +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"; + +/* Select JobIds for File deletion. */ +const char *select_job = + "SELECT JobId from Job " + "WHERE JobTDate<%s " + "AND ClientId=%s " + "AND PurgedFiles=0"; + +/* Delete temp tables and indexes */ +const char *drop_deltabs[] = { + "DROP TABLE DelCandidates", + "DROP INDEX DelInx1", + NULL}; + + +/* List of SQL commands to create temp table and indicies */ +const char *create_deltabs[] = { + "CREATE TEMPORARY TABLE DelCandidates (" +#if defined(HAVE_MYSQL) + "JobId INTEGER UNSIGNED NOT NULL, " + "PurgedFiles TINYINT, " + "FileSetId INTEGER UNSIGNED, " + "JobFiles INTEGER UNSIGNED, " + "JobStatus BINARY(1))", +#elif defined(HAVE_POSTGRESQL) + "JobId INTEGER NOT NULL, " + "PurgedFiles SMALLINT, " + "FileSetId INTEGER, " + "JobFiles INTEGER, " + "JobStatus char(1))", +#else + "JobId INTEGER UNSIGNED NOT NULL, " + "PurgedFiles TINYINT, " + "FileSetId INTEGER UNSIGNED, " + "JobFiles INTEGER UNSIGNED, " + "JobStatus CHAR)", +#endif + "CREATE INDEX DelInx1 ON DelCandidates (JobId)", + NULL}; + +/* Fill candidates table with all Jobs subject to being deleted. + * This is used for pruning Jobs (first the files, then the Jobs). + */ +const char *insert_delcand = + "INSERT INTO DelCandidates " + "SELECT JobId,PurgedFiles,FileSetId,JobFiles,JobStatus FROM Job " + "WHERE Type='%c' " + "AND JobTDate<%s " + "AND ClientId=%s"; + +/* Select Jobs from the DelCandidates table that have a + * more recent backup -- i.e. are not the only backup. + * This is the list of Jobs to delete for a Backup Job. + * At the same time, we select "orphanned" jobs + * (i.e. no files, ...) for deletion. + */ +const char *select_backup_del = + "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles " + "FROM Job,DelCandidates " + "WHERE (Job.JobTDate<%s AND ((DelCandidates.JobFiles=0) OR " + "(DelCandidates.JobStatus!='T'))) OR " + "(Job.JobTDate>%s " + "AND Job.ClientId=%s " + "AND Job.Level='F' AND Job.JobStatus='T' AND Job.Type='B' " + "AND Job.FileSetId=DelCandidates.FileSetId)"; + +/* Select Jobs from the DelCandidates table that have a + * more recent InitCatalog -- i.e. are not the only InitCatalog + * This is the list of Jobs to delete for a Verify Job. + */ +const char *select_verify_del = + "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles " + "FROM Job,DelCandidates " + "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR " + "(Job.JobTDate>%s " + "AND Job.ClientId=%s " + "AND Job.Type='V' AND Job.Level='V' AND Job.JobStatus='T' " + "AND Job.FileSetId=DelCandidates.FileSetId)"; + + +/* Select Jobs from the DelCandidates table. + * This is the list of Jobs to delete for a Restore Job. + */ +const char *select_restore_del = + "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles " + "FROM Job,DelCandidates " + "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR " + "(Job.JobTDate>%s " + "AND Job.ClientId=%s " + "AND Job.Type='R')"; + +/* Select Jobs from the DelCandidates table. + * This is the list of Jobs to delete for an Admin Job. + */ +const char *select_admin_del = + "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles " + "FROM Job,DelCandidates " + "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR " + "(Job.JobTDate>%s " + "AND Job.ClientId=%s " + "AND Job.Type='D')"; + + +/* ======= ua_restore.c */ +const char *uar_count_files = + "SELECT JobFiles FROM Job WHERE JobId=%s"; + +/* List last 20 Jobs */ +const char *uar_list_jobs = + "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' ORDER BY StartTime DESC LIMIT 20"; + +#ifdef HAVE_MYSQL +/* MYSQL IS NOT STANDARD SQL !!!!! */ +/* List Jobs where a particular file is saved */ +const char *uar_file = + "SELECT Job.JobId as JobId," + "CONCAT(Path.Path,Filename.Name) as Name, " + "StartTime,Type as JobType,JobStatus,JobFiles,JobBytes " + "FROM Client,Job,File,Filename,Path WHERE Client.Name='%s' " + "AND Client.ClientId=Job.ClientId " + "AND Job.JobId=File.JobId " + "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId " + "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20"; +#else +/* List Jobs where a particular file is saved */ +const char *uar_file = + "SELECT Job.JobId as JobId," + "Path.Path||Filename.Name as Name, " + "StartTime,Type as JobType,JobStatus,JobFiles,JobBytes " + "FROM Client,Job,File,Filename,Path WHERE Client.Name='%s' " + "AND Client.ClientId=Job.ClientId " + "AND Job.JobId=File.JobId " + "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId " + "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20"; +#endif + + +/* + * Find all files for a particular JobId and insert them into + * the tree during a restore. + */ +const char *uar_sel_files = + "SELECT Path.Path,Filename.Name,FileIndex,JobId,LStat " + "FROM File,Filename,Path " + "WHERE File.JobId=%s AND Filename.FilenameId=File.FilenameId " + "AND Path.PathId=File.PathId"; + +const char *uar_del_temp = "DROP TABLE temp"; +const char *uar_del_temp1 = "DROP TABLE temp1"; + +const char *uar_create_temp = + "CREATE TEMPORARY TABLE temp (" +#ifdef HAVE_POSTGRESQL + "JobId INTEGER NOT NULL," + "JobTDate BIGINT," + "ClientId INTEGER," + "Level CHAR," + "JobFiles INTEGER," + "JobBytes BIGINT," + "StartTime TEXT," + "VolumeName TEXT," + "StartFile INTEGER," + "VolSessionId INTEGER," + "VolSessionTime INTEGER)"; +#else + "JobId INTEGER UNSIGNED NOT NULL," + "JobTDate BIGINT UNSIGNED," + "ClientId INTEGER UNSIGNED," + "Level CHAR," + "JobFiles INTEGER UNSIGNED," + "JobBytes BIGINT UNSIGNED," + "StartTime TEXT," + "VolumeName TEXT," + "StartFile INTEGER UNSIGNED," + "VolSessionId INTEGER UNSIGNED," + "VolSessionTime INTEGER UNSIGNED)"; +#endif + +const char *uar_create_temp1 = + "CREATE TEMPORARY TABLE temp1 (" +#ifdef HAVE_POSTGRESQL + "JobId INTEGER NOT NULL," + "JobTDate BIGINT)"; +#else + "JobId INTEGER UNSIGNED NOT NULL," + "JobTDate BIGINT UNSIGNED)"; +#endif + +const char *uar_last_full = + "INSERT INTO temp1 SELECT Job.JobId,JobTdate " + "FROM Client,Job,JobMedia,Media,FileSet WHERE Client.ClientId=%s " + "AND Job.ClientId=%s " + "AND Job.StartTime<'%s' " + "AND Level='F' AND JobStatus='T' AND Type='B' " + "AND JobMedia.JobId=Job.JobId " + "AND JobMedia.MediaId=Media.MediaId " + "AND Job.FileSetId=FileSet.FileSetId " + "AND FileSet.FileSet='%s' " + "%s" + "ORDER BY Job.JobTDate DESC LIMIT 1"; + +const char *uar_full = + "INSERT INTO temp SELECT Job.JobId,Job.JobTDate," + "Job.ClientId,Job.Level,Job.JobFiles,Job.JobBytes," + "StartTime,VolumeName,JobMedia.StartFile,VolSessionId,VolSessionTime " + "FROM temp1,Job,JobMedia,Media WHERE temp1.JobId=Job.JobId " + "AND Level='F' AND JobStatus='T' AND Type='B' " + "AND JobMedia.JobId=Job.JobId " + "AND JobMedia.MediaId=Media.MediaId"; + +const char *uar_dif = + "INSERT INTO temp SELECT Job.JobId,Job.JobTDate,Job.ClientId," + "Job.Level,Job.JobFiles,Job.JobBytes," + "Job.StartTime,Media.VolumeName,JobMedia.StartFile," + "Job.VolSessionId,Job.VolSessionTime " + "FROM Job,JobMedia,Media,FileSet " + "WHERE Job.JobTDate>%s AND Job.StartTime<'%s' " + "AND Job.ClientId=%s " + "AND JobMedia.JobId=Job.JobId " + "AND JobMedia.MediaId=Media.MediaId " + "AND Job.Level='D' AND JobStatus='T' AND Type='B' " + "AND Job.FileSetId=FileSet.FileSetId " + "AND FileSet.FileSet='%s' " + "%s" + "ORDER BY Job.JobTDate DESC LIMIT 1"; + +const char *uar_inc = + "INSERT INTO temp SELECT Job.JobId,Job.JobTDate,Job.ClientId," + "Job.Level,Job.JobFiles,Job.JobBytes," + "Job.StartTime,Media.VolumeName,JobMedia.StartFile," + "Job.VolSessionId,Job.VolSessionTime " + "FROM Job,JobMedia,Media,FileSet " + "WHERE Job.JobTDate>%s AND Job.StartTime<'%s' " + "AND Job.ClientId=%s " + "AND JobMedia.JobId=Job.JobId " + "AND JobMedia.MediaId=Media.MediaId " + "AND Job.Level='I' AND JobStatus='T' AND Type='B' " + "AND Job.FileSetId=FileSet.FileSetId " + "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"; + +const char *uar_sel_all_temp1 = "SELECT * FROM temp1"; + +const char *uar_sel_all_temp = "SELECT * FROM temp"; + + + +/* Select FileSet names for this Client */ +const char *uar_sel_fileset = + "SELECT DISTINCT FileSet.FileSet FROM Job," + "Client,FileSet WHERE Job.FileSetId=FileSet.FileSetId " + "AND Job.ClientId=%s AND Client.ClientId=%s " + "ORDER BY FileSet.FileSet"; + +/* Find MediaType used by this Job */ +const char *uar_mediatype = + "SELECT MediaType FROM JobMedia,Media WHERE JobMedia.JobId=%s " + "AND JobMedia.MediaId=Media.MediaId"; + +/* + * Find JobId, FileIndex for a given path/file and date + * for use when inserting individual files into the tree. + */ +const char *uar_jobid_fileindex = + "SELECT Job.JobId, File.FileIndex FROM Job,File,Path,Filename,Client " + "WHERE Job.JobId=File.JobId " + "AND Job.StartTime<'%s' " + "AND Path.Path='%s' " + "AND Filename.Name='%s' " + "AND Client.Name='%s' " + "AND Job.ClientId=Client.ClientId " + "AND Path.PathId=File.PathId " + "AND Filename.FilenameId=File.FilenameId " + "ORDER BY Job.StartTime DESC LIMIT 1"; + +const char *uar_jobids_fileindex = + "SELECT Job.JobId, File.FileIndex FROM Job,File,Path,Filename,Client " + "WHERE Job.JobId IN (%s) " + "AND Job.JobId=File.JobId " + "AND Job.StartTime<'%s' " + "AND Path.Path='%s' " + "AND Filename.Name='%s' " + "AND Client.Name='%s' " + "AND Job.ClientId=Client.ClientId " + "AND Path.PathId=File.PathId " + "AND Filename.FilenameId=File.FilenameId " + "ORDER BY Job.StartTime DESC LIMIT 1"; + +/* 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 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 " + "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"; diff --git a/bacula/src/cats/sql_cmds.h b/bacula/src/cats/sql_cmds.h new file mode 100644 index 0000000000..40b8498370 --- /dev/null +++ b/bacula/src/cats/sql_cmds.h @@ -0,0 +1,58 @@ +/* + Copyright (C) 2000-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 + 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 + the file LICENSE for additional details. + + */ + +extern const char CATS_IMP_EXP *client_backups; +extern const char CATS_IMP_EXP *list_pool; +extern const char CATS_IMP_EXP *drop_deltabs[]; +extern const char CATS_IMP_EXP *create_deltabs[]; +extern const char CATS_IMP_EXP *insert_delcand; +extern const char CATS_IMP_EXP *select_backup_del; +extern const char CATS_IMP_EXP *select_verify_del; +extern const char CATS_IMP_EXP *select_restore_del; +extern const char CATS_IMP_EXP *select_admin_del; +extern const char CATS_IMP_EXP *select_job; +extern const char CATS_IMP_EXP *del_File; +extern const char CATS_IMP_EXP *cnt_File; +extern const char CATS_IMP_EXP *cnt_DelCand; +extern const char CATS_IMP_EXP *del_Job; +extern const char CATS_IMP_EXP *del_MAC; +extern const char CATS_IMP_EXP *del_JobMedia; +extern const char CATS_IMP_EXP *cnt_JobMedia; +extern const char CATS_IMP_EXP *sel_JobMedia; +extern const char CATS_IMP_EXP *upd_Purged; + +extern const char CATS_IMP_EXP *uar_list_jobs; +extern const char CATS_IMP_EXP *uar_file; +extern const char CATS_IMP_EXP *uar_count_files; +extern const char CATS_IMP_EXP *uar_sel_files; +extern const char CATS_IMP_EXP *uar_del_temp; +extern const char CATS_IMP_EXP *uar_del_temp1; +extern const char CATS_IMP_EXP *uar_create_temp; +extern const char CATS_IMP_EXP *uar_create_temp1; +extern const char CATS_IMP_EXP *uar_last_full; +extern const char CATS_IMP_EXP *uar_full; +extern const char CATS_IMP_EXP *uar_inc; +extern const char CATS_IMP_EXP *uar_list_temp; +extern const char CATS_IMP_EXP *uar_sel_all_temp1; +extern const char CATS_IMP_EXP *uar_sel_fileset; +extern const char CATS_IMP_EXP *uar_mediatype; +extern const char CATS_IMP_EXP *uar_jobid_fileindex; +extern const char CATS_IMP_EXP *uar_dif; +extern const char CATS_IMP_EXP *uar_sel_all_temp; +extern const char CATS_IMP_EXP *uar_count_files; +extern const char CATS_IMP_EXP *uar_jobids_fileindex; +extern const char CATS_IMP_EXP *uar_jobid_fileindex_from_dir; +extern const char CATS_IMP_EXP *uar_jobid_fileindex_from_table; +extern const char CATS_IMP_EXP *uar_sel_jobid_temp; diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 43d22aabd9..d38043aa45 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -45,15 +45,6 @@ static int db_create_filename_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); static int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); -/* Imported subroutines */ -extern void print_dashes(B_DB *mdb); -extern void print_result(B_DB *mdb); -extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd); -extern int InsertDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd); -extern int UpdateDB(const char *file, int line, JCR *jcr, B_DB *db, char *update_cmd); -extern void split_path_and_file(JCR *jcr, B_DB *mdb, const char *fname); - - /* Create a new record for the Job * Returns: false on failure * true on success diff --git a/bacula/src/cats/sql_delete.c b/bacula/src/cats/sql_delete.c index c4641ff4f6..ef5904b840 100644 --- a/bacula/src/cats/sql_delete.c +++ b/bacula/src/cats/sql_delete.c @@ -40,12 +40,6 @@ * ----------------------------------------------------------------------- */ -/* Imported subroutines */ -extern void print_dashes(B_DB *mdb); -extern void print_result(B_DB *mdb); -extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd); -extern int DeleteDB(const char *file, int line, JCR *jcr, B_DB *db, char *delete_cmd); - /* * Delete Pool record, must also delete all associated * Media records. diff --git a/bacula/src/cats/sql_find.c b/bacula/src/cats/sql_find.c index e11a0e0c5f..8d7c9d442f 100644 --- a/bacula/src/cats/sql_find.c +++ b/bacula/src/cats/sql_find.c @@ -43,10 +43,6 @@ * ----------------------------------------------------------------------- */ -/* Imported subroutines */ -extern void print_result(B_DB *mdb); -extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd); - /* * Find job start time if JobId specified, otherwise * find last full save for Incremental and Differential saves. diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 0fcc2dabd5..74c03435e2 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -48,13 +48,6 @@ static int db_get_filename_record(JCR *jcr, B_DB *mdb); static int db_get_path_record(JCR *jcr, B_DB *mdb); -/* Imported subroutines */ -extern void print_result(B_DB *mdb); -extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd); -extern void split_path_and_file(JCR *jcr, B_DB *mdb, const char *fname); - - - /* * Given a full filename (with path), look up the File record * (with attributes) in the database. diff --git a/bacula/src/cats/sql_list.c b/bacula/src/cats/sql_list.c index 2eff15952a..b9a138a16f 100644 --- a/bacula/src/cats/sql_list.c +++ b/bacula/src/cats/sql_list.c @@ -37,11 +37,6 @@ * ----------------------------------------------------------------------- */ -/* Imported subroutines */ -extern void list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type); -extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd); - - /* * Submit general SQL query */ diff --git a/bacula/src/cats/sql_update.c b/bacula/src/cats/sql_update.c index b276c671bd..d526ad2845 100644 --- a/bacula/src/cats/sql_update.c +++ b/bacula/src/cats/sql_update.c @@ -37,10 +37,6 @@ * ----------------------------------------------------------------------- */ -/* Imported subroutines */ -extern void print_result(B_DB *mdb); -extern int UpdateDB(const char *file, int line, JCR *jcr, B_DB *db, char *update_cmd); - /* ----------------------------------------------------------------------- * * Generic Routines (or almost generic) @@ -445,13 +441,4 @@ db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) } } -#else - -void -db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) -{ - /* DUMMY func for Bacula_DB */ - return; -} - #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL*/ diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index edc465d37a..34f2c136e8 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -39,8 +39,6 @@ * ----------------------------------------------------------------------- */ -extern const char *working_directory; - /* List of open databases */ static BQUEUE db_list = {&db_list, &db_list}; diff --git a/bacula/src/dird/Makefile.in b/bacula/src/dird/Makefile.in index f1218a1414..7e417b07fb 100644 --- a/bacula/src/dird/Makefile.in +++ b/bacula/src/dird/Makefile.in @@ -38,7 +38,7 @@ SVRSRCS = dird.c admin.c authenticate.c \ mountreq.c msgchan.c next_vol.c newvol.c \ pythondir.c \ recycle.c restore.c run_conf.c \ - scheduler.c sql_cmds.c \ + scheduler.c \ ua_acl.c ua_cmds.c ua_dotcmds.c \ ua_query.c \ ua_input.c ua_label.c ua_output.c ua_prune.c \ @@ -53,7 +53,7 @@ SVROBJS = dird.o admin.o authenticate.o \ mountreq.o msgchan.o next_vol.o newvol.o \ pythondir.o \ recycle.o restore.o run_conf.o \ - scheduler.o sql_cmds.o \ + scheduler.o \ ua_acl.o ua_cmds.o ua_dotcmds.o \ ua_query.o \ ua_input.o ua_label.o ua_output.o ua_prune.o \ diff --git a/bacula/src/dird/sql_cmds.c b/bacula/src/dird/sql_cmds.c deleted file mode 100644 index e0f97192e5..0000000000 --- a/bacula/src/dird/sql_cmds.c +++ /dev/null @@ -1,395 +0,0 @@ -/* - * - * This file contains all the SQL commands issued by the Director - * - * Kern Sibbald, July MMII - * - * Version $Id$ - */ -/* - 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 - 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 - the file LICENSE for additional details. - - */ - -#include "bacula.h" -#include "dird.h" - -/* For ua_cmds.c */ -const char *list_pool = "SELECT * FROM Pool WHERE PoolId=%s"; - -/* For ua_dotcmds.c */ -const char *client_backups = - "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 Type='B'" - " AND JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId" - " AND Job.FileSetId=FileSet.FileSetId" - " ORDER BY Job.StartTime"; - - -/* ====== ua_prune.c */ - -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"; - -/* Select JobIds for File deletion. */ -const char *select_job = - "SELECT JobId from Job " - "WHERE JobTDate<%s " - "AND ClientId=%s " - "AND PurgedFiles=0"; - -/* Delete temp tables and indexes */ -const char *drop_deltabs[] = { - "DROP TABLE DelCandidates", - "DROP INDEX DelInx1", - NULL}; - - -/* List of SQL commands to create temp table and indicies */ -const char *create_deltabs[] = { - "CREATE TEMPORARY TABLE DelCandidates (" -#if defined(HAVE_MYSQL) - "JobId INTEGER UNSIGNED NOT NULL, " - "PurgedFiles TINYINT, " - "FileSetId INTEGER UNSIGNED, " - "JobFiles INTEGER UNSIGNED, " - "JobStatus BINARY(1))", -#elif defined(HAVE_POSTGRESQL) - "JobId INTEGER NOT NULL, " - "PurgedFiles SMALLINT, " - "FileSetId INTEGER, " - "JobFiles INTEGER, " - "JobStatus char(1))", -#else - "JobId INTEGER UNSIGNED NOT NULL, " - "PurgedFiles TINYINT, " - "FileSetId INTEGER UNSIGNED, " - "JobFiles INTEGER UNSIGNED, " - "JobStatus CHAR)", -#endif - "CREATE INDEX DelInx1 ON DelCandidates (JobId)", - NULL}; - -/* Fill candidates table with all Jobs subject to being deleted. - * This is used for pruning Jobs (first the files, then the Jobs). - */ -const char *insert_delcand = - "INSERT INTO DelCandidates " - "SELECT JobId,PurgedFiles,FileSetId,JobFiles,JobStatus FROM Job " - "WHERE Type='%c' " - "AND JobTDate<%s " - "AND ClientId=%s"; - -/* Select Jobs from the DelCandidates table that have a - * more recent backup -- i.e. are not the only backup. - * This is the list of Jobs to delete for a Backup Job. - * At the same time, we select "orphanned" jobs - * (i.e. no files, ...) for deletion. - */ -const char *select_backup_del = - "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles " - "FROM Job,DelCandidates " - "WHERE (Job.JobTDate<%s AND ((DelCandidates.JobFiles=0) OR " - "(DelCandidates.JobStatus!='T'))) OR " - "(Job.JobTDate>%s " - "AND Job.ClientId=%s " - "AND Job.Level='F' AND Job.JobStatus='T' AND Job.Type='B' " - "AND Job.FileSetId=DelCandidates.FileSetId)"; - -/* Select Jobs from the DelCandidates table that have a - * more recent InitCatalog -- i.e. are not the only InitCatalog - * This is the list of Jobs to delete for a Verify Job. - */ -const char *select_verify_del = - "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles " - "FROM Job,DelCandidates " - "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR " - "(Job.JobTDate>%s " - "AND Job.ClientId=%s " - "AND Job.Type='V' AND Job.Level='V' AND Job.JobStatus='T' " - "AND Job.FileSetId=DelCandidates.FileSetId)"; - - -/* Select Jobs from the DelCandidates table. - * This is the list of Jobs to delete for a Restore Job. - */ -const char *select_restore_del = - "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles " - "FROM Job,DelCandidates " - "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR " - "(Job.JobTDate>%s " - "AND Job.ClientId=%s " - "AND Job.Type='R')"; - -/* Select Jobs from the DelCandidates table. - * This is the list of Jobs to delete for an Admin Job. - */ -const char *select_admin_del = - "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles " - "FROM Job,DelCandidates " - "WHERE (Job.JobTdate<%s AND DelCandidates.JobStatus!='T') OR " - "(Job.JobTDate>%s " - "AND Job.ClientId=%s " - "AND Job.Type='D')"; - - -/* ======= ua_restore.c */ -const char *uar_count_files = - "SELECT JobFiles FROM Job WHERE JobId=%s"; - -/* List last 20 Jobs */ -const char *uar_list_jobs = - "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' ORDER BY StartTime DESC LIMIT 20"; - -#ifdef HAVE_MYSQL -/* MYSQL IS NOT STANDARD SQL !!!!! */ -/* List Jobs where a particular file is saved */ -const char *uar_file = - "SELECT Job.JobId as JobId," - "CONCAT(Path.Path,Filename.Name) as Name, " - "StartTime,Type as JobType,JobStatus,JobFiles,JobBytes " - "FROM Client,Job,File,Filename,Path WHERE Client.Name='%s' " - "AND Client.ClientId=Job.ClientId " - "AND Job.JobId=File.JobId " - "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId " - "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20"; -#else -/* List Jobs where a particular file is saved */ -const char *uar_file = - "SELECT Job.JobId as JobId," - "Path.Path||Filename.Name as Name, " - "StartTime,Type as JobType,JobStatus,JobFiles,JobBytes " - "FROM Client,Job,File,Filename,Path WHERE Client.Name='%s' " - "AND Client.ClientId=Job.ClientId " - "AND Job.JobId=File.JobId " - "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId " - "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20"; -#endif - - -/* - * Find all files for a particular JobId and insert them into - * the tree during a restore. - */ -const char *uar_sel_files = - "SELECT Path.Path,Filename.Name,FileIndex,JobId,LStat " - "FROM File,Filename,Path " - "WHERE File.JobId=%s AND Filename.FilenameId=File.FilenameId " - "AND Path.PathId=File.PathId"; - -const char *uar_del_temp = "DROP TABLE temp"; -const char *uar_del_temp1 = "DROP TABLE temp1"; - -const char *uar_create_temp = - "CREATE TEMPORARY TABLE temp (" -#ifdef HAVE_POSTGRESQL - "JobId INTEGER NOT NULL," - "JobTDate BIGINT," - "ClientId INTEGER," - "Level CHAR," - "JobFiles INTEGER," - "JobBytes BIGINT," - "StartTime TEXT," - "VolumeName TEXT," - "StartFile INTEGER," - "VolSessionId INTEGER," - "VolSessionTime INTEGER)"; -#else - "JobId INTEGER UNSIGNED NOT NULL," - "JobTDate BIGINT UNSIGNED," - "ClientId INTEGER UNSIGNED," - "Level CHAR," - "JobFiles INTEGER UNSIGNED," - "JobBytes BIGINT UNSIGNED," - "StartTime TEXT," - "VolumeName TEXT," - "StartFile INTEGER UNSIGNED," - "VolSessionId INTEGER UNSIGNED," - "VolSessionTime INTEGER UNSIGNED)"; -#endif - -const char *uar_create_temp1 = - "CREATE TEMPORARY TABLE temp1 (" -#ifdef HAVE_POSTGRESQL - "JobId INTEGER NOT NULL," - "JobTDate BIGINT)"; -#else - "JobId INTEGER UNSIGNED NOT NULL," - "JobTDate BIGINT UNSIGNED)"; -#endif - -const char *uar_last_full = - "INSERT INTO temp1 SELECT Job.JobId,JobTdate " - "FROM Client,Job,JobMedia,Media,FileSet WHERE Client.ClientId=%s " - "AND Job.ClientId=%s " - "AND Job.StartTime<'%s' " - "AND Level='F' AND JobStatus='T' AND Type='B' " - "AND JobMedia.JobId=Job.JobId " - "AND JobMedia.MediaId=Media.MediaId " - "AND Job.FileSetId=FileSet.FileSetId " - "AND FileSet.FileSet='%s' " - "%s" - "ORDER BY Job.JobTDate DESC LIMIT 1"; - -const char *uar_full = - "INSERT INTO temp SELECT Job.JobId,Job.JobTDate," - "Job.ClientId,Job.Level,Job.JobFiles,Job.JobBytes," - "StartTime,VolumeName,JobMedia.StartFile,VolSessionId,VolSessionTime " - "FROM temp1,Job,JobMedia,Media WHERE temp1.JobId=Job.JobId " - "AND Level='F' AND JobStatus='T' AND Type='B' " - "AND JobMedia.JobId=Job.JobId " - "AND JobMedia.MediaId=Media.MediaId"; - -const char *uar_dif = - "INSERT INTO temp SELECT Job.JobId,Job.JobTDate,Job.ClientId," - "Job.Level,Job.JobFiles,Job.JobBytes," - "Job.StartTime,Media.VolumeName,JobMedia.StartFile," - "Job.VolSessionId,Job.VolSessionTime " - "FROM Job,JobMedia,Media,FileSet " - "WHERE Job.JobTDate>%s AND Job.StartTime<'%s' " - "AND Job.ClientId=%s " - "AND JobMedia.JobId=Job.JobId " - "AND JobMedia.MediaId=Media.MediaId " - "AND Job.Level='D' AND JobStatus='T' AND Type='B' " - "AND Job.FileSetId=FileSet.FileSetId " - "AND FileSet.FileSet='%s' " - "%s" - "ORDER BY Job.JobTDate DESC LIMIT 1"; - -const char *uar_inc = - "INSERT INTO temp SELECT Job.JobId,Job.JobTDate,Job.ClientId," - "Job.Level,Job.JobFiles,Job.JobBytes," - "Job.StartTime,Media.VolumeName,JobMedia.StartFile," - "Job.VolSessionId,Job.VolSessionTime " - "FROM Job,JobMedia,Media,FileSet " - "WHERE Job.JobTDate>%s AND Job.StartTime<'%s' " - "AND Job.ClientId=%s " - "AND JobMedia.JobId=Job.JobId " - "AND JobMedia.MediaId=Media.MediaId " - "AND Job.Level='I' AND JobStatus='T' AND Type='B' " - "AND Job.FileSetId=FileSet.FileSetId " - "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"; - -const char *uar_sel_all_temp1 = "SELECT * FROM temp1"; - -const char *uar_sel_all_temp = "SELECT * FROM temp"; - - - -/* Select FileSet names for this Client */ -const char *uar_sel_fileset = - "SELECT DISTINCT FileSet.FileSet FROM Job," - "Client,FileSet WHERE Job.FileSetId=FileSet.FileSetId " - "AND Job.ClientId=%s AND Client.ClientId=%s " - "ORDER BY FileSet.FileSet"; - -/* Find MediaType used by this Job */ -const char *uar_mediatype = - "SELECT MediaType FROM JobMedia,Media WHERE JobMedia.JobId=%s " - "AND JobMedia.MediaId=Media.MediaId"; - -/* - * Find JobId, FileIndex for a given path/file and date - * for use when inserting individual files into the tree. - */ -const char *uar_jobid_fileindex = - "SELECT Job.JobId, File.FileIndex FROM Job,File,Path,Filename,Client " - "WHERE Job.JobId=File.JobId " - "AND Job.StartTime<'%s' " - "AND Path.Path='%s' " - "AND Filename.Name='%s' " - "AND Client.Name='%s' " - "AND Job.ClientId=Client.ClientId " - "AND Path.PathId=File.PathId " - "AND Filename.FilenameId=File.FilenameId " - "ORDER BY Job.StartTime DESC LIMIT 1"; - -const char *uar_jobids_fileindex = - "SELECT Job.JobId, File.FileIndex FROM Job,File,Path,Filename,Client " - "WHERE Job.JobId IN (%s) " - "AND Job.JobId=File.JobId " - "AND Job.StartTime<'%s' " - "AND Path.Path='%s' " - "AND Filename.Name='%s' " - "AND Client.Name='%s' " - "AND Job.ClientId=Client.ClientId " - "AND Path.PathId=File.PathId " - "AND Filename.FilenameId=File.FilenameId " - "ORDER BY Job.StartTime DESC LIMIT 1"; - -/* 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 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 " - "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"; diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index f39d3a5d06..4200031817 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -32,7 +32,6 @@ extern int r_first; extern int r_last; extern struct s_res resources[]; -extern const char *client_backups; /* Imported functions */ extern void do_messages(UAContext *ua, const char *cmd); diff --git a/bacula/src/dird/ua_prune.c b/bacula/src/dird/ua_prune.c index 4e83cc50b7..39fc3b3989 100644 --- a/bacula/src/dird/ua_prune.c +++ b/bacula/src/dird/ua_prune.c @@ -32,24 +32,6 @@ #define MAX_DEL_LIST_LEN 2000000 -/* Imported variables */ -extern const char *select_job; -extern const char *drop_deltabs[]; -extern const char *create_deltabs[]; -extern const char *insert_delcand; -extern const char *select_backup_del; -extern const char *select_verify_del; -extern const char *select_restore_del; -extern const char *select_admin_del; -extern const char *cnt_File; -extern const char *cnt_DelCand; -extern const char *del_Job; -extern const char *del_MAC; -extern const char *del_JobMedia; -extern const char *cnt_JobMedia; -extern const char *sel_JobMedia; - - /* In memory list of JobIds */ struct s_file_del_ctx { JobId_t *JobId; diff --git a/bacula/src/dird/ua_purge.c b/bacula/src/dird/ua_purge.c index fd4bc81a69..f55e63f109 100644 --- a/bacula/src/dird/ua_purge.c +++ b/bacula/src/dird/ua_purge.c @@ -28,9 +28,6 @@ #include "bacula.h" #include "dird.h" -extern const char *del_File; -extern const char *upd_Purged; - /* Forward referenced functions */ static int purge_files_from_client(UAContext *ua, CLIENT *client); static int purge_jobs_from_client(UAContext *ua, CLIENT *client); diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index 24d0aba7b7..0ada4cf794 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -35,17 +35,6 @@ /* Imported functions */ extern void print_bsr(UAContext *ua, RBSR *bsr); -/* Imported variables */ -extern const char *uar_list_jobs, *uar_file, *uar_sel_files; -extern const char *uar_del_temp, *uar_del_temp1, *uar_create_temp; -extern const char *uar_create_temp1, *uar_last_full, *uar_full; -extern const char *uar_inc, *uar_list_temp, *uar_sel_jobid_temp; -extern const char *uar_sel_all_temp1, *uar_sel_fileset, *uar_mediatype; -extern const char *uar_jobid_fileindex, *uar_dif, *uar_sel_all_temp; -extern const char *uar_count_files, *uar_jobids_fileindex; -extern const char *uar_jobid_fileindex_from_dir; -extern const char *uar_jobid_fileindex_from_table; - /* Forward referenced functions */ diff --git a/bacula/src/dird/ua_update.c b/bacula/src/dird/ua_update.c index 58788a8b9c..c3191e377f 100644 --- a/bacula/src/dird/ua_update.c +++ b/bacula/src/dird/ua_update.c @@ -25,9 +25,6 @@ #include "bacula.h" #include "dird.h" -/* External variables */ -extern const char *list_pool; /* in sql_cmds.c */ - /* Imported functions */ void update_slots(UAContext *ua); diff --git a/bacula/src/win32/Makefile b/bacula/src/win32/Makefile index 235c6b1a83..9e8f133c45 100644 --- a/bacula/src/win32/Makefile +++ b/bacula/src/win32/Makefile @@ -1,6 +1,7 @@ ECHO_CMD=@ DIRS= dll \ + cats \ filed \ dird \ stored \ diff --git a/bacula/src/win32/Makefile.inc.in b/bacula/src/win32/Makefile.inc.in index 7b06f5648d..d9d7fce0bb 100644 --- a/bacula/src/win32/Makefile.inc.in +++ b/bacula/src/win32/Makefile.inc.in @@ -25,6 +25,7 @@ CXX = $(MINGW_BIN)/mingw32-g++ $(DEFINES) $(INCLUDES) AR := $(MINGW_BIN)/mingw32-ar RANLIB := $(MINGW_BIN)/mingw32-ranlib WINDRES := $(MINGW_BIN)/mingw32-windres +DLLTOOL := $(MINGW_BIN)/../mingw32/bin/dlltool OBJCPY := $(MINGW_BIN)/mingw32-objcopy NSIS_DIR := $(DEPKGS)/nsis @@ -47,9 +48,12 @@ LIBS_PTHREADS := \ LIBS_ZLIB := \ $(DEPKGS)/lib/libz.a -LIBS_SQL := \ +LIBS_MYSQL := \ $(DEPKGS)/lib/libmysql.a +LIBS_POSTGRESQL := \ + $(DEPKGS)/lib/libpq.a + LIBS_SSL := \ $(DEPKGS)/lib/libssl.dll.a @@ -60,6 +64,9 @@ LIBS_WX := \ $(DEPKGS)/lib/wx_dll/libwxmsw26_core.a \ $(DEPKGS)/lib/wx_dll/libwxbase26.a +LIBS_CATS := \ + $(LIBDIR)/libcats.a + LIBS_BACULA := \ $(LIBDIR)/libbacula.a @@ -68,8 +75,6 @@ HAVES := \ -DHAVE_MINGW \ -DHAVE_ZLIB_H \ -DHAVE_LIBZ \ - -DHAVE_MYSQL \ -DHAVE_CRYPTO \ - -DWIN32_VSS \ -DHAVE_OPENSSL \ -DHAVE_TLS diff --git a/bacula/src/win32/cats/.cvsignore b/bacula/src/win32/cats/.cvsignore new file mode 100644 index 0000000000..dfef40e6ae --- /dev/null +++ b/bacula/src/win32/cats/.cvsignore @@ -0,0 +1,6 @@ +*.o +*.d +libcats.exp +bdb +mysql +pgsql diff --git a/bacula/src/win32/cats/Makefile b/bacula/src/win32/cats/Makefile index 46b71a0670..39bb1dbcfe 100644 --- a/bacula/src/win32/cats/Makefile +++ b/bacula/src/win32/cats/Makefile @@ -1,49 +1,49 @@ # # Makefile for win32 bacula executables # Using MinGW cross-compiler on GNU/Linux -# -# Written for Bacula by Howard Thomson, April 2006 -# +# +# Written by Robert Nelson, June 2006 +# include ../Makefile.inc INCLUDES = \ - $(INCLUDE_GCC) \ - $(INCLUDE_MINGW) \ $(INCLUDE_PTHREADS) \ $(INCLUDE_BACULA) \ $(INCLUDE_ZLIB) \ - $(INCLUDE_VSS) \ - $(INCLUDE_ICONS) \ $(INCLUDE_OPENSSL) \ $(INCLUDE_MYSQL) DEFINES = \ - -DWIN32 \ $(HAVES) +VPATH = ../../cats + ###################################################################### -# Files in src/cats - -LIB_OBJS = \ - $(OBJDIR)/bdb.o \ - $(OBJDIR)/bdb_create.o \ - $(OBJDIR)/bdb_delete.o \ - $(OBJDIR)/bdb_find.o \ - $(OBJDIR)/bdb_get.o \ - $(OBJDIR)/bdb_list.o \ - $(OBJDIR)/bdb_update.o \ - $(OBJDIR)/mysql.o \ - $(OBJDIR)/postgresql.o \ - $(OBJDIR)/sql.o \ - $(OBJDIR)/sql_create.o \ - $(OBJDIR)/sql_delete.o \ - $(OBJDIR)/sql_find.o \ - $(OBJDIR)/sql_get.o \ - $(OBJDIR)/sql_list.o \ - $(OBJDIR)/sql_update.o \ - $(OBJDIR)/sqlite.o +# Files files in src/lib + +BDB_OBJS = \ + bdb.o \ + bdb_create.o \ + bdb_delete.o \ + bdb_find.o \ + bdb_get.o \ + bdb_list.o \ + bdb_update.o \ + +SQL_OBJS = \ + sql.o \ + sql_cmds.o \ + sql_create.o \ + sql_delete.o \ + sql_find.o \ + sql_get.o \ + sql_list.o \ + sql_update.o \ + +LIBS_DLL = \ + $(LIBS_BACULA) ###################################################################### @@ -51,23 +51,58 @@ LIB_OBJS = \ .PHONY: all clean -all: $(LIBDIR)/libcats.a +all: $(BINDIR)/cats_mysql.dll $(BINDIR)/cats_pgsql.dll $(BINDIR)/cats_bdb.dll clean: @echo "Cleaning `pwd`" - $(ECHO_CMD)rm -f $(OBJDIR)/*.[od] $(LIBDIR)/libcats.a + $(call clean_obj,$(addprefix $(OBJDIR)/mysql/,mysql.o $(SQL_OBJS))) + $(call clean_obj,$(addprefix $(OBJDIR)/pgsql/,postgresql.o $(SQL_OBJS))) + $(call clean_obj,$(addprefix $(OBJDIR)/bdb/,sql_cmds.o $(BDB_OBJS))) + $(call clean_exe,$(BINDIR)/cats_mysql.dll) + $(call clean_exe,$(BINDIR)/cats_pgsql.dll) + $(call clean_exe,$(BINDIR)/cats_bdb.dll) + $(ECHO_CMD)rm -f $(OBJDIR)/libcats.exp $(LIBDIR)/libcats.a -# -# Rules -# +$(LIBDIR)/libcats.a $(OBJDIR)/libcats.exp: bacula_cats.def + $(DLLTOOL) --dllname bacula_cats.dll --no-export-all-symbols --input-def bacula_cats.def --output-exp $(OBJDIR)/libcats.exp --output-lib $(LIBDIR)/libcats.a $^ + +$(BINDIR)/cats_mysql.dll: $(addprefix $(OBJDIR)/mysql/,mysql.o $(SQL_OBJS)) $(OBJDIR)/libcats.exp + @echo "Linking $@" + $(call checkdir,$@) + $(ECHO_CMD)$(CXX) $(LDFLAGS) -mdll -mwindows $^ $(LIBS_MYSQL) $(LIBS_DLL) -o $@ + +$(BINDIR)/cats_pgsql.dll: $(addprefix $(OBJDIR)/pgsql/,postgresql.o $(SQL_OBJS)) $(OBJDIR)/libcats.exp + @echo "Linking $@" + $(call checkdir,$@) + $(ECHO_CMD)$(CXX) $(LDFLAGS) -mdll -mwindows $^ $(LIBS_POSTGRESQL) $(LIBS_DLL) -o $@ -$(LIBDIR)/libcats.a: $(LIB_OBJS) - @echo "Updating archive $@" +$(BINDIR)/cats_bdb.dll: $(addprefix $(OBJDIR)/bdb/,sql_cmds.o $(BDB_OBJS)) $(OBJDIR)/libcats.exp + @echo "Linking $@" $(call checkdir,$@) - $(ECHO_CMD)$(AR) rs $@ $^ $(LIB_OBJS) + $(ECHO_CMD)$(CXX) $(LDFLAGS) -mdll -mwindows $^ $(LIBS_DLL) -o $@ + +# +# Rules for generating from ../cats +# include ../Makefile.rules -ifneq ($(MAKECMDGOALS),clean) -include $(patsubst %.o,%.d,$(filter-out %.res,$(LIB_OBJS))) -endif +define Link_Dll +$(OBJDIR)/$(1)/%.o: %.c + @echo "Compiling $$<" + $$(call checkdir,$$@) + $(ECHO_CMD)$(CXX) -DBUILDING_CATS -DUSING_DLL -DHAVE_$(2) $(CFLAGS) -c $$< -o $$@ + +$(OBJDIR)/$(1)/%.o: %.cpp + @echo "Compiling $$<" + $$(call checkdir,$$@) + $(ECHO_CMD)$(CXX) -DBUILDING_CATS -DUSING_DLL -DHAVE_$(2) $(CFLAGS) -c $$< -o $$@ + +endef + +$(eval $(call Link_Dll,mysql,MYSQL)) + +$(eval $(call Link_Dll,pgsql,POSTGRESQL)) + +$(eval $(call Link_Dll,bdb,BACULA_DB)) + diff --git a/bacula/src/win32/cats/bacula_cats.def b/bacula/src/win32/cats/bacula_cats.def new file mode 100644 index 0000000000..1cc08cfb6c --- /dev/null +++ b/bacula/src/win32/cats/bacula_cats.def @@ -0,0 +1,143 @@ +LIBRARY bacula_cats.dll +EXPORTS + +; bdb.c: +; mysql.c: +; postgresql.c: +; sqlite.c: +_Z12db_sql_queryP4B_DBPKcPFiPviPPcES3_ +;_Z13db_next_indexP3JCRP4B_DBPcS3_ +_Z16db_escape_stringPcS_i +_Z16db_init_databaseP3JCRPKcS2_S2_S2_iS2_i +_Z16db_open_databaseP3JCRP4B_DB +_Z17db_close_databaseP3JCRP4B_DB + +; sql.c: +_Z10_db_unlockPKciP4B_DB +_Z11db_strerrorP4B_DB +;_Z11list_dashesP4B_DBPFvPvPKcES1_ +;_Z11list_resultP3JCRP4B_DBPFvPvPKcES3_11e_list_type +_Z16db_int64_handlerPviPPc +_Z18db_end_transactionP3JCRP4B_DB +;_Z18get_sql_record_maxP3JCRP4B_DB +;_Z19split_path_and_fileP3JCRP4B_DBPKc +;_Z20check_tables_versionP3JCRP4B_DB +_Z20db_start_transactionP3JCRP4B_DB +;_Z7QueryDBPKciP3JCRP4B_DBPc +_Z8_db_lockPKciP4B_DB +;_Z8DeleteDBPKciP3JCRP4B_DBPc +;_Z8InsertDBPKciP3JCRP4B_DBPc +;_Z8UpdateDBPKciP3JCRP4B_DBPc + +; bdb_create.c: +; sql_create.c: +_Z20db_create_job_recordP3JCRP4B_DBP7JOB_DBR +_Z21db_create_pool_recordP3JCRP4B_DBP8POOL_DBR +_Z22db_create_media_recordP3JCRP4B_DBP9MEDIA_DBR +_Z23db_create_client_recordP3JCRP4B_DBP10CLIENT_DBR +;_Z23db_create_device_recordP3JCRP4B_DBP10DEVICE_DBR +_Z24db_create_counter_recordP3JCRP4B_DBP11COUNTER_DBR +_Z24db_create_fileset_recordP3JCRP4B_DBP11FILESET_DBR +_Z24db_create_storage_recordP3JCRP4B_DBP11STORAGE_DBR +_Z25db_create_jobmedia_recordP3JCRP4B_DBP12JOBMEDIA_DBR +_Z26db_create_mediatype_recordP3JCRP4B_DBP13MEDIATYPE_DBR +_Z32db_create_file_attributes_recordP3JCRP4B_DBP8ATTR_DBR + +; bdb_delete.c: +; sql_delete.c: +_Z21db_delete_pool_recordP3JCRP4B_DBP8POOL_DBR +;_Z21db_purge_media_recordP3JCRP4B_DBP9MEDIA_DBR +_Z22db_delete_media_recordP3JCRP4B_DBP9MEDIA_DBR + +; bdb_find.c: +; sql_find.c: +_Z18db_find_last_jobidP3JCRP4B_DBPKcP7JOB_DBR +_Z19db_find_next_volumeP3JCRP4B_DBibP9MEDIA_DBR +_Z22db_find_job_start_timeP3JCRP4B_DBP7JOB_DBRPPc +_Z24db_find_failed_job_sinceP3JCRP4B_DBP7JOB_DBRPcRi + +; bdb_get.c: +; sql_get.c: +_Z15db_get_pool_idsP3JCRP4B_DBPiPPj +_Z16db_get_media_idsP3JCRP4B_DBjPiPPj +_Z17db_get_client_idsP3JCRP4B_DBPiPPj +_Z17db_get_job_recordP3JCRP4B_DBP7JOB_DBR +_Z18db_get_pool_recordP3JCRP4B_DBP8POOL_DBR +_Z19db_get_media_recordP3JCRP4B_DBP9MEDIA_DBR +_Z20db_get_client_recordP3JCRP4B_DBP10CLIENT_DBR +;_Z21db_get_counter_recordP3JCRP4B_DBP11COUNTER_DBR +_Z21db_get_fileset_recordP3JCRP4B_DBP11FILESET_DBR +_Z23db_get_job_volume_namesP3JCRP4B_DBjPPc +;_Z23db_get_num_pool_recordsP3JCRP4B_DB +;_Z24db_get_num_media_recordsP3JCRP4B_DB +_Z28db_get_job_volume_parametersP3JCRP4B_DBjPP10VOL_PARAMS +_Z29db_get_file_attributes_recordP3JCRP4B_DBPcP7JOB_DBRP8FILE_DBR + +; bdb_list.c: +; sql_list.c: +_Z17db_list_sql_queryP3JCRP4B_DBPKcPFvPvS4_ES5_i11e_list_type +_Z18db_list_job_totalsP3JCRP4B_DBP7JOB_DBRPFvPvPKcES5_ +_Z19db_list_job_recordsP3JCRP4B_DBP7JOB_DBRPFvPvPKcES5_11e_list_type +_Z20db_list_pool_recordsP3JCRP4B_DBP8POOL_DBRPFvPvPKcES5_11e_list_type +_Z21db_list_files_for_jobP3JCRP4B_DBjPFvPvPKcES3_ +_Z21db_list_media_recordsP3JCRP4B_DBP9MEDIA_DBRPFvPvPKcES5_11e_list_type +_Z22db_list_client_recordsP3JCRP4B_DBPFvPvPKcES3_11e_list_type +_Z24db_list_jobmedia_recordsP3JCRP4B_DBjPFvPvPKcES3_11e_list_type + +; bdb_update.c: +; sql_update.c: +_Z19db_mark_file_recordP3JCRP4B_DBjj +_Z21db_update_pool_recordP3JCRP4B_DBP8POOL_DBR +_Z22db_update_media_recordP3JCRP4B_DBP9MEDIA_DBR +_Z23db_update_client_recordP3JCRP4B_DBP10CLIENT_DBR +_Z24db_make_inchanger_uniqueP3JCRP4B_DBP9MEDIA_DBR +_Z24db_update_counter_recordP3JCRP4B_DBP11COUNTER_DBR +_Z24db_update_job_end_recordP3JCRP4B_DBP7JOB_DBR +_Z24db_update_media_defaultsP3JCRP4B_DBP9MEDIA_DBR +_Z24db_update_storage_recordP3JCRP4B_DBP11STORAGE_DBR +_Z26db_update_job_start_recordP3JCRP4B_DBP7JOB_DBR +_Z28db_add_digest_to_file_recordP3JCRP4B_DBjPci + +client_backups DATA +list_pool DATA +drop_deltabs DATA +create_deltabs DATA +insert_delcand DATA +select_backup_del DATA +select_verify_del DATA +select_restore_del DATA +select_admin_del DATA +select_job DATA +del_File DATA +;cnt_File DATA +cnt_DelCand DATA +del_Job DATA +del_MAC DATA +del_JobMedia DATA +cnt_JobMedia DATA +sel_JobMedia DATA +upd_Purged DATA + +uar_list_jobs DATA +uar_file DATA +uar_count_files DATA +uar_sel_files DATA +uar_del_temp DATA +uar_del_temp1 DATA +uar_create_temp DATA +uar_create_temp1 DATA +uar_last_full DATA +uar_full DATA +uar_inc DATA +uar_list_temp DATA +uar_sel_all_temp1 DATA +uar_sel_fileset DATA +uar_mediatype DATA +uar_jobid_fileindex DATA +uar_dif DATA +uar_sel_all_temp DATA +uar_count_files DATA +uar_jobids_fileindex DATA +uar_jobid_fileindex_from_dir DATA +uar_jobid_fileindex_from_table DATA +uar_sel_jobid_temp DATA diff --git a/bacula/src/win32/cats/create_bdb_database.cmd b/bacula/src/win32/cats/create_bdb_database.cmd new file mode 100644 index 0000000000..71355ccad5 --- /dev/null +++ b/bacula/src/win32/cats/create_bdb_database.cmd @@ -0,0 +1,4 @@ +rem +rem shell script to create Bacula database(s) +rem +rem Nothing to do diff --git a/bacula/src/win32/cats/create_mysql_database.cmd b/bacula/src/win32/cats/create_mysql_database.cmd index 138bff38ab..f6bb8c8ffd 100644 --- a/bacula/src/win32/cats/create_mysql_database.cmd +++ b/bacula/src/win32/cats/create_mysql_database.cmd @@ -1,13 +1,13 @@ -rem -rem Script to create Bacula database(s) -rem - -%SQL_BINDIR%\mysql $* -e "CREATE DATABASE bacula;" -set RESULT=%ERRORLEVEL% -if %RESULT% GTR 0 goto :ERROR -echo "Creation of bacula database succeeded." -exit /b 0 - -:ERROR -echo "Creation of bacula database failed." -exit /b %RESULT% +rem +rem Script to create Bacula database(s) +rem + +%SQL_BINDIR%\mysql $* -e "CREATE DATABASE bacula;" +set RESULT=%ERRORLEVEL% +if %RESULT% GTR 0 goto :ERROR +echo "Creation of bacula database succeeded." +exit /b 0 + +:ERROR +echo "Creation of bacula database failed." +exit /b %RESULT% diff --git a/bacula/src/win32/cats/create_postgresql_database.cmd b/bacula/src/win32/cats/create_postgresql_database.cmd new file mode 100644 index 0000000000..e47eaad23c --- /dev/null +++ b/bacula/src/win32/cats/create_postgresql_database.cmd @@ -0,0 +1,23 @@ +rem +rem shell script to create Bacula database(s) +rem + +bindir=@SQL_BINDIR@ + +rem use SQL_ASCII to be able to put any filename into +rem the database even those created with unusual character sets +ENCODING="ENCODING 'SQL_ASCII'" +rem use UTF8 if you are using standard Unix/Linux LANG specifications +rem that use UTF8 -- this is normally the default and *should* be +rem your standard. Bacula consoles work correctly *only* with UTF8. +rem ENCODING="ENCODING 'UTF8'" + +$bindir/psql -f create_postgresql_database.sql -d template1 $* +if ERRORLEVEL 1 GOTO :ERROR +echo "Creation of bacula database succeeded." +EXIT /b 0 +GOTO :EOF + +:ERROR +echo "Creation of bacula database failed." +EXIT /b 1 diff --git a/bacula/src/win32/cats/create_postgresql_database.sql b/bacula/src/win32/cats/create_postgresql_database.sql new file mode 100644 index 0000000000..2dec4e48c3 --- /dev/null +++ b/bacula/src/win32/cats/create_postgresql_database.sql @@ -0,0 +1,2 @@ +CREATE DATABASE bacula $ENCODING; +ALTER DATABASE bacula SET datestyle TO 'ISO, YMD'; diff --git a/bacula/src/win32/cats/delete_catalog_backup.cmd b/bacula/src/win32/cats/delete_catalog_backup.cmd index a3cfcf6333..6ff55912ac 100644 --- a/bacula/src/win32/cats/delete_catalog_backup.cmd +++ b/bacula/src/win32/cats/delete_catalog_backup.cmd @@ -1,4 +1,4 @@ -rem -rem This script deletes a catalog dump -rem -del /f %WORKING_DIR%/bacula.sql +rem +rem This script deletes a catalog dump +rem +del /f %WORKING_DIR%/bacula.sql diff --git a/bacula/src/win32/cats/drop_bdb_database.cmd b/bacula/src/win32/cats/drop_bdb_database.cmd new file mode 100644 index 0000000000..9338c8f5e0 --- /dev/null +++ b/bacula/src/win32/cats/drop_bdb_database.cmd @@ -0,0 +1,5 @@ +rem +rem +rem shell script to drop Bacula database(s) +rem +rem Nothing to do diff --git a/bacula/src/win32/cats/drop_bdb_tables.cmd b/bacula/src/win32/cats/drop_bdb_tables.cmd new file mode 100644 index 0000000000..e90fef99bd --- /dev/null +++ b/bacula/src/win32/cats/drop_bdb_tables.cmd @@ -0,0 +1,12 @@ +rem +rem shell script to Delete the Bacula database (same as deleting +rem the tables) +rem + +del /f @working_dir@/control.db +del /f @working_dir@/jobs.db +del /f @working_dir@/pools.db +del /f @working_dir@/media.db +del /f @working_dir@/jobmedia.db +del /f @working_dir@/client.db +del /f @working_dir@/fileset.db diff --git a/bacula/src/win32/cats/drop_mysql_database.cmd b/bacula/src/win32/cats/drop_mysql_database.cmd index 586de2a3b2..ddee47cec7 100644 --- a/bacula/src/win32/cats/drop_mysql_database.cmd +++ b/bacula/src/win32/cats/drop_mysql_database.cmd @@ -1,13 +1,13 @@ -rem -rem shell script to drop Bacula database(s) -rem - -%SQL_BINDIR%/mysql $* -f -e "DROP DATABASE bacula;" -set RESULT=%ERRORLEVEL% -if %RESULT% GTR 0 goto :ERROR -echo "Drop of bacula database succeeded." -exit /b 0 - -:ERROR -echo "Drop of bacula database failed." -exit /b %RESULT% +rem +rem shell script to drop Bacula database(s) +rem + +%SQL_BINDIR%/mysql $* -f -e "DROP DATABASE bacula;" +set RESULT=%ERRORLEVEL% +if %RESULT% GTR 0 goto :ERROR +echo "Drop of bacula database succeeded." +exit /b 0 + +:ERROR +echo "Drop of bacula database failed." +exit /b %RESULT% diff --git a/bacula/src/win32/cats/drop_mysql_tables.cmd b/bacula/src/win32/cats/drop_mysql_tables.cmd index fb897394ce..7e2640fe65 100644 --- a/bacula/src/win32/cats/drop_mysql_tables.cmd +++ b/bacula/src/win32/cats/drop_mysql_tables.cmd @@ -1,13 +1,13 @@ -rem -rem Script to delete Bacula tables for MySQL -rem - -if %SQL_BINDIR%/mysql $* < drop_mysql_tables.sql -set RESULT=%ERRORLEVEL% -if %RESULT% GTR 0 goto :ERROR -echo "Deletion of Bacula MySQL tables succeeded." -exit /b 0 - -:ERROR -echo "Deletion of Bacula MySQL tables failed." -exit /b %RESULT% +rem +rem Script to delete Bacula tables for MySQL +rem + +if %SQL_BINDIR%/mysql $* < drop_mysql_tables.sql +set RESULT=%ERRORLEVEL% +if %RESULT% GTR 0 goto :ERROR +echo "Deletion of Bacula MySQL tables succeeded." +exit /b 0 + +:ERROR +echo "Deletion of Bacula MySQL tables failed." +exit /b %RESULT% diff --git a/bacula/src/win32/cats/drop_mysql_tables.sql b/bacula/src/win32/cats/drop_mysql_tables.sql index cf81c8dd9a..562a50b237 100644 --- a/bacula/src/win32/cats/drop_mysql_tables.sql +++ b/bacula/src/win32/cats/drop_mysql_tables.sql @@ -1,25 +1,25 @@ -USE bacula; -DROP TABLE IF EXISTS Filename; -DROP TABLE IF EXISTS Path; -DROP TABLE IF EXISTS LongName; -DROP TABLE IF EXISTS Device; -DROP TABLE IF EXISTS Storage; -DROP TABLE IF EXISTS MediaType; -DROP TABLE IF EXISTS File; -DROP TABLE IF EXISTS Client; -DROP TABLE IF EXISTS Job; -DROP TABLE IF EXISTS Media; -DROP TABLE IF EXISTS MAC; -DROP TABLE IF EXISTS JobMedia; -DROP TABLE IF EXISTS Pool; -DROP TABLE IF EXISTS MultiVolume; -DROP TABLE IF EXISTS FileSave; -DROP TABLE IF EXISTS FileSet; -DROP TABLE IF EXISTS Version; -DROP TABLE IF EXISTS Counters; -DROP TABLE IF EXISTS BaseFiles; -DROP TABLE IF EXISTS UnsavedFiles; -DROP TABLE IF EXISTS CDImages; -DROP TABLE IF EXISTS Status; -DROP TABLE IF EXISTS MAC; -DROP TABLE IF EXISTS Location; +USE bacula; +DROP TABLE IF EXISTS Filename; +DROP TABLE IF EXISTS Path; +DROP TABLE IF EXISTS LongName; +DROP TABLE IF EXISTS Device; +DROP TABLE IF EXISTS Storage; +DROP TABLE IF EXISTS MediaType; +DROP TABLE IF EXISTS File; +DROP TABLE IF EXISTS Client; +DROP TABLE IF EXISTS Job; +DROP TABLE IF EXISTS Media; +DROP TABLE IF EXISTS MAC; +DROP TABLE IF EXISTS JobMedia; +DROP TABLE IF EXISTS Pool; +DROP TABLE IF EXISTS MultiVolume; +DROP TABLE IF EXISTS FileSave; +DROP TABLE IF EXISTS FileSet; +DROP TABLE IF EXISTS Version; +DROP TABLE IF EXISTS Counters; +DROP TABLE IF EXISTS BaseFiles; +DROP TABLE IF EXISTS UnsavedFiles; +DROP TABLE IF EXISTS CDImages; +DROP TABLE IF EXISTS Status; +DROP TABLE IF EXISTS MAC; +DROP TABLE IF EXISTS Location; diff --git a/bacula/src/win32/cats/drop_postgresql_database.cmd b/bacula/src/win32/cats/drop_postgresql_database.cmd new file mode 100644 index 0000000000..553ae3cf5c --- /dev/null +++ b/bacula/src/win32/cats/drop_postgresql_database.cmd @@ -0,0 +1,15 @@ +rem +rem shell script to drop Bacula database(s) +rem + +bindir=@SQL_BINDIR@ + +$bindir/dropdb bacula +if ERRORLEVEL 1 GOTO :ERROR +echo "Drop of bacula database succeeded." +EXIT /b 0 +GOTO :EOF + +:ERROR +echo "Drop of bacula database failed." +EXIT /b 1 diff --git a/bacula/src/win32/cats/drop_postgresql_tables.cmd b/bacula/src/win32/cats/drop_postgresql_tables.cmd new file mode 100644 index 0000000000..f25037edc4 --- /dev/null +++ b/bacula/src/win32/cats/drop_postgresql_tables.cmd @@ -0,0 +1,15 @@ +rem +rem shell script to delete Bacula tables for PostgreSQL +rem + +bindir=@SQL_BINDIR@ + +$bindir/psql -f drop_postgresql_tables.sql -d bacula $* +if ERRORLEVEL 1 GOTO :ERROR +echo "Deletion of Bacula PostgreSQL tables succeeded." +EXIT /b 0 +GOTO :EOF + +:ERROR +echo "Deletion of Bacula PostgreSQL tables failed." +EXIT /b 1 diff --git a/bacula/src/win32/cats/drop_postgresql_tables.sql b/bacula/src/win32/cats/drop_postgresql_tables.sql new file mode 100644 index 0000000000..4057b920ce --- /dev/null +++ b/bacula/src/win32/cats/drop_postgresql_tables.sql @@ -0,0 +1,22 @@ +drop table unsavedfiles; +drop table basefiles; +drop table jobmedia; +drop table file; +drop table job; +drop table media; +drop table client; +drop table pool; +drop table fileset; +drop table path; +drop table filename; +drop table counters; +drop table version; +drop table CDImages; +drop table Device; +drop table Storage; +drop table MediaType; +drop table Status; +drop table MAC; +drop table log; +drop table Location; +drop table locationlog; diff --git a/bacula/src/win32/cats/fix_postgresql_tables b/bacula/src/win32/cats/fix_postgresql_tables new file mode 100755 index 0000000000..2d69f89278 --- /dev/null +++ b/bacula/src/win32/cats/fix_postgresql_tables @@ -0,0 +1,35 @@ +#!/bin/sh +# +# Shell script to fix PostgreSQL tables in version 8 +# +echo " " +echo "This script will fix a Bacula PostgreSQL database version 8" +echo "Depending on the size of your database," +echo "this script may take several minutes to run." +echo " " +# +# Set the following to the path to psql. +bindir=****EDIT-ME to be the path to psql**** + +if $bindir/psql $* -f - <%1.sql - -# -# To read back a MySQL database use: -# cd @working_dir@ -# rm -f @SQL_BINDIR@/../var/bacula/* -# mysql %1.sql + +# +# To read back a MySQL database use: +# cd @working_dir@ +# rm -f @SQL_BINDIR@/../var/bacula/* +# mysql >%working_dir%\mtx.log + +REM +REM check parameter count on commandline +REM +REM Check for special cases where only 2 arguments are needed, +REM all others are a minimum of 5 +REM +IF "%1" EQU "" goto :param_count_invalid +IF "%2" EQU "" goto :param_count_invalid +IF "%2" EQU "list" goto :param_count_valid +IF "%2" EQU "slots" goto :param_count_valid +IF "%3" EQU "" goto :param_count_invalid +IF "%4" EQU "" goto :param_count_invalid +IF "%5" EQU "" goto :param_count_invalid +GOTO :param_count_valid + +:param_count_invalid + echo Insufficient number of arguments given. + IF "%2" EQU "" ( + echo At least two arguments must be specified. + ) else echo Command expected 5 arguments. +:usage + ECHO. + ECHO usage: mtx-changer ctl-device command [slot archive-device drive-index] + ECHO Valid commands are: unload, load, list, loaded, and slots. + EXIT /B 1 + +:param_count_valid + +REM Setup arguments +SET ctl=%1 +SET cmd=%2 +SET slot=%3 +SET device=%4 +SET drive=%5 + +CALL :debug "Parms: %ctl% %cmd% %slot% %device% %drive%" + +IF "%cmd%" NEQ "unload" goto :cmdLoad + CALL :debug "Doing mtx -f %ctl% unload %slot% %drive%" + %MT% -f %device% offline + %MTX% -f %ctl% unload %slot% %drive% + EXIT /B %ERRORLEVEL% + +:cmdLoad +IF "%cmd%" NEQ "load" goto :cmdList + CALL :debug "Doing mtx -f %ctl% load %slot% %drive%" + %MTX% -f %ctl% load %slot% %drive% + SET rtn=%ERRORLEVEL% + %MT% -f %device% load + CALL :wait_for_drive %device% + EXIT /B %rtn% + +:cmdList +IF "%cmd%" NEQ "list" goto :cmdLoaded + CALL :debug "Doing mtx -f %ctl% -- to list volumes" + CALL :make_temp_file + IF ERRORLEVEL 1 GOTO :EOF +REM Enable the following if you are using barcodes and need an inventory +REM %MTX% -f %ctl% inventory + %MTX% -f %ctl% status >%TMPFILE% + SET rtn=%ERRORLEVEL% + FOR /F "usebackq tokens=3,6 delims==: " %%i in ( `findstr /R /C:" *Storage Element [0-9]*:.*Full" %TMPFILE%` ) do echo %%i:%%j + FOR /F "usebackq tokens=7,10" %%i in ( `findstr /R /C:"^Data Transfer Element [0-9]*:Full (Storage Element [0-9]" %TMPFILE%` ) do echo %%i:%%j + DEL /F "%TMPFILE%" >nul 2>&1 +REM +REM If you have a VXA PacketLoader and the above does not work, try +REM turning it off and enabling the following line. +REM %MTX% -f %ctl% status | grep " *Storage Element [0-9]*:.*Full" | sed "s/*Storage Element //" | sed "s/Full :VolumeTag=//" + EXIT /B %rtn% + +:cmdLoaded +IF "%cmd%" NEQ "loaded" goto :cmdSlots + CALL :debug "Doing mtx -f %ctl% %drive% -- to find what is loaded" + CALL :make_temp_file + %MTX% -f %ctl% status >%TMPFILE% + SET rtn=%ERRORLEVEL% + FOR /F "usebackq tokens=7" %%i in ( `findstr /R /C:"^Data Transfer Element %drive%:Full" %TMPFILE%` ) do echo %%i + findstr /R /C:"^Data Transfer Element %drive%:Empty" %TMPFILE% >nul && echo 0 + DEL /F "%TMPFILE%" >nul 2>&1 + EXIT /B %rtn% + +:cmdSlots +IF "%cmd%" NEQ "slots" goto :cmdUnknown + CALL :debug "Doing mtx -f %ctl% -- to get count of slots" + CALL :make_temp_file + %MTX% -f %ctl% status >%TMPFILE% + SET rtn=%ERRORLEVEL% + FOR /F "usebackq tokens=5" %%i in ( `findstr /R /C:" *Storage Changer" %TMPFILE%` ) do echo %%i + DEL /F "%TMPFILE%" >nul 2>&1 + EXIT /B %rtn% + +:cmdUnknown + ECHO '%cmd%' is an invalid command. + GOTO :usage + +REM +REM log whats done +REM +:debug + IF NOT EXIST "%dbgfile%" GOTO :EOF + FOR /F "usebackq tokens=2-4,5-7 delims=/:. " %%i in ( '%DATE% %TIME%' ) do SET TIMESTAMP=%%k%%i%%j-%%l:%%m:%%n + ECHO %TIMESTAMP% %*>> %dbgfile% + GOTO :EOF + +REM +REM Create a temporary file +REM +:make_temp_file + REM SET TMPFILE=%working_dir%\mtx.tmp + SET TMPFILE=c:\bacula.test\working\mtx.tmp + IF EXIST "%TMPFILE%" ( + ECHO Temp file security problem on: %TMPFILE% + EXIT /B 1 + ) + GOTO :EOF + +REM +REM The purpose of this function to wait a maximum +REM time for the drive. It will +REM return as soon as the drive is ready, or after +REM waiting a maximum of 300 seconds. +REM Note, this is very system dependent, so if you are +REM not running on Linux, you will probably need to +REM re-write it, or at least change the grep target. +REM +:wait_for_drive + FOR /L %%i IN ( 1, 1, 300 ) DO ( + %MT% -f %1 status | findstr ONLINE >NUL 2>&1 + IF %ERRORLEVEL%==0 GOTO :EOF + CALL :debug "Device %1 - not ready, retrying..." + CALL :sleep 1 + ) + CALL :debug "Device %1 - not ready, timed out..." + GOTO :EOF + +:sleep + CALL :get_secs + SET start_time=%ERRORLEVEL% + SET /A end_time=100*%1+start_time +:sleep_wait + CALL :get_secs + IF %ERRORLEVEL% LSS %start_time% GOTO :sleep + IF %ERRORLEVEL% LSS %end_time% GOTO :sleep_wait + GOTO :EOF + +:get_secs + FOR /F "tokens=3,4 delims=:. " %%i IN ( "%TIME%" ) do SET /A "secs= ( 1%%i %% 100 ) * 100 + ( 1%%j %% 100 )" + EXIT /B %secs% diff --git a/bacula/src/win32/scripts/mtx-changer.cmd.in b/bacula/src/win32/scripts/mtx-changer.cmd.in deleted file mode 100644 index 323d7331cb..0000000000 --- a/bacula/src/win32/scripts/mtx-changer.cmd.in +++ /dev/null @@ -1,194 +0,0 @@ -@echo off -REM -REM -REM Bacula interface to mtx autoloader -REM -REM $Id$ -REM -REM If you set in your Device resource -REM -REM Changer Command = "path-to-this-script/mtx-changer %c %o %S %a %d" -REM you will have the following input to this script: -REM -REM So Bacula will always call with all the following arguments, even though -REM in come cases, not all are used. -REM -REM mtx-changer "changer-device" "command" "slot" "archive-device" "drive-index" -REM $1 $2 $3 $4 $5 -REM -REM for example: -REM -REM mtx-changer /dev/sg0 load 1 /dev/nst0 0 (on a Linux system) -REM -REM will request to load the first cartidge into drive 0, where -REM the SCSI control channel is /dev/sg0, and the read/write device -REM is /dev/nst0. -REM -REM If you need to an offline, refer to the drive as $4 -REM e.g. mt -f $4 offline -REM -REM Many changers need an offline after the unload. Also many -REM changers need a sleep 60 after the mtx load. -REM -REM N.B. If you change the script, take care to return either -REM the mtx exit code or a 0. If the script exits with a non-zero -REM exit code, Bacula will assume the request failed. -REM - -SET MTX=@MTX@ -SET MT=@MT@ -SET working_dir=@working_dir@ - -SET dbgfile=%working_dir%\mtx.log - -REM to turn on logging, uncomment the following line -REM findstr xxx >%working_dir%\mtx.log - -REM -REM check parameter count on commandline -REM -REM Check for special cases where only 2 arguments are needed, -REM all others are a minimum of 5 -REM -IF "%1" EQU "" goto :param_count_invalid -IF "%2" EQU "" goto :param_count_invalid -IF "%2" EQU "list" goto :param_count_valid -IF "%2" EQU "slots" goto :param_count_valid -IF "%3" EQU "" goto :param_count_invalid -IF "%4" EQU "" goto :param_count_invalid -IF "%5" EQU "" goto :param_count_invalid -GOTO :param_count_valid - -:param_count_invalid - echo Insufficient number of arguments given. - IF "%2" EQU "" ( - echo At least two arguments must be specified. - ) else echo Command expected 5 arguments. -:usage - ECHO. - ECHO usage: mtx-changer ctl-device command [slot archive-device drive-index] - ECHO Valid commands are: unload, load, list, loaded, and slots. - EXIT /B 1 - -:param_count_valid - -REM Setup arguments -SET ctl=%1 -SET cmd=%2 -SET slot=%3 -SET device=%4 -SET drive=%5 - -CALL :debug "Parms: %ctl% %cmd% %slot% %device% %drive%" - -IF "%cmd%" NEQ "unload" goto :cmdLoad - CALL :debug "Doing mtx -f %ctl% unload %slot% %drive%" - %MT% -f %device% offline - %MTX% -f %ctl% unload %slot% %drive% - EXIT /B %ERRORLEVEL% - -:cmdLoad -IF "%cmd%" NEQ "load" goto :cmdList - CALL :debug "Doing mtx -f %ctl% load %slot% %drive%" - %MTX% -f %ctl% load %slot% %drive% - SET rtn=%ERRORLEVEL% - %MT% -f %device% load - CALL :wait_for_drive %device% - EXIT /B %rtn% - -:cmdList -IF "%cmd%" NEQ "list" goto :cmdLoaded - CALL :debug "Doing mtx -f %ctl% -- to list volumes" - CALL :make_temp_file - IF ERRORLEVEL 1 GOTO :EOF -REM Enable the following if you are using barcodes and need an inventory -REM %MTX% -f %ctl% inventory - %MTX% -f %ctl% status >%TMPFILE% - SET rtn=%ERRORLEVEL% - FOR /F "usebackq tokens=3,6 delims==: " %%i in ( `findstr /R /C:" *Storage Element [0-9]*:.*Full" %TMPFILE%` ) do echo %%i:%%j - FOR /F "usebackq tokens=7,10" %%i in ( `findstr /R /C:"^Data Transfer Element [0-9]*:Full (Storage Element [0-9]" %TMPFILE%` ) do echo %%i:%%j - DEL /F "%TMPFILE%" >nul 2>&1 -REM -REM If you have a VXA PacketLoader and the above does not work, try -REM turning it off and enabling the following line. -REM %MTX% -f %ctl% status | grep " *Storage Element [0-9]*:.*Full" | sed "s/*Storage Element //" | sed "s/Full :VolumeTag=//" - EXIT /B %rtn% - -:cmdLoaded -IF "%cmd%" NEQ "loaded" goto :cmdSlots - CALL :debug "Doing mtx -f %ctl% %drive% -- to find what is loaded" - CALL :make_temp_file - %MTX% -f %ctl% status >%TMPFILE% - SET rtn=%ERRORLEVEL% - FOR /F "usebackq tokens=7" %%i in ( `findstr /R /C:"^Data Transfer Element %drive%:Full" %TMPFILE%` ) do echo %%i - findstr /R /C:"^Data Transfer Element %drive%:Empty" %TMPFILE% >nul && echo 0 - DEL /F "%TMPFILE%" >nul 2>&1 - EXIT /B %rtn% - -:cmdSlots -IF "%cmd%" NEQ "slots" goto :cmdUnknown - CALL :debug "Doing mtx -f %ctl% -- to get count of slots" - CALL :make_temp_file - %MTX% -f %ctl% status >%TMPFILE% - SET rtn=%ERRORLEVEL% - FOR /F "usebackq tokens=5" %%i in ( `findstr /R /C:" *Storage Changer" %TMPFILE%` ) do echo %%i - DEL /F "%TMPFILE%" >nul 2>&1 - EXIT /B %rtn% - -:cmdUnknown - ECHO '%cmd%' is an invalid command. - GOTO :usage - -REM -REM log whats done -REM -:debug - IF NOT EXIST "%dbgfile%" GOTO :EOF - FOR /F "usebackq tokens=2-4,5-7 delims=/:. " %%i in ( '%DATE% %TIME%' ) do SET TIMESTAMP=%%k%%i%%j-%%l:%%m:%%n - ECHO %TIMESTAMP% %*>> %dbgfile% - GOTO :EOF - -REM -REM Create a temporary file -REM -:make_temp_file - REM SET TMPFILE=%working_dir%\mtx.tmp - SET TMPFILE=c:\bacula.test\working\mtx.tmp - IF EXIST "%TMPFILE%" ( - ECHO Temp file security problem on: %TMPFILE% - EXIT /B 1 - ) - GOTO :EOF - -REM -REM The purpose of this function to wait a maximum -REM time for the drive. It will -REM return as soon as the drive is ready, or after -REM waiting a maximum of 300 seconds. -REM Note, this is very system dependent, so if you are -REM not running on Linux, you will probably need to -REM re-write it, or at least change the grep target. -REM -:wait_for_drive - FOR /L %%i IN ( 1, 1, 300 ) DO ( - %MT% -f %1 status | findstr ONLINE >NUL 2>&1 - IF %ERRORLEVEL%==0 GOTO :EOF - CALL :debug "Device %1 - not ready, retrying..." - CALL :sleep 1 - ) - CALL :debug "Device %1 - not ready, timed out..." - GOTO :EOF - -:sleep - CALL :get_secs - SET start_time=%ERRORLEVEL% - SET /A end_time=100*%1+start_time -:sleep_wait - CALL :get_secs - IF %ERRORLEVEL% LSS %start_time% GOTO :sleep - IF %ERRORLEVEL% LSS %end_time% GOTO :sleep_wait - GOTO :EOF - -:get_secs - FOR /F "tokens=3,4 delims=:. " %%i IN ( "%TIME%" ) do SET /A "secs= ( 1%%i %% 100 ) * 100 + ( 1%%j %% 100 )" - EXIT /B %secs% diff --git a/bacula/src/win32/stored/Makefile b/bacula/src/win32/stored/Makefile index a16e65ff3a..96d1feb773 100644 --- a/bacula/src/win32/stored/Makefile +++ b/bacula/src/win32/stored/Makefile @@ -129,7 +129,7 @@ $(BINDIR)/bls.exe: $(OBJDIR)/bls.o $(COMMON_OBJS) $(LIBS_BACULA) $(BINDIR)/bextract.exe: $(BEXTRACT_OBJS) $(COMMON_OBJS) $(LIBS_BACULA) $(call link_conapp,$(LIBS_STORED) $(LIBS_ZLIB)) -$(BINDIR)/bscan.exe: $(OBJDIR)/bscan.o $(COMMON_OBJS) $(LIBS_BACULA) +$(BINDIR)/bscan.exe: $(OBJDIR)/bscan.o $(COMMON_OBJS) $(LIBS_CATS) $(LIBS_BACULA) $(call link_conapp,$(LIBS_STORED)) $(BINDIR)/bcopy.exe: $(OBJDIR)/bcopy.o $(COMMON_OBJS) $(LIBS_BACULA) diff --git a/bacula/src/win32/tools/Makefile b/bacula/src/win32/tools/Makefile index 59d3829cf4..31797e0f55 100644 --- a/bacula/src/win32/tools/Makefile +++ b/bacula/src/win32/tools/Makefile @@ -16,6 +16,7 @@ INCLUDES = \ DEFINES = \ -DUSING_DLL \ + -DUSING_CATS \ $(HAVES) VPATH = ../../tools ../../dird @@ -73,7 +74,7 @@ clean: $(BINDIR)/bsmtp.exe: $(OBJDIR)/bsmtp.o $(LIBS_BACULA) $(call link_conapp,) -$(BINDIR)/dbcheck.exe: $(OBJDIR)/dbcheck.o $(DIRCONF_OBJS) $(LIBS_BACULA) +$(BINDIR)/dbcheck.exe: $(OBJDIR)/dbcheck.o $(DIRCONF_OBJS) $(LIBS_BACULA) $(LIBS_CATS) $(call link_conapp,) $(BINDIR)/fstype.exe: $(OBJDIR)/fstype.o $(LIBS_BACULA)