]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/protos.h
Don't compute accurate list with MD5 if not used
[bacula/bacula] / bacula / src / cats / protos.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
5
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 three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
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.
17
18    You should have received a copy of the GNU Affero 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
21    02110-1301, USA.
22
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.
27 */
28 /*
29  *
30  *  Database routines that are exported by the cats library for
31  *    use elsewhere in Bacula (mainly the Director).
32  *
33  *    Version $Id$
34  */
35
36 #ifndef __SQL_PROTOS_H
37 #define __SQL_PROTOS_H
38
39 #include "cats.h"
40
41 /* Database prototypes */
42
43 /* sql.c */
44 B_DB *db_init(JCR *jcr, const char *db_driver, const char *db_name, const char *db_user, 
45               const char *db_password, const char *db_address, int db_port, 
46               const char *db_socket, int mult_db_connections);
47 B_DB *db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char *db_password,
48                        const char *db_address, int db_port, const char *db_socket,
49                        int mult_db_connections);
50 int  db_open_database(JCR *jcr, B_DB *db);
51 void db_close_database(JCR *jcr, B_DB *db);
52 bool db_open_batch_connexion(JCR *jcr, B_DB *mdb);
53 void db_escape_string(JCR *jcr, B_DB *db, char *snew, char *old, int len);
54 char *db_escape_object(JCR *jcr, B_DB *db, char *old, int len);
55 void db_unescape_object(JCR *jcr, B_DB *db, 
56                         char *from, int32_t expected_len, 
57                         POOLMEM **dest, int32_t *len);
58 char *db_strerror(B_DB *mdb);
59 int  db_next_index(JCR *jcr, B_DB *mdb, char *table, char *index);
60 bool db_sql_query(B_DB *mdb, const char *cmd, DB_RESULT_HANDLER *result_handler, void *ctx);
61 void db_start_transaction(JCR *jcr, B_DB *mdb);
62 void db_end_transaction(JCR *jcr, B_DB *mdb);
63 int db_int64_handler(void *ctx, int num_fields, char **row);
64 int db_list_handler(void *ctx, int num_fields, char **row);
65 void db_thread_cleanup();
66 void db_debug_print(JCR *jcr, FILE *fp);
67 int db_int_handler(void *ctx, int num_fields, char **row);
68 void db_check_backend_thread_safe();
69
70 /* sql_create.c */
71 int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
72 bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
73 bool db_create_job_record(JCR *jcr, B_DB *db, JOB_DBR *jr);
74 int db_create_media_record(JCR *jcr, B_DB *db, MEDIA_DBR *media_dbr);
75 int db_create_client_record(JCR *jcr, B_DB *db, CLIENT_DBR *cr);
76 bool db_create_fileset_record(JCR *jcr, B_DB *db, FILESET_DBR *fsr);
77 bool db_create_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pool_dbr);
78 bool db_create_jobmedia_record(JCR *jcr, B_DB *mdb, JOBMEDIA_DBR *jr);
79 int db_create_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr);
80 bool db_create_device_record(JCR *jcr, B_DB *mdb, DEVICE_DBR *dr);
81 bool db_create_storage_record(JCR *jcr, B_DB *mdb, STORAGE_DBR *sr);
82 bool db_create_mediatype_record(JCR *jcr, B_DB *mdb, MEDIATYPE_DBR *mr);
83 bool db_write_batch_file_records(JCR *jcr);
84 bool my_batch_start(JCR *jcr, B_DB *mdb);
85 bool my_batch_end(JCR *jcr, B_DB *mdb, const char *error);
86 bool my_batch_insert(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
87 bool db_create_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
88 bool db_create_restore_object_record(JCR *jcr, B_DB *mdb, ROBJECT_DBR *ar);
89 bool db_create_base_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
90 bool db_commit_base_file_attributes_record(JCR *jcr, B_DB *mdb);
91 bool db_create_base_file_list(JCR *jcr, B_DB *mdb, char *jobids);
92
93 /* sql_delete.c */
94 int db_delete_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pool_dbr);
95 int db_delete_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
96
97 /* sql_find.c */
98 bool db_find_last_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, int JobLevel);
99 bool db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime);
100 bool db_find_last_jobid(JCR *jcr, B_DB *mdb, const char *Name, JOB_DBR *jr);
101 int db_find_next_volume(JCR *jcr, B_DB *mdb, int index, bool InChanger, MEDIA_DBR *mr);
102 bool db_find_failed_job_since(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM *stime, int &JobLevel);
103
104 /* sql_get.c */
105 bool db_get_volume_jobids(JCR *jcr, B_DB *mdb, 
106                          MEDIA_DBR *mr, db_list_ctx *lst);
107 bool db_get_base_file_list(JCR *jcr, B_DB *mdb, bool use_md5,
108                            DB_RESULT_HANDLER *result_handler,void *ctx);
109 int db_get_path_record(JCR *jcr, B_DB *mdb);
110 bool db_get_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pdbr);
111 int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr);
112 bool db_get_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr);
113 int db_get_job_volume_names(JCR *jcr, B_DB *mdb, JobId_t JobId, POOLMEM **VolumeNames);
114 int db_get_file_attributes_record(JCR *jcr, B_DB *mdb, char *fname, JOB_DBR *jr, FILE_DBR *fdbr);
115 int db_get_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr);
116 bool db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
117 int db_get_num_media_records(JCR *jcr, B_DB *mdb);
118 int db_get_num_pool_records(JCR *jcr, B_DB *mdb);
119 int db_get_pool_ids(JCR *jcr, B_DB *mdb, int *num_ids, DBId_t **ids);
120 int db_get_client_ids(JCR *jcr, B_DB *mdb, int *num_ids, DBId_t **ids);
121 bool db_get_media_ids(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr, int *num_ids, uint32_t **ids);
122 int db_get_job_volume_parameters(JCR *jcr, B_DB *mdb, JobId_t JobId, VOL_PARAMS **VolParams);
123 int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cdbr);
124 int db_get_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr);
125 bool db_get_query_dbids(JCR *jcr, B_DB *mdb, POOL_MEM &query, dbid_list &ids);
126 bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, bool use_md5, DB_RESULT_HANDLER *result_handler, void *ctx);
127 bool db_get_base_jobid(JCR *jcr, B_DB *mdb, JOB_DBR *jr, JobId_t *jobid);
128 bool db_accurate_get_jobids(JCR *jcr, B_DB *mdb, JOB_DBR *jr, db_list_ctx *jobids);
129 bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, db_list_ctx *result);
130 /* sql_list.c */
131 enum e_list_type {
132    HORZ_LIST,
133    VERT_LIST
134 };
135 void db_list_pool_records(JCR *jcr, B_DB *db, POOL_DBR *pr, DB_LIST_HANDLER sendit, void *ctx, e_list_type type);
136 void db_list_job_records(JCR *jcr, B_DB *db, JOB_DBR *jr, DB_LIST_HANDLER sendit, void *ctx, e_list_type type);
137 void db_list_job_totals(JCR *jcr, B_DB *db, JOB_DBR *jr, DB_LIST_HANDLER sendit, void *ctx);
138 void db_list_files_for_job(JCR *jcr, B_DB *db, uint32_t jobid, DB_LIST_HANDLER sendit, void *ctx);
139 void db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
140 void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, JobId_t JobId, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
141 void db_list_joblog_records(JCR *jcr, B_DB *mdb, JobId_t JobId, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
142 int  db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose, e_list_type type);
143 void db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
144 void db_list_copies_records(JCR *jcr, B_DB *mdb, uint32_t limit, char *jobids, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
145 void
146 db_list_base_files_for_job(JCR *jcr, B_DB *mdb, JobId_t jobid, DB_LIST_HANDLER *sendit, void *ctx);
147
148
149 /* sql_update.c */
150 bool db_update_job_start_record(JCR *jcr, B_DB *db, JOB_DBR *jr);
151 int  db_update_job_end_record(JCR *jcr, B_DB *db, JOB_DBR *jr);
152 int  db_update_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr);
153 int  db_update_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pr);
154 bool db_update_storage_record(JCR *jcr, B_DB *mdb, STORAGE_DBR *sr);
155 int  db_update_media_record(JCR *jcr, B_DB *db, MEDIA_DBR *mr);
156 int  db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
157 int  db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr);
158 int  db_add_digest_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *digest, int type);
159 int  db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId);
160 void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
161 int db_update_stats(JCR *jcr, B_DB *mdb, utime_t age);
162
163 #endif /* __SQL_PROTOS_H */