3 # shell script to create Bacula MySQL tables
6 db_name=${db_name:-@db_name@}
8 if $bindir/mysql $* -f <<END-OF-DATA
11 -- Note, we use BLOB rather than TEXT because in MySQL,
12 -- BLOBs are identical to TEXT except that BLOB is case
13 -- sensitive in sorts, which is what we want, and TEXT
14 -- is case insensitive.
16 CREATE TABLE Filename (
17 FilenameId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
19 PRIMARY KEY(FilenameId),
24 PathId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
31 -- FileIndex can be 0 for FT_DELETED files
32 -- FileNameId can link to Filename.Name='' for directories
34 FileId BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
35 FileIndex INTEGER UNSIGNED DEFAULT 0,
36 JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
37 PathId INTEGER UNSIGNED NOT NULL REFERENCES Path,
38 FilenameId INTEGER UNSIGNED NOT NULL REFERENCES Filename,
39 MarkId INTEGER UNSIGNED DEFAULT 0,
40 LStat TINYBLOB NOT NULL,
44 INDEX (JobId, PathId, FilenameId)
48 # Possibly add one or more of the following indexes
49 # to the above File table if your Verifies are
54 # INDEX (FilenameId, PathId)
58 CREATE TABLE MediaType (
59 MediaTypeId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
60 MediaType TINYBLOB NOT NULL,
61 ReadOnly TINYINT DEFAULT 0,
62 PRIMARY KEY(MediaTypeId)
65 CREATE TABLE Storage (
66 StorageId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
67 Name TINYBLOB NOT NULL,
68 AutoChanger TINYINT DEFAULT 0,
69 PRIMARY KEY(StorageId)
73 DeviceId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
74 Name TINYBLOB NOT NULL,
75 MediaTypeId INTEGER UNSIGNED DEFAULT 0 REFERENCES MediaType,
76 StorageId INTEGER UNSIGNED DEFAULT 0 REFERENCES Storage,
77 DevMounts INTEGER UNSIGNED DEFAULT 0,
78 DevReadBytes BIGINT UNSIGNED DEFAULT 0,
79 DevWriteBytes BIGINT UNSIGNED DEFAULT 0,
80 DevReadBytesSinceCleaning BIGINT UNSIGNED DEFAULT 0,
81 DevWriteBytesSinceCleaning BIGINT UNSIGNED DEFAULT 0,
82 DevReadTime BIGINT UNSIGNED DEFAULT 0,
83 DevWriteTime BIGINT UNSIGNED DEFAULT 0,
84 DevReadTimeSinceCleaning BIGINT UNSIGNED DEFAULT 0,
85 DevWriteTimeSinceCleaning BIGINT UNSIGNED DEFAULT 0,
86 CleaningDate DATETIME DEFAULT 0,
87 CleaningPeriod BIGINT UNSIGNED DEFAULT 0,
93 JobId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
94 Job TINYBLOB NOT NULL,
95 Name TINYBLOB NOT NULL,
96 Type BINARY(1) NOT NULL,
97 Level BINARY(1) NOT NULL,
98 ClientId INTEGER DEFAULT 0 REFERENCES Client,
99 JobStatus BINARY(1) NOT NULL,
100 SchedTime DATETIME DEFAULT 0,
101 StartTime DATETIME DEFAULT 0,
102 EndTime DATETIME DEFAULT 0,
103 RealEndTime DATETIME DEFAULT 0,
104 JobTDate BIGINT UNSIGNED DEFAULT 0,
105 VolSessionId INTEGER UNSIGNED DEFAULT 0,
106 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
107 JobFiles INTEGER UNSIGNED DEFAULT 0,
108 JobBytes BIGINT UNSIGNED DEFAULT 0,
109 ReadBytes BIGINT UNSIGNED DEFAULT 0,
110 JobErrors INTEGER UNSIGNED DEFAULT 0,
111 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
112 PoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
113 FileSetId INTEGER UNSIGNED DEFAULT 0 REFERENCES FileSet,
114 PriorJobId INTEGER UNSIGNED DEFAULT 0 REFERENCES Job,
115 PurgedFiles TINYINT DEFAULT 0,
116 HasBase TINYINT DEFAULT 0,
121 -- Create a table like Job for long term statistics
122 CREATE TABLE JobHisto (
123 JobId INTEGER UNSIGNED NOT NULL,
124 Job TINYBLOB NOT NULL,
125 Name TINYBLOB NOT NULL,
126 Type BINARY(1) NOT NULL,
127 Level BINARY(1) NOT NULL,
128 ClientId INTEGER DEFAULT 0,
129 JobStatus BINARY(1) NOT NULL,
130 SchedTime DATETIME DEFAULT 0,
131 StartTime DATETIME DEFAULT 0,
132 EndTime DATETIME DEFAULT 0,
133 RealEndTime DATETIME DEFAULT 0,
134 JobTDate BIGINT UNSIGNED DEFAULT 0,
135 VolSessionId INTEGER UNSIGNED DEFAULT 0,
136 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
137 JobFiles INTEGER UNSIGNED DEFAULT 0,
138 JobBytes BIGINT UNSIGNED DEFAULT 0,
139 ReadBytes BIGINT UNSIGNED DEFAULT 0,
140 JobErrors INTEGER UNSIGNED DEFAULT 0,
141 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
142 PoolId INTEGER UNSIGNED DEFAULT 0,
143 FileSetId INTEGER UNSIGNED DEFAULT 0,
144 PriorJobId INTEGER UNSIGNED DEFAULT 0,
145 PurgedFiles TINYINT DEFAULT 0,
146 HasBase TINYINT DEFAULT 0,
150 CREATE TABLE Location (
151 LocationId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
152 Location TINYBLOB NOT NULL,
153 Cost INTEGER DEFAULT 0,
155 PRIMARY KEY(LocationId)
158 CREATE TABLE LocationLog (
159 LocLogId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
160 Date DATETIME DEFAULT 0,
161 Comment BLOB NOT NULL,
162 MediaId INTEGER UNSIGNED DEFAULT 0 REFERENCES Media,
163 LocationId INTEGER UNSIGNED DEFAULT 0 REFERENCES Location,
164 NewVolStatus ENUM('Full', 'Archive', 'Append', 'Recycle', 'Purged',
165 'Read-Only', 'Disabled', 'Error', 'Busy', 'Used', 'Cleaning') NOT NULL,
167 PRIMARY KEY(LocLogId)
172 CREATE TABLE FileSet (
173 FileSetId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
174 FileSet TINYBLOB NOT NULL,
176 CreateTime DATETIME DEFAULT 0,
177 PRIMARY KEY(FileSetId)
180 CREATE TABLE JobMedia (
181 JobMediaId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
182 JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
183 MediaId INTEGER UNSIGNED NOT NULL REFERENCES Media,
184 FirstIndex INTEGER UNSIGNED DEFAULT 0,
185 LastIndex INTEGER UNSIGNED DEFAULT 0,
186 StartFile INTEGER UNSIGNED DEFAULT 0,
187 EndFile INTEGER UNSIGNED DEFAULT 0,
188 StartBlock INTEGER UNSIGNED DEFAULT 0,
189 EndBlock INTEGER UNSIGNED DEFAULT 0,
190 VolIndex INTEGER UNSIGNED DEFAULT 0,
191 Copy INTEGER UNSIGNED DEFAULT 0,
192 Stripe INTEGER UNSIGNED DEFAULT 0,
193 PRIMARY KEY(JobMediaId),
194 INDEX (JobId, MediaId)
199 MediaId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
200 VolumeName TINYBLOB NOT NULL,
201 Slot INTEGER DEFAULT 0,
202 PoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
203 MediaType TINYBLOB NOT NULL,
204 MediaTypeId INTEGER UNSIGNED DEFAULT 0 REFERENCES MediaType,
205 LabelType TINYINT DEFAULT 0,
206 FirstWritten DATETIME DEFAULT 0,
207 LastWritten DATETIME DEFAULT 0,
208 LabelDate DATETIME DEFAULT 0,
209 VolJobs INTEGER UNSIGNED DEFAULT 0,
210 VolFiles INTEGER UNSIGNED DEFAULT 0,
211 VolBlocks INTEGER UNSIGNED DEFAULT 0,
212 VolMounts INTEGER UNSIGNED DEFAULT 0,
213 VolBytes BIGINT UNSIGNED DEFAULT 0,
214 VolParts INTEGER UNSIGNED DEFAULT 0,
215 VolErrors INTEGER UNSIGNED DEFAULT 0,
216 VolWrites INTEGER UNSIGNED DEFAULT 0,
217 VolCapacityBytes BIGINT UNSIGNED DEFAULT 0,
218 VolStatus ENUM('Full', 'Archive', 'Append', 'Recycle', 'Purged',
219 'Read-Only', 'Disabled', 'Error', 'Busy', 'Used', 'Cleaning') NOT NULL,
220 Enabled TINYINT DEFAULT 1,
221 Recycle TINYINT DEFAULT 0,
222 ActionOnPurge TINYINT DEFAULT 0,
223 VolRetention BIGINT UNSIGNED DEFAULT 0,
224 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
225 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
226 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
227 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
228 InChanger TINYINT DEFAULT 0,
229 StorageId INTEGER UNSIGNED DEFAULT 0 REFERENCES Storage,
230 DeviceId INTEGER UNSIGNED DEFAULT 0 REFERENCES Device,
231 MediaAddressing TINYINT DEFAULT 0,
232 VolReadTime BIGINT UNSIGNED DEFAULT 0,
233 VolWriteTime BIGINT UNSIGNED DEFAULT 0,
234 EndFile INTEGER UNSIGNED DEFAULT 0,
235 EndBlock INTEGER UNSIGNED DEFAULT 0,
236 LocationId INTEGER UNSIGNED DEFAULT 0 REFERENCES Location,
237 RecycleCount INTEGER UNSIGNED DEFAULT 0,
238 InitialWrite DATETIME DEFAULT 0,
239 ScratchPoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
240 RecyclePoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
242 PRIMARY KEY(MediaId),
243 UNIQUE (VolumeName(128)),
248 PoolId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
249 Name TINYBLOB NOT NULL,
250 NumVols INTEGER UNSIGNED DEFAULT 0,
251 MaxVols INTEGER UNSIGNED DEFAULT 0,
252 UseOnce TINYINT DEFAULT 0,
253 UseCatalog TINYINT DEFAULT 0,
254 AcceptAnyVolume TINYINT DEFAULT 0,
255 VolRetention BIGINT UNSIGNED DEFAULT 0,
256 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
257 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
258 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
259 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
260 AutoPrune TINYINT DEFAULT 0,
261 Recycle TINYINT DEFAULT 0,
262 ActionOnPurge TINYINT DEFAULT 0,
263 PoolType ENUM('Backup', 'Copy', 'Cloned', 'Archive', 'Migration', 'Scratch') NOT NULL,
264 LabelType TINYINT DEFAULT 0,
265 LabelFormat TINYBLOB,
266 Enabled TINYINT DEFAULT 1,
267 ScratchPoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
268 RecyclePoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
269 NextPoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
270 MigrationHighBytes BIGINT UNSIGNED DEFAULT 0,
271 MigrationLowBytes BIGINT UNSIGNED DEFAULT 0,
272 MigrationTime BIGINT UNSIGNED DEFAULT 0,
278 CREATE TABLE Client (
279 ClientId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
280 Name TINYBLOB NOT NULL,
281 Uname TINYBLOB NOT NULL, /* full uname -a of client */
282 AutoPrune TINYINT DEFAULT 0,
283 FileRetention BIGINT UNSIGNED DEFAULT 0,
284 JobRetention BIGINT UNSIGNED DEFAULT 0,
286 PRIMARY KEY(ClientId)
290 LogId INTEGER UNSIGNED AUTO_INCREMENT,
291 JobId INTEGER UNSIGNED DEFAULT 0 REFERENCES Job,
292 Time DATETIME DEFAULT 0,
293 LogText BLOB NOT NULL,
299 CREATE TABLE BaseFiles (
300 BaseId INTEGER UNSIGNED AUTO_INCREMENT,
301 BaseJobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
302 JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
303 FileId BIGINT UNSIGNED NOT NULL REFERENCES File,
304 FileIndex INTEGER UNSIGNED,
308 CREATE TABLE UnsavedFiles (
309 UnsavedId INTEGER UNSIGNED AUTO_INCREMENT,
310 JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
311 PathId INTEGER UNSIGNED NOT NULL REFERENCES Path,
312 FilenameId INTEGER UNSIGNED NOT NULL REFERENCES Filename,
313 PRIMARY KEY (UnsavedId)
318 CREATE TABLE Counters (
319 Counter TINYBLOB NOT NULL,
320 MinValue INTEGER DEFAULT 0,
321 MaxValue INTEGER DEFAULT 0,
322 CurrentValue INTEGER DEFAULT 0,
323 WrapCounter TINYBLOB NOT NULL,
324 PRIMARY KEY (Counter(128))
327 CREATE TABLE CDImages (
328 MediaId INTEGER UNSIGNED NOT NULL,
329 LastBurn DATETIME NOT NULL,
330 PRIMARY KEY (MediaId)
333 CREATE TABLE Status (
334 JobStatus CHAR(1) BINARY NOT NULL,
336 PRIMARY KEY (JobStatus)
339 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
340 ('C', 'Created, not yet running'),
343 ('T', 'Completed successfully'),
344 ('E', 'Terminated with errors'),
345 ('e', 'Non-fatal error'),
346 ('f', 'Fatal error'),
347 ('D', 'Verify found differences'),
348 ('A', 'Canceled by user'),
349 ('F', 'Waiting for Client'),
350 ('S', 'Waiting for Storage daemon'),
351 ('m', 'Waiting for new media'),
352 ('M', 'Waiting for media mount'),
353 ('s', 'Waiting for storage resource'),
354 ('j', 'Waiting for job resource'),
355 ('c', 'Waiting for client resource'),
356 ('d', 'Waiting on maximum jobs'),
357 ('t', 'Waiting on start time'),
358 ('p', 'Waiting on higher priority jobs'),
359 ('i', 'Doing batch insert file records'),
360 ('a', 'SD despooling attributes');
362 CREATE TABLE Version (
363 VersionId INTEGER UNSIGNED NOT NULL
366 -- Initialize Version
367 INSERT INTO Version (VersionId) VALUES (11);
371 echo "Creation of Bacula MySQL tables succeeded."
373 echo "Creation of Bacula MySQL tables failed."