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