3 # shell script to create Bacula SQLite tables
10 ${bindir}/${sqlite} $* ${db_name}.db <<END-OF-DATA
11 CREATE TABLE Filename (
14 PRIMARY KEY(FilenameId)
17 CREATE INDEX inx1 ON Filename (Name);
25 CREATE INDEX inx2 ON Path (Path);
30 FileIndex INTEGER UNSIGNED NOT NULL,
31 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
32 PathId INTEGER UNSIGNED REFERENCES Path NOT NULL,
33 FilenameId INTEGER UNSIGNED REFERENCES Filename NOT NULL,
34 MarkId INTEGER UNSIGNED DEFAULT 0,
35 LStat VARCHAR(255) NOT NULL,
36 MD5 VARCHAR(255) NOT NULL,
40 CREATE INDEX inx3 ON File (JobId);
41 CREATE INDEX inx4 ON File (FilenameId, PathId);
43 -- Possibly add one or more of the following indexes
44 -- if your Verifies are too slow.
46 -- CREATE INDEX inx4 ON File (PathId);
47 -- CREATE INDEX inx5 ON File (FileNameId);
48 -- CREATE INDEX inx9 ON File (JobId, PathId, FilenameId);
52 Job VARCHAR(128) NOT NULL,
53 Name VARCHAR(128) NOT NULL,
54 Type CHAR(1) NOT NULL,
55 Level CHAR(1) NOT NULL,
56 ClientId INTEGER REFERENCES Client DEFAULT 0,
57 JobStatus CHAR(1) NOT NULL,
58 SchedTime DATETIME NOT NULL,
59 StartTime DATETIME DEFAULT 0,
60 EndTime DATETIME DEFAULT 0,
61 RealEndTime DATETIME DEFAULT 0,
62 JobTDate BIGINT UNSIGNED DEFAULT 0,
63 VolSessionId INTEGER UNSIGNED DEFAULT 0,
64 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
65 JobFiles INTEGER UNSIGNED DEFAULT 0,
66 JobBytes BIGINT UNSIGNED DEFAULT 0,
67 ReadBytes BIGINT UNSIGNED DEFAULT 0,
68 JobErrors INTEGER UNSIGNED DEFAULT 0,
69 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
70 PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
71 FileSetId INTEGER UNSIGNED REFERENCES FileSet DEFAULT 0,
72 PriorJobId INTEGER UNSIGNED REFERENCES Job DEFAULT 0,
73 PurgedFiles TINYINT DEFAULT 0,
74 HasBase TINYINT DEFAULT 0,
77 CREATE INDEX inx6 ON Job (Name);
79 -- Create a table like Job for long term statistics
80 CREATE TABLE JobHisto (
82 Job VARCHAR(128) NOT NULL,
83 Name VARCHAR(128) NOT NULL,
84 Type CHAR(1) NOT NULL,
85 Level CHAR(1) NOT NULL,
86 ClientId INTEGER DEFAULT 0,
87 JobStatus CHAR(1) NOT NULL,
88 SchedTime DATETIME NOT NULL,
89 StartTime DATETIME DEFAULT 0,
90 EndTime DATETIME DEFAULT 0,
91 RealEndTime DATETIME DEFAULT 0,
92 JobTDate BIGINT UNSIGNED DEFAULT 0,
93 VolSessionId INTEGER UNSIGNED DEFAULT 0,
94 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
95 JobFiles INTEGER UNSIGNED DEFAULT 0,
96 JobBytes BIGINT UNSIGNED DEFAULT 0,
97 ReadBytes BIGINT UNSIGNED DEFAULT 0,
98 JobErrors INTEGER UNSIGNED DEFAULT 0,
99 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
100 PoolId INTEGER UNSIGNED DEFAULT 0,
101 FileSetId INTEGER UNSIGNED DEFAULT 0,
102 PriorJobId INTEGER UNSIGNED DEFAULT 0,
103 PurgedFiles TINYINT DEFAULT 0,
104 HasBase TINYINT DEFAULT 0
106 CREATE INDEX inx61 ON JobHisto (StartTime);
108 CREATE TABLE Location (
110 Location TEXT NOT NULL,
111 Cost INTEGER DEFAULT 0,
113 PRIMARY KEY(LocationId)
116 CREATE TABLE LocationLog (
118 Date DATETIME NOT NULL,
119 Comment TEXT NOT NULL,
120 MediaId INTEGER UNSIGNED REFERENCES Media DEFAULT 0,
121 LocationId INTEGER UNSIGNED REFERENCES LocationId DEFAULT 0,
122 NewVolStatus VARCHAR(20) NOT NULL,
123 NewEnabled TINYINT NOT NULL,
124 PRIMARY KEY(LocLogId)
130 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
131 Time DATETIME NOT NULL,
132 LogText TEXT NOT NULL,
135 CREATE INDEX LogInx1 ON Log (JobId);
138 CREATE TABLE FileSet (
140 FileSet VARCHAR(128) NOT NULL,
141 MD5 VARCHAR(25) NOT NULL,
142 CreateTime DATETIME DEFAULT 0,
143 PRIMARY KEY(FileSetId)
146 CREATE TABLE JobMedia (
148 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
149 MediaId INTEGER UNSIGNED REFERENCES Media NOT NULL,
150 FirstIndex INTEGER UNSIGNED NOT NULL,
151 LastIndex INTEGER UNSIGNED NOT NULL,
152 StartFile INTEGER UNSIGNED DEFAULT 0,
153 EndFile INTEGER UNSIGNED DEFAULT 0,
154 StartBlock INTEGER UNSIGNED DEFAULT 0,
155 EndBlock INTEGER UNSIGNED DEFAULT 0,
156 VolIndex INTEGER UNSIGNED DEFAULT 0,
157 Copy INTEGER UNSIGNED DEFAULT 0,
158 PRIMARY KEY(JobMediaId)
161 CREATE INDEX inx7 ON JobMedia (JobId, MediaId);
166 VolumeName VARCHAR(128) NOT NULL,
167 Slot INTEGER DEFAULT 0,
168 PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
169 MediaType VARCHAR(128) NOT NULL,
170 MediaTypeId INTEGER UNSIGNED REFERENCES MediaType DEFAULT 0,
171 LabelType TINYINT DEFAULT 0,
172 FirstWritten DATETIME DEFAULT 0,
173 LastWritten DATETIME DEFAULT 0,
174 LabelDate DATETIME DEFAULT 0,
175 VolJobs INTEGER UNSIGNED DEFAULT 0,
176 VolFiles INTEGER UNSIGNED DEFAULT 0,
177 VolBlocks INTEGER UNSIGNED DEFAULT 0,
178 VolMounts INTEGER UNSIGNED DEFAULT 0,
179 VolBytes BIGINT UNSIGNED DEFAULT 0,
180 VolParts INTEGER UNSIGNED DEFAULT 0,
181 VolErrors INTEGER UNSIGNED DEFAULT 0,
182 VolWrites INTEGER UNSIGNED DEFAULT 0,
183 VolCapacityBytes BIGINT UNSIGNED DEFAULT 0,
184 VolStatus VARCHAR(20) NOT NULL,
185 Enabled TINYINT DEFAULT 1,
186 Recycle TINYINT DEFAULT 0,
187 ActionOnPurge TINYINT DEFAULT 0,
188 VolRetention BIGINT UNSIGNED DEFAULT 0,
189 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
190 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
191 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
192 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
193 InChanger TINYINT DEFAULT 0,
194 StorageId INTEGER UNSIGNED REFERENCES Storage DEFAULT 0,
195 DeviceId INTEGER UNSIGNED REFERENCES Device DEFAULT 0,
196 MediaAddressing TINYINT DEFAULT 0,
197 VolReadTime BIGINT UNSIGNED DEFAULT 0,
198 VolWriteTime BIGINT UNSIGNED DEFAULT 0,
199 EndFile INTEGER UNSIGNED DEFAULT 0,
200 EndBlock INTEGER UNSIGNED DEFAULT 0,
201 LocationId INTEGER UNSIGNED REFERENCES Location DEFAULT 0,
202 RecycleCount INTEGER UNSIGNED DEFAULT 0,
203 InitialWrite DATETIME DEFAULT 0,
204 ScratchPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
205 RecyclePoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
210 CREATE INDEX inx8 ON Media (PoolId);
212 CREATE TABLE MediaType (
214 MediaType VARCHAR(128) NOT NULL,
215 ReadOnly TINYINT DEFAULT 0,
216 PRIMARY KEY(MediaTypeId)
219 CREATE TABLE Storage (
221 Name VARCHAR(128) NOT NULL,
222 AutoChanger TINYINT DEFAULT 0,
223 PRIMARY KEY(StorageId)
226 CREATE TABLE Device (
228 Name VARCHAR(128) NOT NULL,
229 MediaTypeId INTEGER UNSIGNED REFERENCES MediaType NOT NULL,
230 StorageId INTEGER UNSIGNED REFERENCES Storage,
231 DevMounts INTEGER UNSIGNED DEFAULT 0,
232 DevReadBytes BIGINT UNSIGNED DEFAULT 0,
233 DevWriteBytes BIGINT UNSIGNED DEFAULT 0,
234 DevReadBytesSinceCleaning BIGINT UNSIGNED DEFAULT 0,
235 DevWriteBytesSinceCleaning BIGINT UNSIGNED DEFAULT 0,
236 DevReadTime BIGINT UNSIGNED DEFAULT 0,
237 DevWriteTime BIGINT UNSIGNED DEFAULT 0,
238 DevReadTimeSinceCleaning BIGINT UNSIGNED DEFAULT 0,
239 DevWriteTimeSinceCleaning BIGINT UNSIGNED DEFAULT 0,
240 CleaningDate DATETIME DEFAULT 0,
241 CleaningPeriod BIGINT UNSIGNED DEFAULT 0,
242 PRIMARY KEY(DeviceId)
248 Name VARCHAR(128) NOT NULL,
249 NumVols INTEGER UNSIGNED DEFAULT 0,
250 MaxVols INTEGER UNSIGNED DEFAULT 0,
251 UseOnce TINYINT DEFAULT 0,
252 UseCatalog TINYINT DEFAULT 1,
253 AcceptAnyVolume TINYINT DEFAULT 0,
254 VolRetention BIGINT UNSIGNED DEFAULT 0,
255 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
256 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
257 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
258 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
259 AutoPrune TINYINT DEFAULT 0,
260 Recycle TINYINT DEFAULT 0,
261 ActionOnPurge TINYINT DEFAULT 0,
262 PoolType VARCHAR(20) NOT NULL,
263 LabelType TINYINT DEFAULT 0,
264 LabelFormat VARCHAR(128) NOT NULL,
265 Enabled TINYINT DEFAULT 1,
266 ScratchPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
267 RecyclePoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
268 NextPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
269 MigrationHighBytes BIGINT UNSIGNED DEFAULT 0,
270 MigrationLowBytes BIGINT UNSIGNED DEFAULT 0,
271 MigrationTime BIGINT UNSIGNED DEFAULT 0,
277 CREATE TABLE Client (
279 Name VARCHAR(128) NOT NULL,
280 Uname VARCHAR(255) NOT NULL, -- uname -a field
281 AutoPrune TINYINT DEFAULT 0,
282 FileRetention BIGINT UNSIGNED DEFAULT 0,
283 JobRetention BIGINT UNSIGNED DEFAULT 0,
285 PRIMARY KEY(ClientId)
288 CREATE TABLE BaseFiles (
290 BaseJobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
291 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
292 FileId INTEGER UNSIGNED REFERENCES File NOT NULL,
293 FileIndex INTEGER UNSIGNED,
297 CREATE TABLE UnsavedFiles (
299 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
300 PathId INTEGER UNSIGNED REFERENCES Path NOT NULL,
301 FilenameId INTEGER UNSIGNED REFERENCES Filename NOT NULL,
302 PRIMARY KEY (UnsavedId)
306 CREATE TABLE NextId (
307 id INTEGER UNSIGNED DEFAULT 0,
308 TableName TEXT NOT NULL,
309 PRIMARY KEY (TableName)
314 -- Initialize JobId to start at 1
315 INSERT INTO NextId (id, TableName) VALUES (1, 'Job');
317 CREATE TABLE Version (
318 VersionId INTEGER UNSIGNED NOT NULL
322 CREATE TABLE Counters (
323 Counter TEXT NOT NULL,
324 MinValue INTEGER DEFAULT 0,
325 MaxValue INTEGER DEFAULT 0,
326 CurrentValue INTEGER DEFAULT 0,
327 WrapCounter TEXT NOT NULL,
328 PRIMARY KEY (Counter)
331 CREATE TABLE CDImages (
332 MediaId INTEGER UNSIGNED NOT NULL,
333 LastBurn DATETIME NOT NULL,
334 PRIMARY KEY (MediaId)
338 CREATE TABLE Status (
339 JobStatus CHAR(1) NOT NULL,
341 PRIMARY KEY (JobStatus)
344 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
345 ('C', 'Created, not yet running');
346 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
348 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
350 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
351 ('T', 'Completed successfully');
352 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
353 ('E', 'Terminated with errors');
354 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
355 ('e', 'Non-fatal error');
356 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
357 ('f', 'Fatal error');
358 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
359 ('D', 'Verify found differences');
360 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
361 ('A', 'Canceled by user');
362 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
363 ('F', 'Waiting for Client');
364 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
365 ('S', 'Waiting for Storage daemon');
366 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
367 ('m', 'Waiting for new media');
368 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
369 ('M', 'Waiting for media mount');
370 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
371 ('s', 'Waiting for storage resource');
372 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
373 ('j', 'Waiting for job resource');
374 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
375 ('c', 'Waiting for client resource');
376 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
377 ('d', 'Waiting on maximum jobs');
378 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
379 ('t', 'Waiting on start time');
380 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
381 ('p', 'Waiting on higher priority jobs');
382 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
383 ('a', 'SD despooling attributes');
384 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
385 ('i', 'Doing batch insert file records');
388 -- Initialize Version
389 INSERT INTO Version (VersionId) VALUES (11);
392 PRAGMA default_cache_size = 100000;
393 PRAGMA synchronous = NORMAL;
397 chmod 640 ${db_name}.db