]> git.sur5r.net Git - bacula/docs/blob - docs/manuals/en/developers/gui-interface.tex
update info on bvfs
[bacula/docs] / docs / manuals / en / developers / gui-interface.tex
1 %%
2 %%
3
4 \chapter*{Implementing a GUI Interface}
5 \label{_ChapterStart}
6 \index[general]{Interface!Implementing a Bacula GUI }
7 \index[general]{Implementing a Bacula GUI Interface }
8 \addcontentsline{toc}{section}{Implementing a Bacula GUI Interface}
9
10 \section{General}
11 \index[general]{General }
12 \addcontentsline{toc}{subsection}{General}
13
14 This document is intended mostly for developers who wish to develop a new GUI
15 interface to {\bf Bacula}. 
16
17 \subsection{Minimal Code in Console Program}
18 \index[general]{Program!Minimal Code in Console }
19 \index[general]{Minimal Code in Console Program }
20 \addcontentsline{toc}{subsubsection}{Minimal Code in Console Program}
21
22 Until now, I have kept all the Catalog code in the Directory (with the
23 exception of dbcheck and bscan). This is because at some point I would like to
24 add user level security and access. If we have code spread everywhere such as
25 in a GUI this will be more difficult. The other advantage is that any code you
26 add to the Director is automatically available to both the tty console program
27 and the WX program. The major disadvantage is it increases the size of the
28 code -- however, compared to Networker the Bacula Director is really tiny. 
29
30 \subsection{GUI Interface is Difficult}
31 \index[general]{GUI Interface is Difficult }
32 \index[general]{Difficult!GUI Interface is }
33 \addcontentsline{toc}{subsubsection}{GUI Interface is Difficult}
34
35 Interfacing to an interactive program such as Bacula can be very difficult
36 because the interfacing program must interpret all the prompts that may come.
37 This can be next to impossible. There are are a number of ways that Bacula is
38 designed to facilitate this: 
39
40 \begin{itemize}
41 \item The Bacula network protocol is packet based, and  thus pieces of
42 information sent can be ASCII or binary.  
43 \item The packet interface permits knowing where the end of  a list is.  
44 \item The packet interface permits special ``signals''  to be passed rather
45 than data.  
46 \item The Director has a number of commands that are  non-interactive. They
47 all begin with a period,  and provide things such as the list of all Jobs, 
48 list of all Clients, list of all Pools, list of  all Storage, ... Thus the GUI
49 interface can get  to virtually all information that the Director has  in a
50 deterministic way. See  \lt{}bacula-source\gt{}/src/dird/ua\_dotcmds.c for 
51 more details on this.  
52 \item Most console commands allow all the arguments to  be specified on the
53 command line: e.g.  {\bf run job=NightlyBackup level=Full} 
54 \end{itemize}
55
56 One of the first things to overcome is to be able to establish a conversation
57 with the Director. Although you can write all your own code, it is probably
58 easier to use the Bacula subroutines. The following code is used by the
59 Console program to begin a conversation. 
60
61 \footnotesize
62 \begin{verbatim}
63 static BSOCK *UA_sock = NULL;
64 static JCR *jcr;
65 ...
66   read-your-config-getting-address-and-pasword;
67   UA_sock = bnet_connect(NULL, 5, 15, "Director daemon", dir->address,
68                           NULL, dir->DIRport, 0);
69    if (UA_sock == NULL) {
70       terminate_console(0);
71       return 1;
72    }
73    jcr.dir_bsock = UA_sock;
74    if (!authenticate_director(\&jcr, dir)) {
75       fprintf(stderr, "ERR=%s", UA_sock->msg);
76       terminate_console(0);
77       return 1;
78    }
79    read_and_process_input(stdin, UA_sock);
80    if (UA_sock) {
81       bnet_sig(UA_sock, BNET_TERMINATE); /* send EOF */
82       bnet_close(UA_sock);
83    }
84    exit 0;
85 \end{verbatim}
86 \normalsize
87
88 Then the read\_and\_process\_input routine looks like the following: 
89
90 \footnotesize
91 \begin{verbatim}
92    get-input-to-send-to-the-Director;
93    bnet_fsend(UA_sock, "%s", input);
94    stat = bnet_recv(UA_sock);
95    process-output-from-the-Director;
96 \end{verbatim}
97 \normalsize
98
99 For a GUI program things will be a bit more complicated. Basically in the very
100 inner loop, you will need to check and see if any output is available on the
101 UA\_sock. For an example, please take a look at the WX GUI interface code
102 in: \lt{bacula-source/src/wx-console}
103
104 \section{Bvfs API}
105 \label{sec:bvfs}
106
107 To help developers of restore GUI interfaces, we have added new \textsl{dot
108   commands} that permit browsing the catalog in a very simple way.
109
110
111 Bat has now a bRestore panel that uses Bvfs to display files and
112 directories.
113
114 \begin{figure}[htbp]
115   \centering
116   \includegraphics[width=12cm]{\idir bat-brestore}
117   \label{fig:batbrestore}
118   \caption{Bat Brestore Panel}
119 \end{figure}
120
121 The Bvfs module works correctly with BaseJobs, Copy and Migration jobs.
122
123 \medskip
124 This project was funded by Bacula Systems.
125
126 \subsection*{General notes}
127
128 \begin{itemize}
129 \item All fields are separated by a tab
130 \item You can specify \texttt{limit=} and \texttt{offset=} to list smoothly
131   records in very big directories
132 \item All operations (except cache creation) are designed to run instantly
133 \item At this time, Bvfs works faster on PostgreSQL than MySQL catalog. If you
134   can contribute new faster SQL queries we will be happy, else don't complain
135   about speed.
136 \item The cache creation is dependent of the number of directories. As Bvfs
137   shares information accross jobs, the first creation can be slow
138 \item All fields are separated by a tab
139 \item Due to potential encoding problem, it's advised to allways use pathid in
140   queries.
141 \end{itemize}
142
143 \subsection*{Get dependent jobs from a given JobId}
144
145 Bvfs allows you to query the catalog against any combination of jobs. You
146 can combine all Jobs and all FileSet for a Client in a single session.
147
148 To get all JobId needed to restore a particular job, you can use the
149 \texttt{.bvfs\_get\_jobids} command.
150
151 \begin{verbatim}
152 .bvfs_get_jobids jobid=num [all]
153 \end{verbatim}
154
155 \begin{verbatim}
156 .bvfs_get_jobids jobid=10
157 1,2,5,10
158 .bvfs_get_jobids jobid=10 all
159 1,2,3,5,10
160 \end{verbatim}
161
162 In this example, a normal restore will need to use JobIds 1,2,5,10 to
163 compute a complete restore of the system.
164
165 With the \texttt{all} option, the Director will use all defined FileSet for
166 this client.
167
168 \subsection*{Generating Bvfs cache}
169
170 The \texttt{.bvfs\_update} command computes the directory cache for jobs
171 specified in argument, or for all jobs if unspecified.
172
173 \begin{verbatim}
174 .bvfs_update [jobid=numlist]
175 \end{verbatim}
176
177 Example:
178 \begin{verbatim}
179 .bvfs_update jobid=1,2,3
180 \end{verbatim}
181
182 You can run the cache update process in a RunScript after the catalog backup.
183
184 \subsection*{Get all versions of a specific file}
185
186 Bvfs allows you to find all versions of a specific file for a given Client with
187 the \texttt{.bvfs\_version} command. To avoid problems with encoding, this
188 function uses only PathId and FilenameId. The jobid argument is mandatory but
189 unused.
190
191 \begin{verbatim}
192 .bvfs_versions client=filedaemon pathid=num filenameid=num jobid=1
193 PathId FilenameId FileId JobId LStat Md5 VolName Inchanger
194 PathId FilenameId FileId JobId LStat Md5 VolName Inchanger
195 ...
196 \end{verbatim}
197
198 Example:
199
200 \begin{verbatim}
201 .bvfs_versions client=localhost-fd pathid=1 fnid=47 jobid=1
202 1  47  52  12  gD HRid IGk D Po Po A P BAA I A   /uPgWaxMgKZlnMti7LChyA  Vol1  1
203 \end{verbatim}
204
205 \subsection*{List directories}
206
207 Bvfs allows you to list directories in a specific path.
208 \begin{verbatim}
209 .bvfs_lsdirs pathid=num path=/apath jobid=numlist limit=num offset=num
210 PathId  FilenameId  FileId  JobId  LStat  Path
211 PathId  FilenameId  FileId  JobId  LStat  Path
212 PathId  FilenameId  FileId  JobId  LStat  Path
213 ...
214 \end{verbatim}
215
216 You need to \texttt{pathid} or \texttt{path}. Using \texttt{path=""} will list
217 ``/'' on Unix and all drives on Windows.  If FilenameId is 0, the record
218 listed is a directory.
219
220 \begin{verbatim}
221 .bvfs_lsdirs pathid=4 jobid=1,11,12
222 4       0       0       0       A A A A A A A A A A A A A A     .
223 5       0       0       0       A A A A A A A A A A A A A A     ..
224 3       0       0       0       A A A A A A A A A A A A A A     regress/
225 \end{verbatim}
226
227 In this example, to list directories present in \texttt{regress/}, you can use
228 \begin{verbatim}
229 .bvfs_lsdirs pathid=3 jobid=1,11,12
230 3       0       0       0       A A A A A A A A A A A A A A     .
231 4       0       0       0       A A A A A A A A A A A A A A     ..
232 2       0       0       0       A A A A A A A A A A A A A A     tmp/
233 \end{verbatim}
234
235 \subsection*{List files}
236
237 Bvfs allows you to list files in a specific path.
238 \begin{verbatim}
239 .bvfs_lsfiles pathid=num path=/apath jobid=numlist limit=num offset=num
240 PathId  FilenameId  FileId  JobId  LStat  Path
241 PathId  FilenameId  FileId  JobId  LStat  Path
242 PathId  FilenameId  FileId  JobId  LStat  Path
243 ...
244 \end{verbatim}
245
246 You need to \texttt{pathid} or \texttt{path}. Using \texttt{path=""} will list
247 ``/'' on Unix and all drives on Windows. If FilenameId is 0, the record listed
248 is a directory.
249
250 \begin{verbatim}
251 .bvfs_lsfiles pathid=4 jobid=1,11,12
252 4       0       0       0       A A A A A A A A A A A A A A     .
253 5       0       0       0       A A A A A A A A A A A A A A     ..
254 1       0       0       0       A A A A A A A A A A A A A A     regress/
255 \end{verbatim}
256
257 In this example, to list files present in \texttt{regress/}, you can use
258 \begin{verbatim}
259 .bvfs_lsfiles pathid=1 jobid=1,11,12
260 1   47   52   12    gD HRid IGk BAA I BMqcPH BMqcPE BMqe+t A     titi
261 1   49   53   12    gD HRid IGk BAA I BMqe/K BMqcPE BMqe+t B     toto
262 1   48   54   12    gD HRie IGk BAA I BMqcPH BMqcPE BMqe+3 A     tutu
263 1   45   55   12    gD HRid IGk BAA I BMqe/K BMqcPE BMqe+t B     ficheriro1.txt
264 1   46   56   12    gD HRie IGk BAA I BMqe/K BMqcPE BMqe+3 D     ficheriro2.txt
265 \end{verbatim}
266
267 \subsection*{Restore set of files}
268
269 Bvfs allows you to create a SQL table that contains files that you want to
270 restore. This table can be provided to a restore command with the file option.
271
272 \begin{verbatim}
273 .bvfs_restore fileid=numlist dirid=numlist hardlink=numlist path=b2num
274 OK
275 restore file=?b2num ...
276 \end{verbatim}
277
278 To include a directory (with \texttt{dirid}), Bvfs needs to run a query to
279 select all files. This query could be time consuming.
280
281 \texttt{hardlink} list is always composed of a serie of two numbers (jobid,
282 fileindex). This information can be found in the LinkFI field of the LStat
283 packet.
284
285 The \texttt{path} argument represents the name of the table that Bvfs will
286 store results. The format of this table is \texttt{b2[0-9]+}. (Should start by
287 b2 and followed by digits).
288
289 Example:
290
291 \begin{verbatim}
292 .bvfs_restore fileid=1,2,3,4 hardlink=10,15,10,20 jobid=10 path=b20001
293 OK
294 \end{verbatim}
295
296 \subsection*{Cleanup after Restore}
297
298 To drop the table used by the restore command, you can use the
299 \texttt{.bvfs\_cleanup} command.
300
301 \begin{verbatim}
302 .bvfs_cleanup path=b20001
303 \end{verbatim}
304
305 \subsection*{Clearing the BVFS Cache}
306
307 To clear the BVFS cache, you can use the \texttt{.bvfs\_clear_cache} command.
308
309 \begin{verbatim}
310 .bvfs_clear_cache yes
311 OK
312 \end{verbatim}