]> git.sur5r.net Git - bacula/docs/blob - docs/developers/catalog.tex
Doc updates
[bacula/docs] / docs / developers / catalog.tex
1 %%
2 %%
3
4 \section*{Catalog Services}
5 \label{_ChapterStart30}
6 \index[general]{Services!Catalog }
7 \index[general]{Catalog Services }
8 \addcontentsline{toc}{section}{Catalog Services}
9
10 \subsection*{General}
11 \index[general]{General }
12 \addcontentsline{toc}{subsection}{General}
13
14 This chapter is intended to be a technical discussion of the Catalog services
15 and as such is not targeted at end users but rather at developers and system
16 administrators that want or need to know more of the working details of {\bf
17 Bacula}. 
18
19 The {\bf Bacula Catalog} services consist of the programs that provide the SQL
20 database engine for storage and retrieval of all information concerning files
21 that were backed up and their locations on the storage media. 
22
23 We have investigated the possibility of using the following SQL engines for
24 Bacula: Beagle, mSQL, GNU SQL, PostgreSQL, SQLite, Oracle, and MySQL. Each
25 presents certain problems with either licensing or maturity. At present, we
26 have chosen for development purposes to use MySQL, PostgreSQL and SQLite.
27 MySQL was chosen because it is fast, proven to be reliable, widely used, and
28 actively being developed. MySQL is released under the GNU GPL license.
29 PostgreSQL was chosen because it is a full-featured, very mature database, and
30 because Dan Langille did the Bacula driver for it. PostgreSQL is distributed
31 under the BSD license. SQLite was chosen because it is small, efficient, and
32 can be directly embedded in {\bf Bacula} thus requiring much less effort from
33 the system administrator or person building {\bf Bacula}. In our testing
34 SQLite has performed very well, and for the functions that we use, it has
35 never encountered any errors except that it does not appear to handle
36 databases larger than 2GBytes. That said, we would not recommend it for
37 serious production use.
38
39 The Bacula SQL code has been written in a manner that will allow it to be
40 easily modified to support any of the current SQL database systems on the
41 market (for example: mSQL, iODBC, unixODBC, Solid, OpenLink ODBC, EasySoft
42 ODBC, InterBase, Oracle8, Oracle7, and DB2). 
43
44 If you do not specify either {\bf \verb{--{with-mysql} or {\bf \verb{--{with-postgresql} or
45 {\bf \verb{--{with-sqlite} on the ./configure line, Bacula will use its minimalist
46 internal database. This database is kept for build reasons but is no longer
47 supported. Bacula {\bf requires} one of the three databases (MySQL,
48 PostgreSQL, or SQLite) to run. 
49
50 \subsubsection*{Filenames and Maximum Filename Length}
51 \index[general]{Filenames and Maximum Filename Length }
52 \index[general]{Length!Filenames and Maximum Filename }
53 \addcontentsline{toc}{subsubsection}{Filenames and Maximum Filename Length}
54
55 In general, either MySQL, PostgreSQL or SQLite permit storing arbitrary long
56 path names and file names in the catalog database. In practice, there still
57 may be one or two places in the Catalog interface code that restrict the
58 maximum path length to 512 characters and the maximum file name length to 512
59 characters. These restrictions are believed to have been removed. Please note,
60 these restrictions apply only to the Catalog database and thus to your ability
61 to list online the files saved during any job. All information received and
62 stored by the Storage daemon (normally on tape) allows and handles arbitrarily
63 long path and filenames. 
64
65 \subsubsection*{Installing and Configuring MySQL}
66 \index[general]{MySQL!Installing and Configuring }
67 \index[general]{Installing and Configuring MySQL }
68 \addcontentsline{toc}{subsubsection}{Installing and Configuring MySQL}
69
70 For the details of installing and configuring MySQL, please see the 
71 \ilink{Installing and Configuring MySQL}{_ChapterStart} chapter of
72 this manual. 
73
74 \subsubsection*{Installing and Configuring PostgreSQL}
75 \index[general]{PostgreSQL!Installing and Configuring }
76 \index[general]{Installing and Configuring PostgreSQL }
77 \addcontentsline{toc}{subsubsection}{Installing and Configuring PostgreSQL}
78
79 For the details of installing and configuring PostgreSQL, please see the 
80 \ilink{Installing and Configuring PostgreSQL}{_ChapterStart10}
81 chapter of this manual. 
82
83 \subsubsection*{Installing and Configuring SQLite}
84 \index[general]{Installing and Configuring SQLite }
85 \index[general]{SQLite!Installing and Configuring }
86 \addcontentsline{toc}{subsubsection}{Installing and Configuring SQLite}
87
88 For the details of installing and configuring SQLite, please see the 
89 \ilink{Installing and Configuring SQLite}{_ChapterStart33} chapter of
90 this manual. 
91
92 \subsubsection*{Internal Bacula Catalog}
93 \index[general]{Catalog!Internal Bacula }
94 \index[general]{Internal Bacula Catalog }
95 \addcontentsline{toc}{subsubsection}{Internal Bacula Catalog}
96
97 Please see the 
98 \ilink{Internal Bacula Database}{_ChapterStart42} chapter of this
99 manual for more details. 
100
101 \subsubsection*{Database Table Design}
102 \index[general]{Design!Database Table }
103 \index[general]{Database Table Design }
104 \addcontentsline{toc}{subsubsection}{Database Table Design}
105
106 All discussions that follow pertain to the MySQL database. The details for the
107 PostgreSQL and SQLite databases are essentially identical except for that all
108 fields in the SQLite database are stored as ASCII text and some of the
109 database creation statements are a bit different. The details of the internal
110 Bacula catalog are not discussed here. 
111
112 Because the Catalog database may contain very large amounts of data for large
113 sites, we have made a modest attempt to normalize the data tables to reduce
114 redundant information. While reducing the size of the database significantly,
115 it does, unfortunately, add some complications to the structures. 
116
117 In simple terms, the Catalog database must contain a record of all Jobs run by
118 Bacula, and for each Job, it must maintain a list of all files saved, with
119 their File Attributes (permissions, create date, ...), and the location and
120 Media on which the file is stored. This is seemingly a simple task, but it
121 represents a huge amount interlinked data. Note: the list of files and their
122 attributes is not maintained when using the internal Bacula database. The data
123 stored in the File records, which allows the user or administrator to obtain a
124 list of all files backed up during a job, is by far the largest volume of
125 information put into the Catalog database. 
126
127 Although the Catalog database has been designed to handle backup data for
128 multiple clients, some users may want to maintain multiple databases, one for
129 each machine to be backed up. This reduces the risk of confusion of accidental
130 restoring a file to the wrong machine as well as reducing the amount of data
131 in a single database, thus increasing efficiency and reducing the impact of a
132 lost or damaged database. 
133
134 \subsection*{Sequence of Creation of Records for a Save Job}
135 \index[general]{Sequence of Creation of Records for a Save Job }
136 \index[general]{Job!Sequence of Creation of Records for a Save }
137 \addcontentsline{toc}{subsection}{Sequence of Creation of Records for a Save
138 Job}
139
140 Start with StartDate, ClientName, Filename, Path, Attributes, MediaName,
141 MediaCoordinates. (PartNumber, NumParts). In the steps below, ``Create new''
142 means to create a new record whether or not it is unique. ``Create unique''
143 means each record in the database should be unique. Thus, one must first
144 search to see if the record exists, and only if not should a new one be
145 created, otherwise the existing RecordId should be used. 
146
147 \begin{enumerate}
148 \item Create new Job record with StartDate; save JobId  
149 \item Create unique Media record; save MediaId  
150 \item Create unique Client record; save ClientId  
151 \item Create unique Filename record; save FilenameId  
152 \item Create unique Path record; save PathId  
153 \item Create unique Attribute record; save AttributeId  
154    store ClientId, FilenameId, PathId, and Attributes  
155 \item Create new File record  
156    store JobId, AttributeId, MediaCoordinates, etc  
157 \item Repeat steps 4 through 8 for each file  
158 \item Create a JobMedia record; save MediaId  
159 \item Update Job record filling in EndDate and other Job statistics 
160    \end{enumerate}
161
162 \subsection*{Database Tables}
163 \index[general]{Database Tables }
164 \index[general]{Tables!Database }
165 \addcontentsline{toc}{subsection}{Database Tables}
166
167 \addcontentsline{lot}{table}{Filename Table Layout}
168 \begin{longtable}{|l|l|l|}
169  \hline 
170 \multicolumn{3}{|l| }{\bf Filename  } \\
171  \hline 
172 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{l| }{\bf Data Type }
173 & \multicolumn{1}{l| }{\bf Remark  } \\
174  \hline 
175 {FilenameId } & {integer  } & {Primary Key  } \\
176  \hline 
177 {Name  } & {Blob  } & {Filename }
178 \\ \hline 
179
180 \end{longtable}
181
182 The {\bf Filename} table shown above contains the name of each file backed up
183 with the path removed. If different directories or machines contain the same
184 filename, only one copy will be saved in this table. 
185
186
187
188 \addcontentsline{lot}{table}{Path Table Layout}
189 \begin{longtable}{|l|l|l|}
190  \hline 
191 \multicolumn{3}{|l| }{\bf Path  } \\
192  \hline 
193 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
194 } & \multicolumn{1}{c| }{\bf Remark  } \\
195  \hline 
196 {PathId  } & {integer  } & {Primary Key  } \\
197  \hline 
198 {Path  } & {Blob } & {Full Path }
199 \\ \hline 
200
201 \end{longtable}
202
203 The {\bf Path} table contains shown above the path or directory names of all
204 directories on the system or systems. The filename and any MSDOS disk name are
205 stripped off. As with the filename, only one copy of each directory name is
206 kept regardless of how many machines or drives have the same directory. These
207 path names should be stored in Unix path name format. 
208
209 Some simple testing on a Linux file system indicates that separating the
210 filename and the path may be more complication than is warranted by the space
211 savings. For example, this system has a total of 89,097 files, 60,467 of which
212 have unique filenames, and there are 4,374 unique paths. 
213
214 Finding all those files and doing two stats() per file takes an average wall
215 clock time of 1 min 35 seconds on a 400MHz machine running RedHat 6.1 Linux. 
216
217 Finding all those files and putting them directly into a MySQL database with
218 the path and filename defined as TEXT, which is variable length up to 65,535
219 characters takes 19 mins 31 seconds and creates a 27.6 MByte database. 
220
221 Doing the same thing, but inserting them into Blob fields with the filename
222 indexed on the first 30 characters and the path name indexed on the 255 (max)
223 characters takes 5 mins 18 seconds and creates a 5.24 MB database. Rerunning
224 the job (with the database already created) takes about 2 mins 50 seconds. 
225
226 Running the same as the last one (Path and Filename Blob), but Filename
227 indexed on the first 30 characters and the Path on the first 50 characters
228 (linear search done there after) takes 5 mins on the average and creates a 3.4
229 MB database. Rerunning with the data already in the DB takes 3 mins 35
230 seconds. 
231
232 Finally, saving only the full path name rather than splitting the path and the
233 file, and indexing it on the first 50 characters takes 6 mins 43 seconds and
234 creates a 7.35 MB database. 
235
236
237
238 \addcontentsline{lot}{table}{File Table Layout}
239 \begin{longtable}{|l|l|l|}
240  \hline 
241 \multicolumn{3}{|l| }{\bf File  } \\
242  \hline 
243 \multicolumn{1}{|c| }{\bf Column Name  } & \multicolumn{1}{c| }{\bf Data Type
244 } & \multicolumn{1}{c| }{\bf Remark  } \\
245  \hline 
246 {FileId  } & {integer  } & {Primary Key  } \\
247  \hline 
248 {FileIndex  } & {integer  } & {The sequential file number in the Job  } \\
249  \hline 
250 {JobId  } & {integer  } & {Link to Job Record  } \\
251  \hline 
252 {PathId  } & {integer  } & {Link to Path Record  } \\
253  \hline 
254 {FilenameId  } & {integer  } & {Link to Filename Record  } \\
255  \hline 
256 {MarkId  } & {integer  } & {Used to mark files during Verify Jobs  } \\
257  \hline 
258 {LStat  } & {tinyblob } & {File attributes in base64 encoding  } \\
259  \hline 
260 {MD5  } & {tinyblob } & {MD5 signature in base64 encoding }
261 \\ \hline 
262
263 \end{longtable}
264
265 The {\bf File} table shown above contains one entry for each file backed up by
266 Bacula. Thus a file that is backed up multiple times (as is normal) will have
267 multiple entries in the File table. This will probably be the table with the
268 most number of records. Consequently, it is essential to keep the size of this
269 record to an absolute minimum. At the same time, this table must contain all
270 the information (or pointers to the information) about the file and where it
271 is backed up. Since a file may be backed up many times without having changed,
272 the path and filename are stored in separate tables. 
273
274 This table contains by far the largest amount of information in the Catalog
275 database, both from the stand point of number of records, and the stand point
276 of total database size. As a consequence, the user must take care to
277 periodically reduce the number of File records using the {\bf retention}
278 command in the Console program. 
279
280
281
282 \addcontentsline{lot}{table}{Job Table Layout}
283 \begin{longtable}{|l|l|p{2.5in}|}
284  \hline 
285 \multicolumn{3}{|l| }{\bf Job  } \\
286  \hline 
287 \multicolumn{1}{|c| }{\bf Column Name  } & \multicolumn{1}{c| }{\bf Data Type
288 } & \multicolumn{1}{c| }{\bf Remark  } \\
289  \hline 
290 {JobId  } & {integer  } & {Primary Key  } \\
291  \hline 
292 {Job  } & {tinyblob } & {Unique Job Name  } \\
293  \hline 
294 {Name  } & {tinyblob } & {Job Name  } \\
295  \hline 
296 {PurgedFiles  } & {tinyint  } & {Used by Bacula for purging/retention periods 
297 } \\
298  \hline 
299 {Type  } & {binary(1)  } & {Job Type: Backup, Copy, Clone, Archive, Migration 
300 } \\
301  \hline 
302 {Level  } & {binary(1)  } & {Job Level  } \\
303  \hline 
304 {ClientId  } & {integer  } & {Client index  } \\
305  \hline 
306 {JobStatus  } & {binary(1)  } & {Job Termination Status  } \\
307  \hline 
308 {SchedTime  } & {datetime } & {Time/date when Job scheduled  } \\
309  \hline 
310 {StartTime  } & {datetime } & {Time/date when Job started  } \\
311  \hline 
312 {EndTime  } & {datetime } & {Time/date when Job ended  } \\
313  \hline 
314 {JobTDate  } & {bigint  } & {Start day in Unix format but 64 bits;  used for
315 Retention period.  } \\
316  \hline 
317 {VolSessionId  } & {integer  } & {Unique Volume Session ID  } \\
318  \hline 
319 {VolSessionTime } & {integer  } & {Unique Volume Session Time  } \\
320  \hline 
321 {JobFiles  } & {integer  } & {Number of files saved in Job  } \\
322  \hline 
323 {JobBytes  } & {bigint  } & {Number of bytes saved in Job  } \\
324  \hline 
325 {JobErrors  } & {integer  } & {Number of errors during Job  } \\
326  \hline 
327 {JobMissingFiles } & {integer } & {Number of files not saved (not yet used)  }
328 \\
329  \hline 
330 {PoolId  } & {integer  } & {Link to Pool Record  } \\
331  \hline 
332 {FileSetId  } & {integer  } & {Link to FileSet Record  } \\
333  \hline 
334 {PurgedFiles  } & {tiny integer  } & {Set when all File records purged  } \\
335  \hline 
336 {HasBase  } & {tiny integer  } & {Set when Base Job run }
337 \\ \hline 
338
339 \end{longtable}
340
341 The {\bf Job} table contains one record for each Job run by Bacula. Thus
342 normally, there will be one per day per machine added to the database. Note,
343 the JobId is used to index Job records in the database, and it often is shown
344 to the user in the Console program. However, care must be taken with its use
345 as it is not unique from database to database. For example, the user may have
346 a database for Client data saved on machine Rufus and another database for
347 Client data saved on machine Roxie. In this case, the two database will each
348 have JobIds that match those in another database. For a unique reference to a
349 Job, see Job below. 
350
351 The Name field of the Job record corresponds to the Name resource record given
352 in the Director's configuration file. Thus it is a generic name, and it will
353 be normal to find many Jobs (or even all Jobs) with the same Name. 
354
355 The Job field contains a combination of the Name and the schedule time of the
356 Job by the Director. Thus for a given Director, even with multiple Catalog
357 databases, the Job will contain a unique name that represents the Job. 
358
359 For a given Storage daemon, the VolSessionId and VolSessionTime form a unique
360 identification of the Job. This will be the case even if multiple Directors
361 are using the same Storage daemon. 
362
363 The Job Type (or simply Type) can have one of the following values: 
364
365 \addcontentsline{lot}{table}{Job Types}
366 \begin{longtable}{|l|l|}
367  \hline 
368 \multicolumn{1}{|c| }{\bf Value  } & \multicolumn{1}{c| }{\bf Meaning  } \\
369  \hline 
370 {B  } & {Backup Job  } \\
371  \hline 
372 {V  } & {Verify Job  } \\
373  \hline 
374 {R  } & {Restore Job  } \\
375  \hline 
376 {C  } & {Console program (not in database)  } \\
377  \hline 
378 {D  } & {Admin Job  } \\
379  \hline 
380 {A  } & {Archive Job (not implemented) }
381 \\ \hline 
382
383 \end{longtable}
384
385 The JobStatus field specifies how the job terminated, and can be one of the
386 following: 
387
388 \addcontentsline{lot}{table}{Job Statuses}
389 \begin{longtable}{|l|l|}
390  \hline 
391 \multicolumn{1}{|c| }{\bf Value  } & \multicolumn{1}{c| }{\bf Meaning  } \\
392  \hline 
393 {C  } & {Created but not yet running  } \\
394  \hline 
395 {R  } & {Running  } \\
396  \hline 
397 {B  } & {Blocked  } \\
398  \hline 
399 {T  } & {Terminated normally  } \\
400  \hline 
401 {E  } & {Terminated in Error  } \\
402  \hline 
403 {e  } & {Non-fatal error  } \\
404  \hline 
405 {f  } & {Fatal error  } \\
406  \hline 
407 {D  } & {Verify Differences  } \\
408  \hline 
409 {A  } & {Canceled by the user  } \\
410  \hline 
411 {F  } & {Waiting on the File daemon  } \\
412  \hline 
413 {S  } & {Waiting on the Storage daemon  } \\
414  \hline 
415 {m  } & {Waiting for a new Volume to be mounted  } \\
416  \hline 
417 {M  } & {Waiting for a Mount  } \\
418  \hline 
419 {s  } & {Waiting for Storage resource  } \\
420  \hline 
421 {j  } & {Waiting for Job resource  } \\
422  \hline 
423 {c  } & {Waiting for Client resource  } \\
424  \hline 
425 {d  } & {Wating for Maximum jobs  } \\
426  \hline 
427 {t  } & {Waiting for Start Time  } \\
428  \hline 
429 {p  } & {Waiting for higher priority job to finish }
430 \\ \hline 
431
432 \end{longtable}
433
434
435
436 \addcontentsline{lot}{table}{File Sets Table Layout}
437 \begin{longtable}{|l|l|l|}
438  \hline 
439 \multicolumn{3}{|l| }{\bf FileSet  } \\
440  \hline 
441 \multicolumn{1}{|c| }{\bf Column Name  } & \multicolumn{1}{c| }{\bf Data Type\
442 \ \ } & \multicolumn{1}{c| }{\bf Remark  } \\
443  \hline 
444 {FileSetId  } & {integer  } & {Primary Key  } \\
445  \hline 
446 {FileSet  } & {tinyblob  } & {FileSet name  } \\
447  \hline 
448 {MD5  } & {tinyblob  } & {MD5 checksum of FileSet  } \\
449  \hline 
450 {CreateTime  } & {datetime  } & {Time and date Fileset created }
451 \\ \hline 
452
453 \end{longtable}
454
455 The {\bf FileSet} table contains one entry for each FileSet that is used. The
456 MD5 signature is kept to ensure that if the user changes anything inside the
457 FileSet, it will be detected and the new FileSet will be used. This is
458 particularly important when doing an incremental update. If the user deletes a
459 file or adds a file, we need to ensure that a Full backup is done prior to the
460 next incremental. 
461
462
463
464 \addcontentsline{lot}{table}{JobMedia Table Layout}
465 \begin{longtable}{|l|l|p{2.5in}|}
466  \hline 
467 \multicolumn{3}{|l| }{\bf JobMedia  } \\
468  \hline 
469 \multicolumn{1}{|c| }{\bf Column Name  } & \multicolumn{1}{c| }{\bf Data Type\
470 \ \ } & \multicolumn{1}{c| }{\bf Remark  } \\
471  \hline 
472 {JobMediaId  } & {integer  } & {Primary Key  } \\
473  \hline 
474 {JobId  } & {integer  } & {Link to Job Record  } \\
475  \hline 
476 {MediaId  } & {integer  } & {Link to Media Record  } \\
477  \hline 
478 {FirstIndex  } & {integer  } & {The index (sequence number)  of the first file
479 written for this Job to the Media  } \\
480  \hline 
481 {LastIndex  } & {integer  } & {The index  of the last file written for this
482 Job to the Media  } \\
483  \hline 
484 {StartFile  } & {integer  } & {The physical media (tape)  file number of the
485 first block written for this Job  } \\
486  \hline 
487 {EndFile  } & {integer  } & {The physical media (tape)  file number of the
488 last block written for this Job  } \\
489  \hline 
490 {StartBlock  } & {integer  } & {The number of the first  block written for
491 this Job  } \\
492  \hline 
493 {EndBlock  } & {integer  } & {The number of the last  block written for this
494 Job  } \\
495  \hline 
496 {VolIndex  } & {integer  } & {The Volume use sequence number  within the Job }
497 \\ \hline 
498
499 \end{longtable}
500
501 The {\bf JobMedia} table contains one entry for each volume written for the
502 current Job. If the Job spans 3 tapes, there will be three JobMedia records,
503 each containing the information to find all the files for the given JobId on
504 the tape. 
505
506
507
508 \addcontentsline{lot}{table}{Media Table Layout}
509 \begin{longtable}{|l|l|p{2.4in}|}
510  \hline 
511 \multicolumn{3}{|l| }{\bf Media  } \\
512  \hline 
513 \multicolumn{1}{|c| }{\bf Column Name  } & \multicolumn{1}{c| }{\bf Data Type\
514 \ \ } & \multicolumn{1}{c| }{\bf Remark  } \\
515  \hline 
516 {MediaId  } & {integer } & {Primary Key  } \\
517  \hline 
518 {VolumeName  } & {tinyblob } & {Volume name  } \\
519  \hline 
520 {Slot  } & {integer } & {Autochanger Slot number or zero  } \\
521  \hline 
522 {PoolId  } & {integer } & {Link to Pool Record  } \\
523  \hline 
524 {MediaType  } & {tinyblob } & {The MediaType supplied by the user  } \\
525  \hline 
526 {FirstWritten  } & {datetime } & {Time/date when first written  } \\
527  \hline 
528 {LastWritten  } & {datetime } & {Time/date when last written  } \\
529  \hline 
530 {LabelDate  } & {datetime } & {Time/date when tape labeled  } \\
531  \hline 
532 {VolJobs  } & {integer  } & {Number of jobs written to this media  } \\
533  \hline 
534 {VolFiles  } & {integer  } & {Number of files written to this media  } \\
535  \hline 
536 {VolBlocks  } & {integer  } & {Number of blocks written to this media  } \\
537  \hline 
538 {VolMounts  } & {integer  } & {Number of time media mounted  } \\
539  \hline 
540 {VolBytes  } & {bigint  } & {Number of bytes saved in Job  } \\
541  \hline 
542 {VolErrors  } & {integer  } & {Number of errors during Job  } \\
543  \hline 
544 {VolWrites  } & {integer  } & {Number of writes to media  } \\
545  \hline 
546 {MaxVolBytes  } & {bigint } & {Maximum bytes to put on this media  } \\
547  \hline 
548 {VolCapacityBytes } & {bigint } & {Capacity estimate for this volume  } \\
549  \hline 
550 {VolStatus  } & {enum  } & {Status of media: Full, Archive, Append, Recycle, 
551 Read-Only, Disabled, Error, Busy  } \\
552  \hline 
553 {Recycle  } & {tinyint  } & {Whether or not Bacula can recycle the Volumes:
554 Yes, No  } \\
555  \hline 
556 {VolRetention  } & {bigint  } & {64 bit seconds until expiration  } \\
557  \hline 
558 {VolUseDuration  } & {bigint  } & {64 bit seconds volume can be used  } \\
559  \hline 
560 {MaxVolJobs  } & {integer  } & {maximum jobs to put on Volume  } \\
561  \hline 
562 {MaxVolFiles  } & {integer  } & {maximume EOF marks to put on Volume }
563 \\ \hline 
564
565 \end{longtable}
566
567 The {\bf Volume} table (internally referred to as the Media table) contains
568 one entry for each volume, that is each tape, cassette (8mm, DLT, DAT, ...),
569 or file on which information is or was backed up. There is one Volume record
570 created for each of the NumVols specified in the Pool resource record. 
571
572
573
574 \addcontentsline{lot}{table}{Pool Table Layout}
575 \begin{longtable}{|l|l|p{2.4in}|}
576  \hline 
577 \multicolumn{3}{|l| }{\bf Pool  } \\
578  \hline 
579 \multicolumn{1}{|c| }{\bf Column Name  } & \multicolumn{1}{c| }{\bf Data Type
580 } & \multicolumn{1}{c| }{\bf Remark  } \\
581  \hline 
582 {PoolId  } & {integer  } & {Primary Key  } \\
583  \hline 
584 {Name  } & {Tinyblob } & {Pool Name  } \\
585  \hline 
586 {NumVols  } & {Integer  } & {Number of Volumes in the Pool  } \\
587  \hline 
588 {MaxVols  } & {Integer  } & {Maximum Volumes in the Pool  } \\
589  \hline 
590 {UseOnce  } & {tinyint  } & {Use volume once  } \\
591  \hline 
592 {UseCatalog  } & {tinyint  } & {Set to use catalog  } \\
593  \hline 
594 {AcceptAnyVolume } & {tinyint  } & {Accept any volume from Pool  } \\
595  \hline 
596 {VolRetention  } & {bigint  } & {64 bit seconds to retain volume  } \\
597  \hline 
598 {VolUseDuration  } & {bigint  } & {64 bit seconds volume can be used  } \\
599  \hline 
600 {MaxVolJobs  } & {integer  } & {max jobs on volume  } \\
601  \hline 
602 {MaxVolFiles  } & {integer  } & {max EOF marks to put on Volume  } \\
603  \hline 
604 {MaxVolBytes  } & {bigint  } & {max bytes to write on Volume  } \\
605  \hline 
606 {AutoPrune  } & {tinyint  } & {yes|no for autopruning  } \\
607  \hline 
608 {Recycle  } & {tinyint  } & {yes|no for allowing auto recycling of Volume  }
609 \\
610  \hline 
611 {PoolType  } & {enum  } & {Backup, Copy, Cloned, Archive, Migration  } \\
612  \hline 
613 {LabelFormat  } & {Tinyblob } & {Label format }
614 \\ \hline 
615
616 \end{longtable}
617
618 The {\bf Pool} table contains one entry for each media pool controlled by
619 Bacula in this database. One media record exists for each of the NumVols
620 contained in the Pool. The PoolType is a Bacula defined keyword. The MediaType
621 is defined by the administrator, and corresponds to the MediaType specified in
622 the Director's Storage definition record. The CurrentVol is the sequence
623 number of the Media record for the current volume. 
624
625
626
627 \addcontentsline{lot}{table}{Client Table Layout}
628 \begin{longtable}{|l|l|l|}
629  \hline 
630 \multicolumn{3}{|l| }{\bf Client  } \\
631  \hline 
632 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
633 } & \multicolumn{1}{c| }{\bf Remark  } \\
634  \hline 
635 {ClientId  } & {integer  } & {Primary Key  } \\
636  \hline 
637 {Name  } & {TinyBlob  } & {File Services Name  } \\
638  \hline 
639 {UName  } & {TinyBlob  } & {uname -a from Client (not yet used)  } \\
640  \hline 
641 {AutoPrune  } & {tinyint  } & {yes|no for autopruning  } \\
642  \hline 
643 {FileRetention  } & {bigint  } & {64 bit seconds to retain Files  } \\
644  \hline 
645 {JobRetention  } & {bigint  } & {64 bit seconds to retain Job }
646 \\ \hline 
647
648 \end{longtable}
649
650 The {\bf Client} table contains one entry for each machine backed up by Bacula
651 in this database. Normally the Name is a fully qualified domain name. 
652
653
654
655 \addcontentsline{lot}{table}{Unsaved Files Table Layout}
656 \begin{longtable}{|l|l|l|}
657  \hline 
658 \multicolumn{3}{|l| }{\bf UnsavedFiles  } \\
659  \hline 
660 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
661 } & \multicolumn{1}{c| }{\bf Remark  } \\
662  \hline 
663 {UnsavedId  } & {integer  } & {Primary Key  } \\
664  \hline 
665 {JobId  } & {integer  } & {JobId corresponding to this record  } \\
666  \hline 
667 {PathId  } & {integer  } & {Id of path  } \\
668  \hline 
669 {FilenameId  } & {integer  } & {Id of filename }
670 \\ \hline 
671
672 \end{longtable}
673
674 The {\bf UnsavedFiles} table contains one entry for each file that was not
675 saved. Note! This record is not yet implemented. 
676
677
678
679 \addcontentsline{lot}{table}{Counter Table Layout}
680 \begin{longtable}{|l|l|l|}
681  \hline 
682 \multicolumn{3}{|l| }{\bf Counter  } \\
683  \hline 
684 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
685 } & \multicolumn{1}{c| }{\bf Remark  } \\
686  \hline 
687 {Counter  } & {tinyblob  } & {Counter name  } \\
688  \hline 
689 {MinValue  } & {integer } & {Start/Min value for counter  } \\
690  \hline 
691 {MaxValue  } & {integer } & {Max value for counter  } \\
692  \hline 
693 {CurrentValue  } & {integer } & {Current counter value  } \\
694  \hline 
695 {WrapCounter  } & {tinyblob  } & {Name of another counter }
696 \\ \hline 
697
698 \end{longtable}
699
700 The {\bf Counter} table contains one entry for each permanent counter defined
701 by the user. 
702
703
704
705 \addcontentsline{lot}{table}{Version Table Layout}
706 \begin{longtable}{|l|l|l|}
707  \hline 
708 \multicolumn{3}{|l| }{\bf Version  } \\
709  \hline 
710 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
711 } & \multicolumn{1}{c| }{\bf Remark  } \\
712  \hline 
713 {VersionId  } & {integer  } & {Primary Key }
714 \\ \hline 
715
716 \end{longtable}
717
718 The {\bf Version} table defines the Bacula database version number. Bacula
719 checks this number before reading the database to ensure that it is compatible
720 with the Bacula binary file. 
721
722
723
724 \addcontentsline{lot}{table}{Base Files Table Layout}
725 \begin{longtable}{|l|l|l|}
726  \hline 
727 \multicolumn{3}{|l| }{\bf BaseFiles  } \\
728  \hline 
729 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
730 } & \multicolumn{1}{c| }{\bf Remark  } \\
731  \hline 
732 {BaseId  } & {integer  } & {Primary Key  } \\
733  \hline 
734 {BaseJobId  } & {integer  } & {JobId of Base Job  } \\
735  \hline 
736 {JobId  } & {integer  } & {Reference to Job  } \\
737  \hline 
738 {FileId  } & {integer  } & {Reference to File  } \\
739  \hline 
740 {FileIndex  } & {integer  } & {File Index number }
741 \\ \hline 
742
743 \end{longtable}
744
745 The {\bf BaseFiles} table contains all the File references for a particular
746 JobId that point to a Base file -- i.e. they were previously saved and hence
747 were not saved in the current JobId but in BaseJobId under FileId. FileIndex
748 is the index of the file, and is used for optimization of Restore jobs to
749 prevent the need to read the FileId record when creating the in memory tree.
750 This record is not yet implemented. 
751
752
753
754 \subsubsection*{MySQL Table Definition}
755 \index[general]{MySQL Table Definition }
756 \index[general]{Definition!MySQL Table }
757 \addcontentsline{toc}{subsubsection}{MySQL Table Definition}
758
759 The commands used to create the MySQL tables are as follows: 
760
761 \footnotesize
762 \begin{verbatim}
763 USE bacula;
764 CREATE TABLE Filename (
765   FilenameId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
766   Name BLOB NOT NULL,
767   PRIMARY KEY(FilenameId),
768   INDEX (Name(30))
769   );
770 CREATE TABLE Path (
771    PathId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
772    Path BLOB NOT NULL,
773    PRIMARY KEY(PathId),
774    INDEX (Path(50))
775    );
776 CREATE TABLE File (
777    FileId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
778    FileIndex INTEGER UNSIGNED NOT NULL DEFAULT 0,
779    JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
780    PathId INTEGER UNSIGNED NOT NULL REFERENCES Path,
781    FilenameId INTEGER UNSIGNED NOT NULL REFERENCES Filename,
782    MarkId INTEGER UNSIGNED NOT NULL DEFAULT 0,
783    LStat TINYBLOB NOT NULL,
784    MD5 TINYBLOB NOT NULL,
785    PRIMARY KEY(FileId),
786    INDEX (JobId),
787    INDEX (PathId),
788    INDEX (FilenameId)
789    );
790 CREATE TABLE Job (
791    JobId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
792    Job TINYBLOB NOT NULL,
793    Name TINYBLOB NOT NULL,
794    Type BINARY(1) NOT NULL,
795    Level BINARY(1) NOT NULL,
796    ClientId INTEGER NOT NULL REFERENCES Client,
797    JobStatus BINARY(1) NOT NULL,
798    SchedTime DATETIME NOT NULL,
799    StartTime DATETIME NOT NULL,
800    EndTime DATETIME NOT NULL,
801    JobTDate BIGINT UNSIGNED NOT NULL,
802    VolSessionId INTEGER UNSIGNED NOT NULL DEFAULT 0,
803    VolSessionTime INTEGER UNSIGNED NOT NULL DEFAULT 0,
804    JobFiles INTEGER UNSIGNED NOT NULL DEFAULT 0,
805    JobBytes BIGINT UNSIGNED NOT NULL,
806    JobErrors INTEGER UNSIGNED NOT NULL DEFAULT 0,
807    JobMissingFiles INTEGER UNSIGNED NOT NULL DEFAULT 0,
808    PoolId INTEGER UNSIGNED NOT NULL REFERENCES Pool,
809    FileSetId INTEGER UNSIGNED NOT NULL REFERENCES FileSet,
810    PurgedFiles TINYINT NOT NULL DEFAULT 0,
811    HasBase TINYINT NOT NULL DEFAULT 0,
812    PRIMARY KEY(JobId),
813    INDEX (Name(128))
814    );
815 CREATE TABLE FileSet (
816    FileSetId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
817    FileSet TINYBLOB NOT NULL,
818    MD5 TINYBLOB NOT NULL,
819    CreateTime DATETIME NOT NULL,
820    PRIMARY KEY(FileSetId)
821    );
822 CREATE TABLE JobMedia (
823    JobMediaId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
824    JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
825    MediaId INTEGER UNSIGNED NOT NULL REFERENCES Media,
826    FirstIndex INTEGER UNSIGNED NOT NULL DEFAULT 0,
827    LastIndex INTEGER UNSIGNED NOT NULL DEFAULT 0,
828    StartFile INTEGER UNSIGNED NOT NULL DEFAULT 0,
829    EndFile INTEGER UNSIGNED NOT NULL DEFAULT 0,
830    StartBlock INTEGER UNSIGNED NOT NULL DEFAULT 0,
831    EndBlock INTEGER UNSIGNED NOT NULL DEFAULT 0,
832    VolIndex INTEGER UNSIGNED NOT NULL DEFAULT 0,
833    PRIMARY KEY(JobMediaId),
834    INDEX (JobId, MediaId)
835    );
836 CREATE TABLE Media (
837    MediaId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
838    VolumeName TINYBLOB NOT NULL,
839    Slot INTEGER NOT NULL DEFAULT 0,
840    PoolId INTEGER UNSIGNED NOT NULL REFERENCES Pool,
841    MediaType TINYBLOB NOT NULL,
842    FirstWritten DATETIME NOT NULL,
843    LastWritten DATETIME NOT NULL,
844    LabelDate DATETIME NOT NULL,
845    VolJobs INTEGER UNSIGNED NOT NULL DEFAULT 0,
846    VolFiles INTEGER UNSIGNED NOT NULL DEFAULT 0,
847    VolBlocks INTEGER UNSIGNED NOT NULL DEFAULT 0,
848    VolMounts INTEGER UNSIGNED NOT NULL DEFAULT 0,
849    VolBytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
850    VolErrors INTEGER UNSIGNED NOT NULL DEFAULT 0,
851    VolWrites INTEGER UNSIGNED NOT NULL DEFAULT 0,
852    VolCapacityBytes BIGINT UNSIGNED NOT NULL,
853    VolStatus ENUM('Full', 'Archive', 'Append', 'Recycle', 'Purged',
854     'Read-Only', 'Disabled', 'Error', 'Busy', 'Used', 'Cleaning') NOT NULL,
855    Recycle TINYINT NOT NULL DEFAULT 0,
856    VolRetention BIGINT UNSIGNED NOT NULL DEFAULT 0,
857    VolUseDuration BIGINT UNSIGNED NOT NULL DEFAULT 0,
858    MaxVolJobs INTEGER UNSIGNED NOT NULL DEFAULT 0,
859    MaxVolFiles INTEGER UNSIGNED NOT NULL DEFAULT 0,
860    MaxVolBytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
861    InChanger TINYINT NOT NULL DEFAULT 0,
862    MediaAddressing TINYINT NOT NULL DEFAULT 0,
863    VolReadTime BIGINT UNSIGNED NOT NULL DEFAULT 0,
864    VolWriteTime BIGINT UNSIGNED NOT NULL DEFAULT 0,
865    PRIMARY KEY(MediaId),
866    INDEX (PoolId)
867    );
868 CREATE TABLE Pool (
869    PoolId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
870    Name TINYBLOB NOT NULL,
871    NumVols INTEGER UNSIGNED NOT NULL DEFAULT 0,
872    MaxVols INTEGER UNSIGNED NOT NULL DEFAULT 0,
873    UseOnce TINYINT NOT NULL,
874    UseCatalog TINYINT NOT NULL,
875    AcceptAnyVolume TINYINT DEFAULT 0,
876    VolRetention BIGINT UNSIGNED NOT NULL,
877    VolUseDuration BIGINT UNSIGNED NOT NULL,
878    MaxVolJobs INTEGER UNSIGNED NOT NULL DEFAULT 0,
879    MaxVolFiles INTEGER UNSIGNED NOT NULL DEFAULT 0,
880    MaxVolBytes BIGINT UNSIGNED NOT NULL,
881    AutoPrune TINYINT DEFAULT 0,
882    Recycle TINYINT DEFAULT 0,
883    PoolType ENUM('Backup', 'Copy', 'Cloned', 'Archive', 'Migration', 'Scratch') NOT NULL,
884    LabelFormat TINYBLOB,
885    Enabled TINYINT DEFAULT 1,
886    ScratchPoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
887    RecyclePoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
888    UNIQUE (Name(128)),
889    PRIMARY KEY (PoolId)
890    );
891 CREATE TABLE Client (
892    ClientId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
893    Name TINYBLOB NOT NULL,
894    Uname TINYBLOB NOT NULL,       /* full uname -a of client */
895    AutoPrune TINYINT DEFAULT 0,
896    FileRetention BIGINT UNSIGNED NOT NULL,
897    JobRetention  BIGINT UNSIGNED NOT NULL,
898    UNIQUE (Name(128)),
899    PRIMARY KEY(ClientId)
900    );
901 CREATE TABLE BaseFiles (
902    BaseId INTEGER UNSIGNED AUTO_INCREMENT,
903    BaseJobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
904    JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
905    FileId INTEGER UNSIGNED NOT NULL REFERENCES File,
906    FileIndex INTEGER UNSIGNED,
907    PRIMARY KEY(BaseId)
908    );
909 CREATE TABLE UnsavedFiles (
910    UnsavedId INTEGER UNSIGNED AUTO_INCREMENT,
911    JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
912    PathId INTEGER UNSIGNED NOT NULL REFERENCES Path,
913    FilenameId INTEGER UNSIGNED NOT NULL REFERENCES Filename,
914    PRIMARY KEY (UnsavedId)
915    );
916 CREATE TABLE Version (
917    VersionId INTEGER UNSIGNED NOT NULL
918    );
919 -- Initialize Version
920 INSERT INTO Version (VersionId) VALUES (7);
921 CREATE TABLE Counters (
922    Counter TINYBLOB NOT NULL,
923    MinValue INTEGER,
924    MaxValue INTEGER,
925    CurrentValue INTEGER,
926    WrapCounter TINYBLOB NOT NULL,
927    PRIMARY KEY (Counter(128))
928    );
929 \end{verbatim}
930 \normalsize