]> git.sur5r.net Git - bacula/docs/blob - docs/manuals/en/developers/catalog.tex
Fix inconsistancies with migrated and migration
[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/SHA1 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 {RealEndTime  } & {datetime } & {Time/date when original Job ended  } \\
314  \hline 
315 {JobTDate  } & {bigint  } & {Start day in Unix format but 64 bits;  used for
316 Retention period.  } \\
317  \hline 
318 {VolSessionId  } & {integer  } & {Unique Volume Session ID  } \\
319  \hline 
320 {VolSessionTime } & {integer  } & {Unique Volume Session Time  } \\
321  \hline 
322 {JobFiles  } & {integer  } & {Number of files saved in Job  } \\
323  \hline 
324 {JobBytes  } & {bigint  } & {Number of bytes saved in Job  } \\
325  \hline 
326 {JobErrors  } & {integer  } & {Number of errors during Job  } \\
327  \hline 
328 {JobMissingFiles } & {integer } & {Number of files not saved (not yet used)  }
329 \\
330  \hline 
331 {PoolId  } & {integer  } & {Link to Pool Record  } \\
332  \hline 
333 {FileSetId  } & {integer  } & {Link to FileSet Record  } \\
334  \hline 
335 {PrioJobId  } & {integer  } & {Link to prior Job Record when migrated } \\
336  \hline 
337 {PurgedFiles  } & {tiny integer  } & {Set when all File records purged  } \\
338  \hline 
339 {HasBase  } & {tiny integer  } & {Set when Base Job run }
340 \\ \hline 
341
342 \end{longtable}
343
344 The {\bf Job} table contains one record for each Job run by Bacula. Thus
345 normally, there will be one per day per machine added to the database. Note,
346 the JobId is used to index Job records in the database, and it often is shown
347 to the user in the Console program. However, care must be taken with its use
348 as it is not unique from database to database. For example, the user may have
349 a database for Client data saved on machine Rufus and another database for
350 Client data saved on machine Roxie. In this case, the two database will each
351 have JobIds that match those in another database. For a unique reference to a
352 Job, see Job below. 
353
354 The Name field of the Job record corresponds to the Name resource record given
355 in the Director's configuration file. Thus it is a generic name, and it will
356 be normal to find many Jobs (or even all Jobs) with the same Name. 
357
358 The Job field contains a combination of the Name and the schedule time of the
359 Job by the Director. Thus for a given Director, even with multiple Catalog
360 databases, the Job will contain a unique name that represents the Job. 
361
362 For a given Storage daemon, the VolSessionId and VolSessionTime form a unique
363 identification of the Job. This will be the case even if multiple Directors
364 are using the same Storage daemon. 
365
366 The Job Type (or simply Type) can have one of the following values: 
367
368 \addcontentsline{lot}{table}{Job Types}
369 \begin{longtable}{|l|l|}
370  \hline 
371 \multicolumn{1}{|c| }{\bf Value  } & \multicolumn{1}{c| }{\bf Meaning  } \\
372  \hline 
373 {B  } & {Backup Job  } \\
374  \hline 
375 {M  } & {Migrated Job  } \\
376  \hline 
377 {V  } & {Verify Job  } \\
378  \hline 
379 {R  } & {Restore Job  } \\
380  \hline 
381 {C  } & {Console program (not in database)  } \\
382  \hline 
383 {I  } & {Internal or system Job  } \\
384  \hline 
385 {D  } & {Admin Job  } \\
386  \hline 
387 {A  } & {Archive Job (not implemented) }
388 \\ \hline 
389 {C  } & {Copy Job  } \\
390  \hline 
391 {g  } & {Migration Job  } \\
392  \hline 
393
394 \end{longtable}
395 Note, the Job Type values noted above are not kept in an SQL table.
396
397
398 The JobStatus field specifies how the job terminated, and can be one of the
399 following: 
400
401 \addcontentsline{lot}{table}{Job Statuses}
402 \begin{longtable}{|l|l|}
403  \hline 
404 \multicolumn{1}{|c| }{\bf Value  } & \multicolumn{1}{c| }{\bf Meaning  } \\
405  \hline 
406 {C  } & {Created but not yet running  } \\
407  \hline 
408 {R  } & {Running  } \\
409  \hline 
410 {B  } & {Blocked  } \\
411  \hline 
412 {T  } & {Terminated normally  } \\
413  \hline 
414 {W  } & {Terminated normally with warnings }
415 \\ \hline 
416 {E  } & {Terminated in Error  } \\
417  \hline 
418 {e  } & {Non-fatal error  } \\
419  \hline 
420 {f  } & {Fatal error  } \\
421  \hline 
422 {D  } & {Verify Differences  } \\
423  \hline 
424 {A  } & {Canceled by the user  } \\
425  \hline 
426 {I  } & {Incomplete Job }
427 \\ \hline 
428 {F  } & {Waiting on the File daemon  } \\
429  \hline 
430 {S  } & {Waiting on the Storage daemon  } \\
431  \hline 
432 {m  } & {Waiting for a new Volume to be mounted  } \\
433  \hline 
434 {M  } & {Waiting for a Mount  } \\
435  \hline 
436 {s  } & {Waiting for Storage resource  } \\
437  \hline 
438 {j  } & {Waiting for Job resource  } \\
439  \hline 
440 {c  } & {Waiting for Client resource  } \\
441  \hline 
442 {d  } & {Wating for Maximum jobs  } \\
443  \hline 
444 {t  } & {Waiting for Start Time  } \\
445  \hline 
446 {p  } & {Waiting for higher priority job to finish }
447 \\ \hline 
448 {i  } & {Doing batch insert file records }
449 \\ \hline 
450 {a  } & {SD despooling attributes }
451 \\ \hline 
452 {l  } & {Doing data despooling }
453 \\ \hline 
454 {L  } & {Committing data (last despool) }
455 \\ \hline 
456
457
458
459 \end{longtable}
460
461 \addcontentsline{lot}{table}{File Sets Table Layout}
462 \begin{longtable}{|l|l|l|}
463  \hline 
464 \multicolumn{3}{|l| }{\bf FileSet  } \\
465  \hline 
466 \multicolumn{1}{|c| }{\bf Column Name  } & \multicolumn{1}{c| }{\bf Data Type\
467 \ \ } & \multicolumn{1}{c| }{\bf Remark  } \\
468  \hline 
469 {FileSetId  } & {integer  } & {Primary Key  } \\
470  \hline 
471 {FileSet  } & {tinyblob  } & {FileSet name  } \\
472  \hline 
473 {MD5  } & {tinyblob  } & {MD5 checksum of FileSet  } \\
474  \hline 
475 {CreateTime  } & {datetime  } & {Time and date Fileset created }
476 \\ \hline 
477
478 \end{longtable}
479
480 The {\bf FileSet} table contains one entry for each FileSet that is used. The
481 MD5 signature is kept to ensure that if the user changes anything inside the
482 FileSet, it will be detected and the new FileSet will be used. This is
483 particularly important when doing an incremental update. If the user deletes a
484 file or adds a file, we need to ensure that a Full backup is done prior to the
485 next incremental. 
486
487
488 \addcontentsline{lot}{table}{JobMedia Table Layout}
489 \begin{longtable}{|l|l|p{2.5in}|}
490  \hline 
491 \multicolumn{3}{|l| }{\bf JobMedia  } \\
492  \hline 
493 \multicolumn{1}{|c| }{\bf Column Name  } & \multicolumn{1}{c| }{\bf Data Type\
494 \ \ } & \multicolumn{1}{c| }{\bf Remark  } \\
495  \hline 
496 {JobMediaId  } & {integer  } & {Primary Key  } \\
497  \hline 
498 {JobId  } & {integer  } & {Link to Job Record  } \\
499  \hline 
500 {MediaId  } & {integer  } & {Link to Media Record  } \\
501  \hline 
502 {FirstIndex  } & {integer  } & {The index (sequence number)  of the first file
503 written for this Job to the Media  } \\
504  \hline 
505 {LastIndex  } & {integer  } & {The index  of the last file written for this
506 Job to the Media  } \\
507  \hline 
508 {StartFile  } & {integer  } & {The physical media (tape)  file number of the
509 first block written for this Job  } \\
510  \hline 
511 {EndFile  } & {integer  } & {The physical media (tape)  file number of the
512 last block written for this Job  } \\
513  \hline 
514 {StartBlock  } & {integer  } & {The number of the first  block written for
515 this Job  } \\
516  \hline 
517 {EndBlock  } & {integer  } & {The number of the last  block written for this
518 Job  } \\
519  \hline 
520 {VolIndex  } & {integer  } & {The Volume use sequence number  within the Job }
521 \\ \hline 
522
523 \end{longtable}
524
525 The {\bf JobMedia} table contains one entry at the following: start of
526 the job, start of each new tape file, start of each new tape, end of the
527 job.  Since by default, a new tape file is written every 2GB, in general,
528 you will have more than 2 JobMedia records per Job.  The number can be
529 varied by changing the "Maximum File Size" specified in the Device 
530 resource.  This record allows Bacula to efficiently position close to
531 (within 2GB) any given file in a backup.  For restoring a full Job,
532 these records are not very important, but if you want to retrieve
533 a single file that was written near the end of a 100GB backup, the   
534 JobMedia records can speed it up by orders of magnitude by permitting
535 forward spacing files and blocks rather than reading the whole 100GB
536 backup.
537         
538
539
540
541 \addcontentsline{lot}{table}{Media Table Layout}
542 \begin{longtable}{|l|l|p{2.4in}|}
543  \hline 
544 \multicolumn{3}{|l| }{\bf Media  } \\
545  \hline 
546 \multicolumn{1}{|c| }{\bf Column Name  } & \multicolumn{1}{c| }{\bf Data Type\
547 \ \ } & \multicolumn{1}{c| }{\bf Remark  } \\
548  \hline 
549 {MediaId  } & {integer } & {Primary Key  } \\
550  \hline 
551 {VolumeName  } & {tinyblob } & {Volume name  } \\
552  \hline 
553 {Slot  } & {integer } & {Autochanger Slot number or zero  } \\
554  \hline 
555 {PoolId  } & {integer } & {Link to Pool Record  } \\
556  \hline 
557 {MediaType  } & {tinyblob } & {The MediaType supplied by the user  } \\
558  \hline 
559 {MediaTypeId  } & {integer } & {The MediaTypeId } \\
560  \hline 
561 {LabelType  } & {tinyint } & {The type of label on the Volume  } \\
562  \hline 
563 {FirstWritten  } & {datetime } & {Time/date when first written  } \\
564  \hline 
565 {LastWritten  } & {datetime } & {Time/date when last written  } \\
566  \hline 
567 {LabelDate  } & {datetime } & {Time/date when tape labeled  } \\
568  \hline 
569 {VolJobs  } & {integer  } & {Number of jobs written to this media  } \\
570  \hline 
571 {VolFiles  } & {integer  } & {Number of files written to this media  } \\
572  \hline 
573 {VolBlocks  } & {integer  } & {Number of blocks written to this media  } \\
574  \hline 
575 {VolMounts  } & {integer  } & {Number of time media mounted  } \\
576  \hline 
577 {VolBytes  } & {bigint  } & {Number of bytes saved in Job  } \\
578  \hline 
579 {VolParts  } & {integer } & {The number of parts for a Volume (DVD)  } \\
580  \hline 
581 {VolErrors  } & {integer  } & {Number of errors during Job  } \\
582  \hline 
583 {VolWrites  } & {integer  } & {Number of writes to media  } \\
584  \hline 
585 {MaxVolBytes  } & {bigint } & {Maximum bytes to put on this media  } \\
586  \hline 
587 {VolCapacityBytes } & {bigint } & {Capacity estimate for this volume  } \\
588  \hline 
589 {VolStatus  } & {enum  } & {Status of media: Full, Archive, Append, Recycle, 
590 Read-Only, Disabled, Error, Busy  } \\
591  \hline 
592 {Enabled } {tinyint  } & {Whether or not Volume can be written } \\
593  \hline 
594 {Recycle  } & {tinyint  } & {Whether or not Bacula can recycle the Volumes:
595 Yes, No  } \\
596  \hline 
597 {ActionOnPurge  } & {tinyint  } & {What happens to a Volume after purging  } \\
598  \hline 
599 {VolRetention  } & {bigint  } & {64 bit seconds until expiration  } \\
600  \hline 
601 {VolUseDuration  } & {bigint  } & {64 bit seconds volume can be used  } \\
602  \hline 
603 {MaxVolJobs  } & {integer  } & {maximum jobs to put on Volume  } \\
604  \hline 
605 {MaxVolFiles  } & {integer  } & {maximume EOF marks to put on Volume }
606 \\ \hline 
607 {InChanger  } & {tinyint  } & {Whether or not Volume in autochanger } \\
608  \hline 
609 {StorageId  } & {integer  } & {Storage record ID } \\
610  \hline 
611 {DeviceId  } & {integer  } & {Device record ID } \\
612  \hline 
613 {MediaAddressing  } & {integer } & {Method of addressing media } \\
614  \hline 
615 {VolReadTime  } & {bigint  } & {Time Reading Volume } \\
616  \hline 
617 {VolWriteTime  } & {bigint  } & {Time Writing Volume } \\
618  \hline 
619 {EndFile  } & {integer  } & {End File number of Volume } \\
620  \hline 
621 {EndBlock  } & {integer  } & {End block number of Volume } \\
622  \hline 
623 {LocationId  } & {integer  } & {Location record ID } \\
624  \hline 
625 {RecycleCount  } & {integer  } & {Number of times recycled } \\
626  \hline 
627 {InitialWrite  } & {datetime  } & {When Volume first written } \\
628  \hline 
629 {ScratchPoolId  } & {integer  } & {Id of Scratch Pool  } \\
630  \hline 
631 {RecyclePoolId  } & {integer  } & {Pool ID where to recycle Volume } \\
632  \hline 
633 {Comment  } & {blob  } & {User text field } \\
634  \hline 
635
636
637 \end{longtable}
638
639 The {\bf Volume} table (internally referred to as the Media table) contains
640 one entry for each volume, that is each tape, cassette (8mm, DLT, DAT, ...),
641 or file on which information is or was backed up. There is one Volume record
642 created for each of the NumVols specified in the Pool resource record. 
643
644
645
646 \addcontentsline{lot}{table}{Pool Table Layout}
647 \begin{longtable}{|l|l|p{2.4in}|}
648  \hline 
649 \multicolumn{3}{|l| }{\bf Pool  } \\
650  \hline 
651 \multicolumn{1}{|c| }{\bf Column Name  } & \multicolumn{1}{c| }{\bf Data Type
652 } & \multicolumn{1}{c| }{\bf Remark  } \\
653  \hline 
654 {PoolId  } & {integer  } & {Primary Key  } \\
655  \hline 
656 {Name  } & {Tinyblob } & {Pool Name  } \\
657  \hline 
658 {NumVols  } & {Integer  } & {Number of Volumes in the Pool  } \\
659  \hline 
660 {MaxVols  } & {Integer  } & {Maximum Volumes in the Pool  } \\
661  \hline 
662 {UseOnce  } & {tinyint  } & {Use volume once  } \\
663  \hline 
664 {UseCatalog  } & {tinyint  } & {Set to use catalog  } \\
665  \hline 
666 {AcceptAnyVolume } & {tinyint  } & {Accept any volume from Pool  } \\
667  \hline 
668 {VolRetention  } & {bigint  } & {64 bit seconds to retain volume  } \\
669  \hline 
670 {VolUseDuration  } & {bigint  } & {64 bit seconds volume can be used  } \\
671  \hline 
672 {MaxVolJobs  } & {integer  } & {max jobs on volume  } \\
673  \hline 
674 {MaxVolFiles  } & {integer  } & {max EOF marks to put on Volume  } \\
675  \hline 
676 {MaxVolBytes  } & {bigint  } & {max bytes to write on Volume  } \\
677  \hline 
678 {AutoPrune  } & {tinyint  } & {yes|no for autopruning  } \\
679  \hline 
680 {Recycle  } & {tinyint  } & {yes|no for allowing auto recycling of Volume  } \\
681  \hline 
682 {ActionOnPurge  } & {tinyint  } & {Default Volume ActionOnPurge  } \\
683  \hline 
684 {PoolType  } & {enum  } & {Backup, Copy, Cloned, Archive, Migration  } \\
685  \hline 
686 {LabelType  } & {tinyint  } & {Type of label ANSI/Bacula  } \\
687  \hline 
688 {LabelFormat  } & {Tinyblob } & {Label format }
689 \\ \hline 
690 {Enabled } {tinyint  } & {Whether or not Volume can be written } \\
691  \hline 
692 {ScratchPoolId  } & {integer  } & {Id of Scratch Pool  } \\
693  \hline 
694 {RecyclePoolId  } & {integer  } & {Pool ID where to recycle Volume } \\
695  \hline 
696 {NextPoolId  } & {integer  } & {Pool ID of next Pool } \\
697  \hline 
698 {MigrationHighBytes  } & {bigint  } & {High water mark for migration } \\
699  \hline 
700 {MigrationLowBytes  } & {bigint  } & {Low water mark for migration } \\
701  \hline 
702 {MigrationTime  } & {bigint  } & {Time before migration } \\
703  \hline 
704
705
706
707 \end{longtable}
708
709 The {\bf Pool} table contains one entry for each media pool controlled by
710 Bacula in this database. One media record exists for each of the NumVols
711 contained in the Pool. The PoolType is a Bacula defined keyword. The MediaType
712 is defined by the administrator, and corresponds to the MediaType specified in
713 the Director's Storage definition record. The CurrentVol is the sequence
714 number of the Media record for the current volume. 
715
716
717
718 \addcontentsline{lot}{table}{Client Table Layout}
719 \begin{longtable}{|l|l|l|}
720  \hline 
721 \multicolumn{3}{|l| }{\bf Client  } \\
722  \hline 
723 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
724 } & \multicolumn{1}{c| }{\bf Remark  } \\
725  \hline 
726 {ClientId  } & {integer  } & {Primary Key  } \\
727  \hline 
728 {Name  } & {TinyBlob  } & {File Services Name  } \\
729  \hline 
730 {UName  } & {TinyBlob  } & {uname -a from Client (not yet used)  } \\
731  \hline 
732 {AutoPrune  } & {tinyint  } & {yes|no for autopruning  } \\
733  \hline 
734 {FileRetention  } & {bigint  } & {64 bit seconds to retain Files  } \\
735  \hline 
736 {JobRetention  } & {bigint  } & {64 bit seconds to retain Job }
737 \\ \hline 
738
739 \end{longtable}
740
741 The {\bf Client} table contains one entry for each machine backed up by Bacula
742 in this database. Normally the Name is a fully qualified domain name. 
743
744
745 \addcontentsline{lot}{table}{Storage Table Layout}
746 \begin{longtable}{|l|l|l|}
747  \hline 
748 \multicolumn{3}{|l| }{\bf Storage  } \\
749  \hline 
750 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
751 } & \multicolumn{1}{c| }{\bf Remark  } \\
752  \hline 
753 {StorageId  } & {integer  } & {Unique Id  } \\
754  \hline 
755 {Name  } & {tinyblob } & {Resource name of Storage device  } \\
756  \hline 
757 {AutoChanger  } & {tinyint } & {Set if it is an autochanger  } \\
758  \hline 
759
760 \end{longtable}
761
762 The {\bf Storage} table contains one entry for each Storage used.
763
764
765 \addcontentsline{lot}{table}{Counter Table Layout}
766 \begin{longtable}{|l|l|l|}
767  \hline 
768 \multicolumn{3}{|l| }{\bf Counter  } \\
769  \hline 
770 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
771 } & \multicolumn{1}{c| }{\bf Remark  } \\
772  \hline 
773 {Counter  } & {tinyblob  } & {Counter name  } \\
774  \hline 
775 {MinValue  } & {integer } & {Start/Min value for counter  } \\
776  \hline 
777 {MaxValue  } & {integer } & {Max value for counter  } \\
778  \hline 
779 {CurrentValue  } & {integer } & {Current counter value  } \\
780  \hline 
781 {WrapCounter  } & {tinyblob  } & {Name of another counter }
782 \\ \hline 
783
784 \end{longtable}
785
786 The {\bf Counter} table contains one entry for each permanent counter defined
787 by the user. 
788
789 \addcontentsline{lot}{table}{Job History Table Layout}
790 \begin{longtable}{|l|l|p{2.5in}|}
791  \hline 
792 \multicolumn{3}{|l| }{\bf JobHisto  } \\
793  \hline 
794 \multicolumn{1}{|c| }{\bf Column Name  } & \multicolumn{1}{c| }{\bf Data Type
795 } & \multicolumn{1}{c| }{\bf Remark  } \\
796  \hline 
797 {JobId  } & {integer  } & {Primary Key  } \\
798  \hline 
799 {Job  } & {tinyblob } & {Unique Job Name  } \\
800  \hline 
801 {Name  } & {tinyblob } & {Job Name  } \\
802  \hline 
803 {Type  } & {binary(1)  } & {Job Type: Backup, Copy, Clone, Archive, Migration 
804 } \\
805  \hline 
806 {Level  } & {binary(1)  } & {Job Level  } \\
807  \hline 
808 {ClientId  } & {integer  } & {Client index  } \\
809  \hline 
810 {JobStatus  } & {binary(1)  } & {Job Termination Status  } \\
811  \hline 
812 {SchedTime  } & {datetime } & {Time/date when Job scheduled  } \\
813  \hline 
814 {StartTime  } & {datetime } & {Time/date when Job started  } \\
815  \hline 
816 {EndTime  } & {datetime } & {Time/date when Job ended  } \\
817  \hline 
818 {RealEndTime  } & {datetime } & {Time/date when original Job ended  } \\
819  \hline 
820 {JobTDate  } & {bigint  } & {Start day in Unix format but 64 bits;  used for
821 Retention period.  } \\
822  \hline 
823 {VolSessionId  } & {integer  } & {Unique Volume Session ID  } \\
824  \hline 
825 {VolSessionTime } & {integer  } & {Unique Volume Session Time  } \\
826  \hline 
827 {JobFiles  } & {integer  } & {Number of files saved in Job  } \\
828  \hline 
829 {JobBytes  } & {bigint  } & {Number of bytes saved in Job  } \\
830  \hline 
831 {JobErrors  } & {integer  } & {Number of errors during Job  } \\
832  \hline 
833 {JobMissingFiles } & {integer } & {Number of files not saved (not yet used)  }
834 \\
835  \hline 
836 {PoolId  } & {integer  } & {Link to Pool Record  } \\
837  \hline 
838 {FileSetId  } & {integer  } & {Link to FileSet Record  } \\
839  \hline 
840 {PrioJobId  } & {integer  } & {Link to prior Job Record when migrated } \\
841  \hline 
842 {PurgedFiles  } & {tiny integer  } & {Set when all File records purged  } \\
843  \hline 
844 {HasBase  } & {tiny integer  } & {Set when Base Job run }
845 \\ \hline 
846
847 \end{longtable}
848
849 The {bf JobHisto} table is the same as the Job table, but it keeps
850 long term statistics (i.e. it is not pruned with the Job).
851
852
853 \addcontentsline{lot}{table}{Log Table Layout}
854 \begin{longtable}{|l|l|l|}
855  \hline 
856 \multicolumn{3}{|l| }{\bf Version  } \\
857  \hline 
858 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
859 } & \multicolumn{1}{c| }{\bf Remark  } \\
860  \hline 
861 {LogIdId  } & {integer  } & {Primary Key }
862 \\ \hline 
863 {JobId  } & {integer  } & {Points to Job record }
864 \\ \hline 
865 {Time  } & {datetime  } & {Time/date log record created }
866 \\ \hline 
867 {LogText  } & {blob  } & {Log text }
868 \\ \hline 
869
870 \end{longtable}
871
872 The {\bf Log} table contains a log of all Job output.
873
874 \addcontentsline{lot}{table}{Location Table Layout}
875 \begin{longtable}{|l|l|l|}
876  \hline 
877 \multicolumn{3}{|l| }{\bf Location  } \\
878  \hline 
879 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
880 } & \multicolumn{1}{c| }{\bf Remark  } \\
881  \hline 
882 {LocationId  } & {integer  } & {Primary Key }
883 \\ \hline 
884 {Location  } & {tinyblob  } & {Text defining location }
885 \\ \hline 
886 {Cost  } & {integer  } & {Relative cost of obtaining Volume }
887 \\ \hline 
888 {Enabled  } & {tinyint  } & {Whether or not Volume is enabled }
889 \\ \hline 
890
891 \end{longtable}
892
893 The {\bf Location} table defines where a Volume is physically.
894
895
896 \addcontentsline{lot}{table}{Location Log Table Layout}
897 \begin{longtable}{|l|l|l|}
898  \hline 
899 \multicolumn{3}{|l| }{\bf LocationLog  } \\
900  \hline 
901 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
902 } & \multicolumn{1}{c| }{\bf Remark  } \\
903  \hline 
904 {locLogIdId  } & {integer  } & {Primary Key }
905 \\ \hline 
906 {Date  } & {datetime  } & {Time/date log record created }
907 \\ \hline 
908 {MediaId  } & {integer  } & {Points to Media record }
909 \\ \hline 
910 {LocationId  } & {integer  } & {Points to Location record }
911 \\ \hline 
912 {NewVolStatus  } & {integer  } & {enum: Full, Archive, Append, Recycle, Purged
913   Read-only, Disabled, Error, Busy, Used, Cleaning } 
914 \\ \hline 
915 {Enabled  } & {tinyint  } & {Whether or not Volume is enabled }
916 \\ \hline 
917
918
919 \end{longtable}
920
921 The {\bf Log} table contains a log of all Job output.
922
923
924 \addcontentsline{lot}{table}{Version Table Layout}
925 \begin{longtable}{|l|l|l|}
926  \hline 
927 \multicolumn{3}{|l| }{\bf Version  } \\
928  \hline 
929 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
930 } & \multicolumn{1}{c| }{\bf Remark  } \\
931  \hline 
932 {VersionId  } & {integer  } & {Primary Key }
933 \\ \hline 
934
935 \end{longtable}
936
937 The {\bf Version} table defines the Bacula database version number. Bacula
938 checks this number before reading the database to ensure that it is compatible
939 with the Bacula binary file. 
940
941
942 \addcontentsline{lot}{table}{Base Files Table Layout}
943 \begin{longtable}{|l|l|l|}
944  \hline 
945 \multicolumn{3}{|l| }{\bf BaseFiles  } \\
946  \hline 
947 \multicolumn{1}{|c| }{\bf Column Name } & \multicolumn{1}{c| }{\bf Data Type 
948 } & \multicolumn{1}{c| }{\bf Remark  } \\
949  \hline 
950 {BaseId  } & {integer  } & {Primary Key  } \\
951  \hline 
952 {BaseJobId  } & {integer  } & {JobId of Base Job  } \\
953  \hline 
954 {JobId  } & {integer  } & {Reference to Job  } \\
955  \hline 
956 {FileId  } & {integer  } & {Reference to File  } \\
957  \hline 
958 {FileIndex  } & {integer  } & {File Index number }
959 \\ \hline 
960
961 \end{longtable}
962
963 The {\bf BaseFiles} table contains all the File references for a particular
964 JobId that point to a Base file -- i.e. they were previously saved and hence
965 were not saved in the current JobId but in BaseJobId under FileId. FileIndex
966 is the index of the file, and is used for optimization of Restore jobs to
967 prevent the need to read the FileId record when creating the in memory tree.
968 This record is not yet implemented. 
969
970
971
972 \subsection{MySQL Table Definition}
973 \index[general]{MySQL Table Definition }
974 \index[general]{Definition!MySQL Table }
975 \addcontentsline{toc}{subsubsection}{MySQL Table Definition}
976
977 The commands used to create the MySQL tables are as follows: 
978
979 \footnotesize
980 \begin{verbatim}
981 USE bacula;
982 CREATE TABLE Filename (
983   FilenameId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
984   Name BLOB NOT NULL,
985   PRIMARY KEY(FilenameId),
986   INDEX (Name(30))
987   );
988 CREATE TABLE Path (
989    PathId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
990    Path BLOB NOT NULL,
991    PRIMARY KEY(PathId),
992    INDEX (Path(50))
993    );
994 CREATE TABLE File (
995    FileId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
996    FileIndex INTEGER UNSIGNED NOT NULL DEFAULT 0,
997    JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
998    PathId INTEGER UNSIGNED NOT NULL REFERENCES Path,
999    FilenameId INTEGER UNSIGNED NOT NULL REFERENCES Filename,
1000    MarkId INTEGER UNSIGNED NOT NULL DEFAULT 0,
1001    LStat TINYBLOB NOT NULL,
1002    MD5 TINYBLOB NOT NULL,
1003    PRIMARY KEY(FileId),
1004    INDEX (JobId),
1005    INDEX (PathId),
1006    INDEX (FilenameId)
1007    );
1008 CREATE TABLE Job (
1009    JobId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
1010    Job TINYBLOB NOT NULL,
1011    Name TINYBLOB NOT NULL,
1012    Type BINARY(1) NOT NULL,
1013    Level BINARY(1) NOT NULL,
1014    ClientId INTEGER NOT NULL REFERENCES Client,
1015    JobStatus BINARY(1) NOT NULL,
1016    SchedTime DATETIME NOT NULL,
1017    StartTime DATETIME NOT NULL,
1018    EndTime DATETIME NOT NULL,
1019    JobTDate BIGINT UNSIGNED NOT NULL,
1020    VolSessionId INTEGER UNSIGNED NOT NULL DEFAULT 0,
1021    VolSessionTime INTEGER UNSIGNED NOT NULL DEFAULT 0,
1022    JobFiles INTEGER UNSIGNED NOT NULL DEFAULT 0,
1023    JobBytes BIGINT UNSIGNED NOT NULL,
1024    JobErrors INTEGER UNSIGNED NOT NULL DEFAULT 0,
1025    JobMissingFiles INTEGER UNSIGNED NOT NULL DEFAULT 0,
1026    PoolId INTEGER UNSIGNED NOT NULL REFERENCES Pool,
1027    FileSetId INTEGER UNSIGNED NOT NULL REFERENCES FileSet,
1028    PurgedFiles TINYINT NOT NULL DEFAULT 0,
1029    HasBase TINYINT NOT NULL DEFAULT 0,
1030    PRIMARY KEY(JobId),
1031    INDEX (Name(128))
1032    );
1033 CREATE TABLE FileSet (
1034    FileSetId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
1035    FileSet TINYBLOB NOT NULL,
1036    MD5 TINYBLOB NOT NULL,
1037    CreateTime DATETIME NOT NULL,
1038    PRIMARY KEY(FileSetId)
1039    );
1040 CREATE TABLE JobMedia (
1041    JobMediaId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
1042    JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
1043    MediaId INTEGER UNSIGNED NOT NULL REFERENCES Media,
1044    FirstIndex INTEGER UNSIGNED NOT NULL DEFAULT 0,
1045    LastIndex INTEGER UNSIGNED NOT NULL DEFAULT 0,
1046    StartFile INTEGER UNSIGNED NOT NULL DEFAULT 0,
1047    EndFile INTEGER UNSIGNED NOT NULL DEFAULT 0,
1048    StartBlock INTEGER UNSIGNED NOT NULL DEFAULT 0,
1049    EndBlock INTEGER UNSIGNED NOT NULL DEFAULT 0,
1050    VolIndex INTEGER UNSIGNED NOT NULL DEFAULT 0,
1051    PRIMARY KEY(JobMediaId),
1052    INDEX (JobId, MediaId)
1053    );
1054 CREATE TABLE Media (
1055    MediaId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
1056    VolumeName TINYBLOB NOT NULL,
1057    Slot INTEGER NOT NULL DEFAULT 0,
1058    PoolId INTEGER UNSIGNED NOT NULL REFERENCES Pool,
1059    MediaType TINYBLOB NOT NULL,
1060    FirstWritten DATETIME NOT NULL,
1061    LastWritten DATETIME NOT NULL,
1062    LabelDate DATETIME NOT NULL,
1063    VolJobs INTEGER UNSIGNED NOT NULL DEFAULT 0,
1064    VolFiles INTEGER UNSIGNED NOT NULL DEFAULT 0,
1065    VolBlocks INTEGER UNSIGNED NOT NULL DEFAULT 0,
1066    VolMounts INTEGER UNSIGNED NOT NULL DEFAULT 0,
1067    VolBytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
1068    VolErrors INTEGER UNSIGNED NOT NULL DEFAULT 0,
1069    VolWrites INTEGER UNSIGNED NOT NULL DEFAULT 0,
1070    VolCapacityBytes BIGINT UNSIGNED NOT NULL,
1071    VolStatus ENUM('Full', 'Archive', 'Append', 'Recycle', 'Purged',
1072     'Read-Only', 'Disabled', 'Error', 'Busy', 'Used', 'Cleaning') NOT NULL,
1073    Recycle TINYINT NOT NULL DEFAULT 0,
1074    VolRetention BIGINT UNSIGNED NOT NULL DEFAULT 0,
1075    VolUseDuration BIGINT UNSIGNED NOT NULL DEFAULT 0,
1076    MaxVolJobs INTEGER UNSIGNED NOT NULL DEFAULT 0,
1077    MaxVolFiles INTEGER UNSIGNED NOT NULL DEFAULT 0,
1078    MaxVolBytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
1079    InChanger TINYINT NOT NULL DEFAULT 0,
1080    MediaAddressing TINYINT NOT NULL DEFAULT 0,
1081    VolReadTime BIGINT UNSIGNED NOT NULL DEFAULT 0,
1082    VolWriteTime BIGINT UNSIGNED NOT NULL DEFAULT 0,
1083    PRIMARY KEY(MediaId),
1084    INDEX (PoolId)
1085    );
1086 CREATE TABLE Pool (
1087    PoolId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
1088    Name TINYBLOB NOT NULL,
1089    NumVols INTEGER UNSIGNED NOT NULL DEFAULT 0,
1090    MaxVols INTEGER UNSIGNED NOT NULL DEFAULT 0,
1091    UseOnce TINYINT NOT NULL,
1092    UseCatalog TINYINT NOT NULL,
1093    AcceptAnyVolume TINYINT DEFAULT 0,
1094    VolRetention BIGINT UNSIGNED NOT NULL,
1095    VolUseDuration BIGINT UNSIGNED NOT NULL,
1096    MaxVolJobs INTEGER UNSIGNED NOT NULL DEFAULT 0,
1097    MaxVolFiles INTEGER UNSIGNED NOT NULL DEFAULT 0,
1098    MaxVolBytes BIGINT UNSIGNED NOT NULL,
1099    AutoPrune TINYINT DEFAULT 0,
1100    Recycle TINYINT DEFAULT 0,
1101    PoolType ENUM('Backup', 'Copy', 'Cloned', 'Archive', 'Migration', 'Scratch') NOT NULL,
1102    LabelFormat TINYBLOB,
1103    Enabled TINYINT DEFAULT 1,
1104    ScratchPoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
1105    RecyclePoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
1106    UNIQUE (Name(128)),
1107    PRIMARY KEY (PoolId)
1108    );
1109 CREATE TABLE Client (
1110    ClientId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
1111    Name TINYBLOB NOT NULL,
1112    Uname TINYBLOB NOT NULL,       /* full uname -a of client */
1113    AutoPrune TINYINT DEFAULT 0,
1114    FileRetention BIGINT UNSIGNED NOT NULL,
1115    JobRetention  BIGINT UNSIGNED NOT NULL,
1116    UNIQUE (Name(128)),
1117    PRIMARY KEY(ClientId)
1118    );
1119 CREATE TABLE BaseFiles (
1120    BaseId INTEGER UNSIGNED AUTO_INCREMENT,
1121    BaseJobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
1122    JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
1123    FileId INTEGER UNSIGNED NOT NULL REFERENCES File,
1124    FileIndex INTEGER UNSIGNED,
1125    PRIMARY KEY(BaseId)
1126    );
1127 CREATE TABLE UnsavedFiles (
1128    UnsavedId INTEGER UNSIGNED AUTO_INCREMENT,
1129    JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
1130    PathId INTEGER UNSIGNED NOT NULL REFERENCES Path,
1131    FilenameId INTEGER UNSIGNED NOT NULL REFERENCES Filename,
1132    PRIMARY KEY (UnsavedId)
1133    );
1134 CREATE TABLE Version (
1135    VersionId INTEGER UNSIGNED NOT NULL
1136    );
1137 -- Initialize Version
1138 INSERT INTO Version (VersionId) VALUES (7);
1139 CREATE TABLE Counters (
1140    Counter TINYBLOB NOT NULL,
1141    MinValue INTEGER,
1142    MaxValue INTEGER,
1143    CurrentValue INTEGER,
1144    WrapCounter TINYBLOB NOT NULL,
1145    PRIMARY KEY (Counter(128))
1146    );
1147 \end{verbatim}
1148 \normalsize