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);
28 -- FileIndex can be 0 for FT_DELETED files
29 -- FileNameId can link to Filename.Name='' for directories
32 FileIndex INTEGER UNSIGNED NOT NULL,
33 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
34 PathId INTEGER UNSIGNED REFERENCES Path NOT NULL,
35 FilenameId INTEGER UNSIGNED REFERENCES Filename NOT NULL,
36 MarkId INTEGER UNSIGNED DEFAULT 0,
37 LStat VARCHAR(255) NOT NULL,
38 MD5 VARCHAR(255) NOT NULL,
42 CREATE INDEX inx3 ON File (JobId);
43 CREATE INDEX file_jpf_idx ON File (JobId, PathId, FilenameId);
45 -- Possibly add one or more of the following indexes
46 -- if your Verifies are too slow.
48 -- CREATE INDEX inx4 ON File (PathId);
49 -- CREATE INDEX inx5 ON File (FileNameId);
53 Job VARCHAR(128) NOT NULL,
54 Name VARCHAR(128) NOT NULL,
55 Type CHAR(1) NOT NULL,
56 Level CHAR(1) NOT NULL,
57 ClientId INTEGER REFERENCES Client DEFAULT 0,
58 JobStatus CHAR(1) NOT NULL,
59 SchedTime DATETIME NOT NULL,
60 StartTime DATETIME DEFAULT 0,
61 EndTime DATETIME DEFAULT 0,
62 RealEndTime DATETIME DEFAULT 0,
63 JobTDate BIGINT UNSIGNED DEFAULT 0,
64 VolSessionId INTEGER UNSIGNED DEFAULT 0,
65 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
66 JobFiles INTEGER UNSIGNED DEFAULT 0,
67 JobBytes BIGINT UNSIGNED DEFAULT 0,
68 ReadBytes BIGINT UNSIGNED DEFAULT 0,
69 JobErrors INTEGER UNSIGNED DEFAULT 0,
70 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
71 PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
72 FileSetId INTEGER UNSIGNED REFERENCES FileSet DEFAULT 0,
73 PriorJobId INTEGER UNSIGNED REFERENCES Job DEFAULT 0,
74 PurgedFiles TINYINT DEFAULT 0,
75 HasBase TINYINT DEFAULT 0,
78 CREATE INDEX inx6 ON Job (Name);
80 -- Create a table like Job for long term statistics
81 CREATE TABLE JobHisto (
83 Job VARCHAR(128) NOT NULL,
84 Name VARCHAR(128) NOT NULL,
85 Type CHAR(1) NOT NULL,
86 Level CHAR(1) NOT NULL,
87 ClientId INTEGER DEFAULT 0,
88 JobStatus CHAR(1) NOT NULL,
89 SchedTime DATETIME NOT NULL,
90 StartTime DATETIME DEFAULT 0,
91 EndTime DATETIME DEFAULT 0,
92 RealEndTime DATETIME DEFAULT 0,
93 JobTDate BIGINT UNSIGNED DEFAULT 0,
94 VolSessionId INTEGER UNSIGNED DEFAULT 0,
95 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
96 JobFiles INTEGER UNSIGNED DEFAULT 0,
97 JobBytes BIGINT UNSIGNED DEFAULT 0,
98 ReadBytes BIGINT UNSIGNED DEFAULT 0,
99 JobErrors INTEGER UNSIGNED DEFAULT 0,
100 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
101 PoolId INTEGER UNSIGNED DEFAULT 0,
102 FileSetId INTEGER UNSIGNED DEFAULT 0,
103 PriorJobId INTEGER UNSIGNED DEFAULT 0,
104 PurgedFiles TINYINT DEFAULT 0,
105 HasBase TINYINT DEFAULT 0
107 CREATE INDEX inx61 ON JobHisto (StartTime);
109 CREATE TABLE Location (
111 Location TEXT NOT NULL,
112 Cost INTEGER DEFAULT 0,
114 PRIMARY KEY(LocationId)
117 CREATE TABLE LocationLog (
119 Date DATETIME NOT NULL,
120 Comment TEXT NOT NULL,
121 MediaId INTEGER UNSIGNED REFERENCES Media DEFAULT 0,
122 LocationId INTEGER UNSIGNED REFERENCES LocationId DEFAULT 0,
123 NewVolStatus VARCHAR(20) NOT NULL,
124 NewEnabled TINYINT NOT NULL,
125 PRIMARY KEY(LocLogId)
131 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
132 Time DATETIME NOT NULL,
133 LogText TEXT NOT NULL,
136 CREATE INDEX LogInx1 ON Log (JobId);
139 CREATE TABLE FileSet (
141 FileSet VARCHAR(128) NOT NULL,
142 MD5 VARCHAR(25) NOT NULL,
143 CreateTime DATETIME DEFAULT 0,
144 PRIMARY KEY(FileSetId)
147 CREATE TABLE JobMedia (
149 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
150 MediaId INTEGER UNSIGNED REFERENCES Media NOT NULL,
151 FirstIndex INTEGER UNSIGNED NOT NULL,
152 LastIndex INTEGER UNSIGNED NOT NULL,
153 StartFile INTEGER UNSIGNED DEFAULT 0,
154 EndFile INTEGER UNSIGNED DEFAULT 0,
155 StartBlock INTEGER UNSIGNED DEFAULT 0,
156 EndBlock INTEGER UNSIGNED DEFAULT 0,
157 VolIndex INTEGER UNSIGNED DEFAULT 0,
158 Copy INTEGER UNSIGNED DEFAULT 0,
159 PRIMARY KEY(JobMediaId)
162 CREATE INDEX inx7 ON JobMedia (JobId, MediaId);
167 VolumeName VARCHAR(128) NOT NULL,
168 Slot INTEGER DEFAULT 0,
169 PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
170 MediaType VARCHAR(128) NOT NULL,
171 MediaTypeId INTEGER UNSIGNED REFERENCES MediaType DEFAULT 0,
172 LabelType TINYINT DEFAULT 0,
173 FirstWritten DATETIME DEFAULT 0,
174 LastWritten DATETIME DEFAULT 0,
175 LabelDate DATETIME DEFAULT 0,
176 VolJobs INTEGER UNSIGNED DEFAULT 0,
177 VolFiles INTEGER UNSIGNED DEFAULT 0,
178 VolBlocks INTEGER UNSIGNED DEFAULT 0,
179 VolMounts INTEGER UNSIGNED DEFAULT 0,
180 VolBytes BIGINT UNSIGNED DEFAULT 0,
181 VolParts INTEGER UNSIGNED DEFAULT 0,
182 VolErrors INTEGER UNSIGNED DEFAULT 0,
183 VolWrites INTEGER UNSIGNED DEFAULT 0,
184 VolCapacityBytes BIGINT UNSIGNED DEFAULT 0,
185 VolStatus VARCHAR(20) NOT NULL,
186 Enabled TINYINT DEFAULT 1,
187 Recycle TINYINT DEFAULT 0,
188 ActionOnPurge TINYINT DEFAULT 0,
189 VolRetention BIGINT UNSIGNED DEFAULT 0,
190 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
191 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
192 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
193 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
194 InChanger TINYINT DEFAULT 0,
195 StorageId INTEGER UNSIGNED REFERENCES Storage DEFAULT 0,
196 DeviceId INTEGER UNSIGNED REFERENCES Device DEFAULT 0,
197 MediaAddressing TINYINT DEFAULT 0,
198 VolReadTime BIGINT UNSIGNED DEFAULT 0,
199 VolWriteTime BIGINT UNSIGNED DEFAULT 0,
200 EndFile INTEGER UNSIGNED DEFAULT 0,
201 EndBlock INTEGER UNSIGNED DEFAULT 0,
202 LocationId INTEGER UNSIGNED REFERENCES Location DEFAULT 0,
203 RecycleCount INTEGER UNSIGNED DEFAULT 0,
204 InitialWrite DATETIME DEFAULT 0,
205 ScratchPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
206 RecyclePoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
211 CREATE INDEX inx8 ON Media (PoolId);
213 CREATE TABLE MediaType (
215 MediaType VARCHAR(128) NOT NULL,
216 ReadOnly TINYINT DEFAULT 0,
217 PRIMARY KEY(MediaTypeId)
220 CREATE TABLE Storage (
222 Name VARCHAR(128) NOT NULL,
223 AutoChanger TINYINT DEFAULT 0,
224 PRIMARY KEY(StorageId)
227 CREATE TABLE Device (
229 Name VARCHAR(128) NOT NULL,
230 MediaTypeId INTEGER UNSIGNED REFERENCES MediaType NOT NULL,
231 StorageId INTEGER UNSIGNED REFERENCES Storage,
232 DevMounts INTEGER UNSIGNED DEFAULT 0,
233 DevReadBytes BIGINT UNSIGNED DEFAULT 0,
234 DevWriteBytes BIGINT UNSIGNED DEFAULT 0,
235 DevReadBytesSinceCleaning BIGINT UNSIGNED DEFAULT 0,
236 DevWriteBytesSinceCleaning BIGINT UNSIGNED DEFAULT 0,
237 DevReadTime BIGINT UNSIGNED DEFAULT 0,
238 DevWriteTime BIGINT UNSIGNED DEFAULT 0,
239 DevReadTimeSinceCleaning BIGINT UNSIGNED DEFAULT 0,
240 DevWriteTimeSinceCleaning BIGINT UNSIGNED DEFAULT 0,
241 CleaningDate DATETIME DEFAULT 0,
242 CleaningPeriod BIGINT UNSIGNED DEFAULT 0,
243 PRIMARY KEY(DeviceId)
249 Name VARCHAR(128) NOT NULL,
250 NumVols INTEGER UNSIGNED DEFAULT 0,
251 MaxVols INTEGER UNSIGNED DEFAULT 0,
252 UseOnce TINYINT DEFAULT 0,
253 UseCatalog TINYINT DEFAULT 1,
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 VARCHAR(20) NOT NULL,
264 LabelType TINYINT DEFAULT 0,
265 LabelFormat VARCHAR(128) NOT NULL,
266 Enabled TINYINT DEFAULT 1,
267 ScratchPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
268 RecyclePoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
269 NextPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
270 MigrationHighBytes BIGINT UNSIGNED DEFAULT 0,
271 MigrationLowBytes BIGINT UNSIGNED DEFAULT 0,
272 MigrationTime BIGINT UNSIGNED DEFAULT 0,
278 CREATE TABLE Client (
280 Name VARCHAR(128) NOT NULL,
281 Uname VARCHAR(255) NOT NULL, -- uname -a field
282 AutoPrune TINYINT DEFAULT 0,
283 FileRetention BIGINT UNSIGNED DEFAULT 0,
284 JobRetention BIGINT UNSIGNED DEFAULT 0,
286 PRIMARY KEY(ClientId)
289 CREATE TABLE BaseFiles (
291 BaseJobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
292 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
293 FileId INTEGER UNSIGNED REFERENCES File NOT NULL,
294 FileIndex INTEGER UNSIGNED,
298 CREATE TABLE UnsavedFiles (
300 JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
301 PathId INTEGER UNSIGNED REFERENCES Path NOT NULL,
302 FilenameId INTEGER UNSIGNED REFERENCES Filename NOT NULL,
303 PRIMARY KEY (UnsavedId)
307 CREATE TABLE NextId (
308 id INTEGER UNSIGNED DEFAULT 0,
309 TableName TEXT NOT NULL,
310 PRIMARY KEY (TableName)
315 -- Initialize JobId to start at 1
316 INSERT INTO NextId (id, TableName) VALUES (1, 'Job');
318 CREATE TABLE Version (
319 VersionId INTEGER UNSIGNED NOT NULL
323 CREATE TABLE Counters (
324 Counter TEXT NOT NULL,
325 MinValue INTEGER DEFAULT 0,
326 MaxValue INTEGER DEFAULT 0,
327 CurrentValue INTEGER DEFAULT 0,
328 WrapCounter TEXT NOT NULL,
329 PRIMARY KEY (Counter)
332 CREATE TABLE CDImages (
333 MediaId INTEGER UNSIGNED NOT NULL,
334 LastBurn DATETIME NOT NULL,
335 PRIMARY KEY (MediaId)
339 CREATE TABLE Status (
340 JobStatus CHAR(1) NOT NULL,
342 PRIMARY KEY (JobStatus)
345 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
346 ('C', 'Created, not yet running');
347 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
349 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
351 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
352 ('T', 'Completed successfully');
353 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
354 ('E', 'Terminated with errors');
355 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
356 ('e', 'Non-fatal error');
357 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
358 ('f', 'Fatal error');
359 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
360 ('D', 'Verify found differences');
361 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
362 ('A', 'Canceled by user');
363 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
364 ('F', 'Waiting for Client');
365 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
366 ('S', 'Waiting for Storage daemon');
367 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
368 ('m', 'Waiting for new media');
369 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
370 ('M', 'Waiting for media mount');
371 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
372 ('s', 'Waiting for storage resource');
373 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
374 ('j', 'Waiting for job resource');
375 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
376 ('c', 'Waiting for client resource');
377 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
378 ('d', 'Waiting on maximum jobs');
379 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
380 ('t', 'Waiting on start time');
381 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
382 ('p', 'Waiting on higher priority jobs');
383 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
384 ('a', 'SD despooling attributes');
385 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
386 ('i', 'Doing batch insert file records');
389 -- Initialize Version
390 INSERT INTO Version (VersionId) VALUES (11);
393 PRAGMA default_cache_size = 100000;
394 PRAGMA synchronous = NORMAL;
398 chmod 640 ${db_name}.db