4 \chapter*{Implementing a GUI Interface}
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}
11 \index[general]{General }
12 \addcontentsline{toc}{subsection}{General}
14 This document is intended mostly for developers who wish to develop a new GUI
15 interface to {\bf Bacula}.
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}
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.
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}
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:
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
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
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}
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.
63 static BSOCK *UA_sock = NULL;
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) {
73 jcr.dir_bsock = UA_sock;
74 if (!authenticate_director(\&jcr, dir)) {
75 fprintf(stderr, "ERR=%s", UA_sock->msg);
79 read_and_process_input(stdin, UA_sock);
81 bnet_sig(UA_sock, BNET_TERMINATE); /* send EOF */
88 Then the read\_and\_process\_input routine looks like the following:
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;
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}
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.
111 Bat has now a bRestore panel that uses Bvfs to display files and
116 \includegraphics[width=12cm]{\idir bat-brestore}
117 \label{fig:batbrestore}
118 \caption{Bat Brestore Panel}
121 The Bvfs module works correctly with BaseJobs, Copy and Migration jobs.
124 This project was funded by Bacula Systems.
126 \subsection*{General notes}
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
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
143 \subsection*{Get dependent jobs from a given JobId}
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.
148 To get all JobId needed to restore a particular job, you can use the
149 \texttt{.bvfs\_get\_jobids} command.
152 .bvfs_get_jobids jobid=num [all]
156 .bvfs_get_jobids jobid=10
158 .bvfs_get_jobids jobid=10 all
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.
165 With the \texttt{all} option, the Director will use all defined FileSet for
168 \subsection*{Generating Bvfs cache}
170 The \texttt{.bvfs\_update} command computes the directory cache for jobs
171 specified in argument, or for all jobs if unspecified.
174 .bvfs_update [jobid=numlist]
179 .bvfs_update jobid=1,2,3
182 You can run the cache update process in a RunScript after the catalog backup.
184 \subsection*{Get all versions of a specific file}
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
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
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
205 \subsection*{List directories}
207 Bvfs allows you to list directories in a specific path.
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
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.
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/
227 In this example, to list directories present in \texttt{regress/}, you can use
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/
235 \subsection*{List files}
237 Bvfs allows you to list files in a specific path.
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
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
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/
257 In this example, to list files present in \texttt{regress/}, you can use
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
267 \subsection*{Restore set of files}
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.
273 .bvfs_restore fileid=numlist dirid=numlist hardlink=numlist path=b2num
275 restore file=?b2num ...
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.
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
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).
292 .bvfs_restore fileid=1,2,3,4 hardlink=10,15,10,20 jobid=10 path=b20001
296 \subsection*{Cleanup after Restore}
298 To drop the table used by the restore command, you can use the
299 \texttt{.bvfs\_cleanup} command.
302 .bvfs_cleanup path=b20001
305 \subsection*{Clearing the BVFS Cache}
307 To clear the BVFS cache, you can use the \texttt{.bvfs\_clear\_cache} command.
310 .bvfs_clear_cache yes