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,
32 FileId BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
33 FileIndex INTEGER UNSIGNED DEFAULT 0,
34 JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
35 PathId INTEGER UNSIGNED NOT NULL REFERENCES Path,
36 FilenameId INTEGER UNSIGNED NOT NULL REFERENCES Filename,
37 MarkId INTEGER UNSIGNED DEFAULT 0,
38 LStat TINYBLOB NOT NULL,
42 INDEX (JobId, PathId, FilenameId)
46 # Possibly add one or more of the following indexes
47 # to the above File table if your Verifies are
52 # INDEX (FilenameId, PathId)
56 CREATE TABLE MediaType (
57 MediaTypeId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
58 MediaType TINYBLOB NOT NULL,
59 ReadOnly TINYINT DEFAULT 0,
60 PRIMARY KEY(MediaTypeId)
63 CREATE TABLE Storage (
64 StorageId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
65 Name TINYBLOB NOT NULL,
66 AutoChanger TINYINT DEFAULT 0,
67 PRIMARY KEY(StorageId)
71 DeviceId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
72 Name TINYBLOB NOT NULL,
73 MediaTypeId INTEGER UNSIGNED DEFAULT 0 REFERENCES MediaType,
74 StorageId INTEGER UNSIGNED DEFAULT 0 REFERENCES Storage,
75 DevMounts INTEGER UNSIGNED DEFAULT 0,
76 DevReadBytes BIGINT UNSIGNED DEFAULT 0,
77 DevWriteBytes BIGINT UNSIGNED DEFAULT 0,
78 DevReadBytesSinceCleaning BIGINT UNSIGNED DEFAULT 0,
79 DevWriteBytesSinceCleaning BIGINT UNSIGNED DEFAULT 0,
80 DevReadTime BIGINT UNSIGNED DEFAULT 0,
81 DevWriteTime BIGINT UNSIGNED DEFAULT 0,
82 DevReadTimeSinceCleaning BIGINT UNSIGNED DEFAULT 0,
83 DevWriteTimeSinceCleaning BIGINT UNSIGNED DEFAULT 0,
84 CleaningDate DATETIME DEFAULT 0,
85 CleaningPeriod BIGINT UNSIGNED DEFAULT 0,
91 JobId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
92 Job TINYBLOB NOT NULL,
93 Name TINYBLOB NOT NULL,
94 Type BINARY(1) NOT NULL,
95 Level BINARY(1) NOT NULL,
96 ClientId INTEGER DEFAULT 0 REFERENCES Client,
97 JobStatus BINARY(1) NOT NULL,
98 SchedTime DATETIME DEFAULT 0,
99 StartTime DATETIME DEFAULT 0,
100 EndTime DATETIME DEFAULT 0,
101 RealEndTime DATETIME DEFAULT 0,
102 JobTDate BIGINT UNSIGNED DEFAULT 0,
103 VolSessionId INTEGER UNSIGNED DEFAULT 0,
104 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
105 JobFiles INTEGER UNSIGNED DEFAULT 0,
106 JobBytes BIGINT UNSIGNED DEFAULT 0,
107 ReadBytes BIGINT UNSIGNED DEFAULT 0,
108 JobErrors INTEGER UNSIGNED DEFAULT 0,
109 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
110 PoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
111 FileSetId INTEGER UNSIGNED DEFAULT 0 REFERENCES FileSet,
112 PriorJobId INTEGER UNSIGNED DEFAULT 0 REFERENCES Job,
113 PurgedFiles TINYINT DEFAULT 0,
114 HasBase TINYINT DEFAULT 0,
119 -- Create a table like Job for long term statistics
120 CREATE TABLE JobHisto (
121 JobId INTEGER UNSIGNED NOT NULL,
122 Job TINYBLOB NOT NULL,
123 Name TINYBLOB NOT NULL,
124 Type BINARY(1) NOT NULL,
125 Level BINARY(1) NOT NULL,
126 ClientId INTEGER DEFAULT 0,
127 JobStatus BINARY(1) NOT NULL,
128 SchedTime DATETIME DEFAULT 0,
129 StartTime DATETIME DEFAULT 0,
130 EndTime DATETIME DEFAULT 0,
131 RealEndTime DATETIME DEFAULT 0,
132 JobTDate BIGINT UNSIGNED DEFAULT 0,
133 VolSessionId INTEGER UNSIGNED DEFAULT 0,
134 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
135 JobFiles INTEGER UNSIGNED DEFAULT 0,
136 JobBytes BIGINT UNSIGNED DEFAULT 0,
137 ReadBytes BIGINT UNSIGNED DEFAULT 0,
138 JobErrors INTEGER UNSIGNED DEFAULT 0,
139 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
140 PoolId INTEGER UNSIGNED DEFAULT 0,
141 FileSetId INTEGER UNSIGNED DEFAULT 0,
142 PriorJobId INTEGER UNSIGNED DEFAULT 0,
143 PurgedFiles TINYINT DEFAULT 0,
144 HasBase TINYINT DEFAULT 0,
148 CREATE TABLE Location (
149 LocationId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
150 Location TINYBLOB NOT NULL,
151 Cost INTEGER DEFAULT 0,
153 PRIMARY KEY(LocationId)
156 CREATE TABLE LocationLog (
157 LocLogId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
158 Date DATETIME DEFAULT 0,
159 Comment BLOB NOT NULL,
160 MediaId INTEGER UNSIGNED DEFAULT 0 REFERENCES Media,
161 LocationId INTEGER UNSIGNED DEFAULT 0 REFERENCES Location,
162 NewVolStatus ENUM('Full', 'Archive', 'Append', 'Recycle', 'Purged',
163 'Read-Only', 'Disabled', 'Error', 'Busy', 'Used', 'Cleaning') NOT NULL,
165 PRIMARY KEY(LocLogId)
170 CREATE TABLE FileSet (
171 FileSetId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
172 FileSet TINYBLOB NOT NULL,
174 CreateTime DATETIME DEFAULT 0,
175 PRIMARY KEY(FileSetId)
178 CREATE TABLE JobMedia (
179 JobMediaId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
180 JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
181 MediaId INTEGER UNSIGNED NOT NULL REFERENCES Media,
182 FirstIndex INTEGER UNSIGNED DEFAULT 0,
183 LastIndex INTEGER UNSIGNED DEFAULT 0,
184 StartFile INTEGER UNSIGNED DEFAULT 0,
185 EndFile INTEGER UNSIGNED DEFAULT 0,
186 StartBlock INTEGER UNSIGNED DEFAULT 0,
187 EndBlock INTEGER UNSIGNED DEFAULT 0,
188 VolIndex INTEGER UNSIGNED DEFAULT 0,
189 Copy INTEGER UNSIGNED DEFAULT 0,
190 Stripe INTEGER UNSIGNED DEFAULT 0,
191 PRIMARY KEY(JobMediaId),
192 INDEX (JobId, MediaId)
197 MediaId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
198 VolumeName TINYBLOB NOT NULL,
199 Slot INTEGER DEFAULT 0,
200 PoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
201 MediaType TINYBLOB NOT NULL,
202 MediaTypeId INTEGER UNSIGNED DEFAULT 0 REFERENCES MediaType,
203 LabelType TINYINT DEFAULT 0,
204 FirstWritten DATETIME DEFAULT 0,
205 LastWritten DATETIME DEFAULT 0,
206 LabelDate DATETIME DEFAULT 0,
207 VolJobs INTEGER UNSIGNED DEFAULT 0,
208 VolFiles INTEGER UNSIGNED DEFAULT 0,
209 VolBlocks INTEGER UNSIGNED DEFAULT 0,
210 VolMounts INTEGER UNSIGNED DEFAULT 0,
211 VolBytes BIGINT UNSIGNED DEFAULT 0,
212 VolParts INTEGER UNSIGNED DEFAULT 0,
213 VolErrors INTEGER UNSIGNED DEFAULT 0,
214 VolWrites INTEGER UNSIGNED DEFAULT 0,
215 VolCapacityBytes BIGINT UNSIGNED DEFAULT 0,
216 VolStatus ENUM('Full', 'Archive', 'Append', 'Recycle', 'Purged',
217 'Read-Only', 'Disabled', 'Error', 'Busy', 'Used', 'Cleaning') NOT NULL,
218 Enabled TINYINT DEFAULT 1,
219 Recycle TINYINT DEFAULT 0,
220 ActionOnPurge TINYINT DEFAULT 0,
221 VolRetention BIGINT UNSIGNED DEFAULT 0,
222 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
223 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
224 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
225 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
226 InChanger TINYINT DEFAULT 0,
227 StorageId INTEGER UNSIGNED DEFAULT 0 REFERENCES Storage,
228 DeviceId INTEGER UNSIGNED DEFAULT 0 REFERENCES Device,
229 MediaAddressing TINYINT DEFAULT 0,
230 VolReadTime BIGINT UNSIGNED DEFAULT 0,
231 VolWriteTime BIGINT UNSIGNED DEFAULT 0,
232 EndFile INTEGER UNSIGNED DEFAULT 0,
233 EndBlock INTEGER UNSIGNED DEFAULT 0,
234 LocationId INTEGER UNSIGNED DEFAULT 0 REFERENCES Location,
235 RecycleCount INTEGER UNSIGNED DEFAULT 0,
236 InitialWrite DATETIME DEFAULT 0,
237 ScratchPoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
238 RecyclePoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
240 PRIMARY KEY(MediaId),
241 UNIQUE (VolumeName(128)),
246 PoolId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
247 Name TINYBLOB NOT NULL,
248 NumVols INTEGER UNSIGNED DEFAULT 0,
249 MaxVols INTEGER UNSIGNED DEFAULT 0,
250 UseOnce TINYINT DEFAULT 0,
251 UseCatalog TINYINT DEFAULT 0,
252 AcceptAnyVolume TINYINT DEFAULT 0,
253 VolRetention BIGINT UNSIGNED DEFAULT 0,
254 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
255 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
256 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
257 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
258 AutoPrune TINYINT DEFAULT 0,
259 Recycle TINYINT DEFAULT 0,
260 ActionOnPurge TINYINT DEFAULT 0,
261 PoolType ENUM('Backup', 'Copy', 'Cloned', 'Archive', 'Migration', 'Scratch') NOT NULL,
262 LabelType TINYINT DEFAULT 0,
263 LabelFormat TINYBLOB,
264 Enabled TINYINT DEFAULT 1,
265 ScratchPoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
266 RecyclePoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
267 NextPoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool,
268 MigrationHighBytes BIGINT UNSIGNED DEFAULT 0,
269 MigrationLowBytes BIGINT UNSIGNED DEFAULT 0,
270 MigrationTime BIGINT UNSIGNED DEFAULT 0,
276 CREATE TABLE Client (
277 ClientId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
278 Name TINYBLOB NOT NULL,
279 Uname TINYBLOB NOT NULL, /* full uname -a of client */
280 AutoPrune TINYINT DEFAULT 0,
281 FileRetention BIGINT UNSIGNED DEFAULT 0,
282 JobRetention BIGINT UNSIGNED DEFAULT 0,
284 PRIMARY KEY(ClientId)
288 LogId INTEGER UNSIGNED AUTO_INCREMENT,
289 JobId INTEGER UNSIGNED DEFAULT 0 REFERENCES Job,
290 Time DATETIME DEFAULT 0,
291 LogText BLOB NOT NULL,
297 CREATE TABLE BaseFiles (
298 BaseId INTEGER UNSIGNED AUTO_INCREMENT,
299 BaseJobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
300 JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
301 FileId BIGINT UNSIGNED NOT NULL REFERENCES File,
302 FileIndex INTEGER UNSIGNED,
306 CREATE TABLE UnsavedFiles (
307 UnsavedId INTEGER UNSIGNED AUTO_INCREMENT,
308 JobId INTEGER UNSIGNED NOT NULL REFERENCES Job,
309 PathId INTEGER UNSIGNED NOT NULL REFERENCES Path,
310 FilenameId INTEGER UNSIGNED NOT NULL REFERENCES Filename,
311 PRIMARY KEY (UnsavedId)
316 CREATE TABLE Counters (
317 Counter TINYBLOB NOT NULL,
318 MinValue INTEGER DEFAULT 0,
319 MaxValue INTEGER DEFAULT 0,
320 CurrentValue INTEGER DEFAULT 0,
321 WrapCounter TINYBLOB NOT NULL,
322 PRIMARY KEY (Counter(128))
325 CREATE TABLE CDImages (
326 MediaId INTEGER UNSIGNED NOT NULL,
327 LastBurn DATETIME NOT NULL,
328 PRIMARY KEY (MediaId)
331 CREATE TABLE Status (
332 JobStatus CHAR(1) BINARY NOT NULL,
334 PRIMARY KEY (JobStatus)
337 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
338 ('C', 'Created, not yet running'),
341 ('T', 'Completed successfully'),
342 ('E', 'Terminated with errors'),
343 ('e', 'Non-fatal error'),
344 ('f', 'Fatal error'),
345 ('D', 'Verify found differences'),
346 ('A', 'Canceled by user'),
347 ('F', 'Waiting for Client'),
348 ('S', 'Waiting for Storage daemon'),
349 ('m', 'Waiting for new media'),
350 ('M', 'Waiting for media mount'),
351 ('s', 'Waiting for storage resource'),
352 ('j', 'Waiting for job resource'),
353 ('c', 'Waiting for client resource'),
354 ('d', 'Waiting on maximum jobs'),
355 ('t', 'Waiting on start time'),
356 ('p', 'Waiting on higher priority jobs'),
357 ('i', 'Doing batch insert file records'),
358 ('a', 'SD despooling attributes');
360 CREATE TABLE Version (
361 VersionId INTEGER UNSIGNED NOT NULL
364 -- Initialize Version
365 INSERT INTO Version (VersionId) VALUES (11);
369 echo "Creation of Bacula MySQL tables succeeded."
371 echo "Creation of Bacula MySQL tables failed."