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 file_jpf_idx ON File (JobId, PathId, FilenameId);
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);
51 Job VARCHAR(128) NOT NULL,
52 Name VARCHAR(128) NOT NULL,
53 Type CHAR(1) NOT NULL,
54 Level CHAR(1) NOT NULL,
55 ClientId INTEGER REFERENCES Client DEFAULT 0,
56 JobStatus CHAR(1) NOT NULL,
57 SchedTime DATETIME NOT NULL,
58 StartTime DATETIME DEFAULT 0,
59 EndTime DATETIME DEFAULT 0,
60 RealEndTime DATETIME DEFAULT 0,
61 JobTDate BIGINT UNSIGNED DEFAULT 0,
62 VolSessionId INTEGER UNSIGNED DEFAULT 0,
63 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
64 JobFiles INTEGER UNSIGNED DEFAULT 0,
65 JobBytes BIGINT UNSIGNED DEFAULT 0,
66 ReadBytes BIGINT UNSIGNED DEFAULT 0,
67 JobErrors INTEGER UNSIGNED DEFAULT 0,
68 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
69 PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
70 FileSetId INTEGER UNSIGNED REFERENCES FileSet DEFAULT 0,
71 PriorJobId INTEGER UNSIGNED REFERENCES Job DEFAULT 0,
72 PurgedFiles TINYINT DEFAULT 0,
73 HasBase TINYINT DEFAULT 0,
76 CREATE INDEX inx6 ON Job (Name);
78 -- Create a table like Job for long term statistics
79 CREATE TABLE JobHisto (
81 Job VARCHAR(128) NOT NULL,
82 Name VARCHAR(128) NOT NULL,
83 Type CHAR(1) NOT NULL,
84 Level CHAR(1) NOT NULL,
85 ClientId INTEGER DEFAULT 0,
86 JobStatus CHAR(1) NOT NULL,
87 SchedTime DATETIME NOT NULL,
88 StartTime DATETIME DEFAULT 0,
89 EndTime DATETIME DEFAULT 0,
90 RealEndTime DATETIME DEFAULT 0,
91 JobTDate BIGINT UNSIGNED DEFAULT 0,
92 VolSessionId INTEGER UNSIGNED DEFAULT 0,
93 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
94 JobFiles INTEGER UNSIGNED DEFAULT 0,
95 JobBytes BIGINT UNSIGNED DEFAULT 0,
96 ReadBytes BIGINT UNSIGNED DEFAULT 0,
97 JobErrors INTEGER UNSIGNED DEFAULT 0,
98 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
99 PoolId INTEGER UNSIGNED DEFAULT 0,
100 FileSetId INTEGER UNSIGNED DEFAULT 0,
101 PriorJobId INTEGER UNSIGNED DEFAULT 0,
102 PurgedFiles TINYINT DEFAULT 0,
103 HasBase TINYINT DEFAULT 0
105 CREATE INDEX inx61 ON JobHisto (StartTime);
107 CREATE TABLE Location (
109 Location TEXT NOT NULL,
110 Cost INTEGER DEFAULT 0,
112 PRIMARY KEY(LocationId)
115 CREATE TABLE LocationLog (
117 Date DATETIME NOT NULL,
118 Comment TEXT NOT NULL,
119 MediaId INTEGER UNSIGNED REFERENCES Media DEFAULT 0,
120 LocationId INTEGER UNSIGNED REFERENCES LocationId DEFAULT 0,
121 NewVolStatus VARCHAR(20) NOT NULL,
122 NewEnabled TINYINT NOT NULL,
123 PRIMARY KEY(LocLogId)
129 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
130 Time DATETIME NOT NULL,
131 LogText TEXT NOT NULL,
134 CREATE INDEX LogInx1 ON Log (JobId);
137 CREATE TABLE FileSet (
139 FileSet VARCHAR(128) NOT NULL,
140 MD5 VARCHAR(25) NOT NULL,
141 CreateTime DATETIME DEFAULT 0,
142 PRIMARY KEY(FileSetId)
145 CREATE TABLE JobMedia (
147 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
148 MediaId INTEGER UNSIGNED REFERENCES Media NOT NULL,
149 FirstIndex INTEGER UNSIGNED NOT NULL,
150 LastIndex INTEGER UNSIGNED NOT NULL,
151 StartFile INTEGER UNSIGNED DEFAULT 0,
152 EndFile INTEGER UNSIGNED DEFAULT 0,
153 StartBlock INTEGER UNSIGNED DEFAULT 0,
154 EndBlock INTEGER UNSIGNED DEFAULT 0,
155 VolIndex INTEGER UNSIGNED DEFAULT 0,
156 Copy INTEGER UNSIGNED DEFAULT 0,
157 PRIMARY KEY(JobMediaId)
160 CREATE INDEX inx7 ON JobMedia (JobId, MediaId);
165 VolumeName VARCHAR(128) NOT NULL,
166 Slot INTEGER DEFAULT 0,
167 PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
168 MediaType VARCHAR(128) NOT NULL,
169 MediaTypeId INTEGER UNSIGNED REFERENCES MediaType DEFAULT 0,
170 LabelType TINYINT DEFAULT 0,
171 FirstWritten DATETIME DEFAULT 0,
172 LastWritten DATETIME DEFAULT 0,
173 LabelDate DATETIME DEFAULT 0,
174 VolJobs INTEGER UNSIGNED DEFAULT 0,
175 VolFiles INTEGER UNSIGNED DEFAULT 0,
176 VolBlocks INTEGER UNSIGNED DEFAULT 0,
177 VolMounts INTEGER UNSIGNED DEFAULT 0,
178 VolBytes BIGINT UNSIGNED DEFAULT 0,
179 VolParts INTEGER UNSIGNED DEFAULT 0,
180 VolErrors INTEGER UNSIGNED DEFAULT 0,
181 VolWrites INTEGER UNSIGNED DEFAULT 0,
182 VolCapacityBytes BIGINT UNSIGNED DEFAULT 0,
183 VolStatus VARCHAR(20) NOT NULL,
184 Enabled TINYINT DEFAULT 1,
185 Recycle TINYINT DEFAULT 0,
186 ActionOnPurge TINYINT DEFAULT 0,
187 VolRetention BIGINT UNSIGNED DEFAULT 0,
188 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
189 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
190 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
191 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
192 InChanger TINYINT DEFAULT 0,
193 StorageId INTEGER UNSIGNED REFERENCES Storage DEFAULT 0,
194 DeviceId INTEGER UNSIGNED REFERENCES Device DEFAULT 0,
195 MediaAddressing TINYINT DEFAULT 0,
196 VolReadTime BIGINT UNSIGNED DEFAULT 0,
197 VolWriteTime BIGINT UNSIGNED DEFAULT 0,
198 EndFile INTEGER UNSIGNED DEFAULT 0,
199 EndBlock INTEGER UNSIGNED DEFAULT 0,
200 LocationId INTEGER UNSIGNED REFERENCES Location DEFAULT 0,
201 RecycleCount INTEGER UNSIGNED DEFAULT 0,
202 InitialWrite DATETIME DEFAULT 0,
203 ScratchPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
204 RecyclePoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
209 CREATE INDEX inx8 ON Media (PoolId);
211 CREATE TABLE MediaType (
213 MediaType VARCHAR(128) NOT NULL,
214 ReadOnly TINYINT DEFAULT 0,
215 PRIMARY KEY(MediaTypeId)
218 CREATE TABLE Storage (
220 Name VARCHAR(128) NOT NULL,
221 AutoChanger TINYINT DEFAULT 0,
222 PRIMARY KEY(StorageId)
225 CREATE TABLE Device (
227 Name VARCHAR(128) NOT NULL,
228 MediaTypeId INTEGER UNSIGNED REFERENCES MediaType NOT NULL,
229 StorageId INTEGER UNSIGNED REFERENCES Storage,
230 DevMounts INTEGER UNSIGNED DEFAULT 0,
231 DevReadBytes BIGINT UNSIGNED DEFAULT 0,
232 DevWriteBytes BIGINT UNSIGNED DEFAULT 0,
233 DevReadBytesSinceCleaning BIGINT UNSIGNED DEFAULT 0,
234 DevWriteBytesSinceCleaning BIGINT UNSIGNED DEFAULT 0,
235 DevReadTime BIGINT UNSIGNED DEFAULT 0,
236 DevWriteTime BIGINT UNSIGNED DEFAULT 0,
237 DevReadTimeSinceCleaning BIGINT UNSIGNED DEFAULT 0,
238 DevWriteTimeSinceCleaning BIGINT UNSIGNED DEFAULT 0,
239 CleaningDate DATETIME DEFAULT 0,
240 CleaningPeriod BIGINT UNSIGNED DEFAULT 0,
241 PRIMARY KEY(DeviceId)
247 Name VARCHAR(128) NOT NULL,
248 NumVols INTEGER UNSIGNED DEFAULT 0,
249 MaxVols INTEGER UNSIGNED DEFAULT 0,
250 UseOnce TINYINT DEFAULT 0,
251 UseCatalog TINYINT DEFAULT 1,
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 VARCHAR(20) NOT NULL,
262 LabelType TINYINT DEFAULT 0,
263 LabelFormat VARCHAR(128) NOT NULL,
264 Enabled TINYINT DEFAULT 1,
265 ScratchPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
266 RecyclePoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
267 NextPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
268 MigrationHighBytes BIGINT UNSIGNED DEFAULT 0,
269 MigrationLowBytes BIGINT UNSIGNED DEFAULT 0,
270 MigrationTime BIGINT UNSIGNED DEFAULT 0,
276 CREATE TABLE Client (
278 Name VARCHAR(128) NOT NULL,
279 Uname VARCHAR(255) NOT NULL, -- uname -a field
280 AutoPrune TINYINT DEFAULT 0,
281 FileRetention BIGINT UNSIGNED DEFAULT 0,
282 JobRetention BIGINT UNSIGNED DEFAULT 0,
284 PRIMARY KEY(ClientId)
287 CREATE TABLE BaseFiles (
289 BaseJobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
290 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
291 FileId INTEGER UNSIGNED REFERENCES File NOT NULL,
292 FileIndex INTEGER UNSIGNED,
296 CREATE TABLE UnsavedFiles (
298 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
299 PathId INTEGER UNSIGNED REFERENCES Path NOT NULL,
300 FilenameId INTEGER UNSIGNED REFERENCES Filename NOT NULL,
301 PRIMARY KEY (UnsavedId)
305 CREATE TABLE NextId (
306 id INTEGER UNSIGNED DEFAULT 0,
307 TableName TEXT NOT NULL,
308 PRIMARY KEY (TableName)
313 -- Initialize JobId to start at 1
314 INSERT INTO NextId (id, TableName) VALUES (1, 'Job');
316 CREATE TABLE Version (
317 VersionId INTEGER UNSIGNED NOT NULL
321 CREATE TABLE Counters (
322 Counter TEXT NOT NULL,
323 MinValue INTEGER DEFAULT 0,
324 MaxValue INTEGER DEFAULT 0,
325 CurrentValue INTEGER DEFAULT 0,
326 WrapCounter TEXT NOT NULL,
327 PRIMARY KEY (Counter)
330 CREATE TABLE CDImages (
331 MediaId INTEGER UNSIGNED NOT NULL,
332 LastBurn DATETIME NOT NULL,
333 PRIMARY KEY (MediaId)
337 CREATE TABLE Status (
338 JobStatus CHAR(1) NOT NULL,
340 PRIMARY KEY (JobStatus)
343 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
344 ('C', 'Created, not yet running');
345 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
347 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
349 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
350 ('T', 'Completed successfully');
351 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
352 ('E', 'Terminated with errors');
353 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
354 ('e', 'Non-fatal error');
355 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
356 ('f', 'Fatal error');
357 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
358 ('D', 'Verify found differences');
359 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
360 ('A', 'Canceled by user');
361 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
362 ('F', 'Waiting for Client');
363 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
364 ('S', 'Waiting for Storage daemon');
365 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
366 ('m', 'Waiting for new media');
367 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
368 ('M', 'Waiting for media mount');
369 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
370 ('s', 'Waiting for storage resource');
371 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
372 ('j', 'Waiting for job resource');
373 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
374 ('c', 'Waiting for client resource');
375 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
376 ('d', 'Waiting on maximum jobs');
377 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
378 ('t', 'Waiting on start time');
379 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
380 ('p', 'Waiting on higher priority jobs');
381 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
382 ('a', 'SD despooling attributes');
383 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
384 ('i', 'Doing batch insert file records');
387 -- Initialize Version
388 INSERT INTO Version (VersionId) VALUES (11);
391 PRAGMA default_synchronous = OFF;
392 PRAGMA default_cache_size = 10000;
396 chmod 640 ${db_name}.db