3 # shell script to create Bacula Ingres tables
7 db_name=${db_name:-@db_name@}
8 db_user=${db_user:-@db_user@}
10 sql -u${db_user} $* ${db_name} <<END-OF-DATA
13 -- When using batch insert make sure you adhere to the following
14 -- minimum Ingres version:
16 -- Ingres 9.2 or higher with the fix for bug 123652 and bug 117256
17 -- For Solaris x86 this is Ingres 9.2. + patch 13785 or higher
18 -- For Linux x86_64 this is Ingres 9.2 + patch 13790 or higher
22 -- As it seems the upper limit for a VARCHAR/VARBYTE column is 32000 bytes
23 -- We could have used a BLOB as storage type which can go up to 2 Gb but
24 -- you cannot create indexes based on a BLOB (and we don't seem to be able
25 -- to limit the part of the field which should be used for the index to lets
26 -- say 255 chars like we can in MySQL) and the storage for a BLOB is also far
27 -- from optimal so for now we decided that the upper limit for File and Path
28 -- fields is the 32000 bytes.
30 -- To use the big VARBYTE colums we need the bigger page sizes enabled in
31 -- ingres (which at this time supports 2K, 4K, 8K, 16K, 32K, 64K)
32 -- Make sure you have the following settings in your
33 -- ${II_SYSTEM}/ingres/files/config.dat
35 -- ii.<nodename>.dbms.private.*.cache.p8k_status: ON
36 -- ii.<nodename>.dbms.private.*.cache.p16k_status: ON
37 -- ii.<nodename>.dbms.private.*.cache.p32k_status: ON
38 -- ii.<nodename>.dbms.private.*.cache.p64k_status: ON
39 -- ii.<nodename>.rcp.dmf_cache_size8k: 200
40 -- ii.<nodename>.rcp.dmf_cache_size16k: 200
41 -- ii.<nodename>.rcp.dmf_cache_size32k: 200
42 -- ii.<nodename>.rcp.dmf_cache_size64k: 200
47 CREATE SEQUENCE Filename_Seq;
50 FilenameId INTEGER NOT NULL DEFAULT Filename_Seq.nextval,
51 Name VARBYTE(32000) NOT NULL,
52 PRIMARY KEY (FilenameId)
55 CREATE UNIQUE INDEX (filename_name_idx ON filename (Name) WITH STRUCTURE=HASH,PAGE_SIZE=32768);
57 CREATE SEQUENCE Path_Seq;
60 Pathid INTEGER NOT NULL DEFAULT Path_Seq.nextval,
61 Path VARBYTE(32000) NOT NULL,
65 CREATE UNIQUE INDEX (path_name_idx ON path (Path) WITH STRUCTURE=HASH,PAGE_SIZE=32768);
67 CREATE SEQUENCE File_Seq;
70 FileId BIGINT NOT NULL DEFAULT File_Seq.nextval,
71 FileIndex INTEGER NOT NULL DEFAULT 0,
72 JobId INTEGER NOT NULL,
73 PathId INTEGER NOT NULL,
74 FilenameId INTEGER NOT NULL,
75 MarkId INTEGER NOT NULL DEFAULT 0,
76 LStat VARBYTE(255) NOT NULL,
77 Md5 VARBYTE(255) NOT NULL,
81 CREATE INDEX file_jpfid_idx ON File (jobid, pathid, filenameid);
83 -- If you need performances, you can remove this index
84 -- the database engine is able to use the composite index
85 -- to find all records with a given JobId
86 CREATE INDEX file_jobid_idx ON File(jobid);
88 CREATE SEQUENCE RestoreObject_Seq;
89 CREATE TABLE RestoreObject (
90 RestoreObjectId INTEGER NOT NULL DEFAULT RestoreObject_Seq.nextval,
91 ObjectName VARBYTE(128) NOT NULL,
92 RestoreObject BLOB NOT NULL,
93 PluginName VARBYTE(128) NOT NULL,
94 ObjectLength INTEGER DEFAULT 0,
95 ObjectFullLength INTEGER DEFAULT 0,
96 ObjectIndex INTEGER DEFAULT 0,
97 ObjectType INTEGER DEFAULT 0,
98 FileIndex INTEGER DEFAULT 0,
100 ObjectCompression INTEGER DEFAULT 0,
101 PRIMARY KEY (RestoreObjectId)
104 CREATE INDEX restore_jobid_idx on RestoreObject(JobId);
106 CREATE SEQUENCE Job_Seq;
109 JobId INTEGER NOT NULL DEFAULT Job_Seq.nextval,
110 Job VARBYTE(128) NOT NULL,
111 Name VARBYTE(128) NOT NULL,
112 Type CHAR(1) NOT NULL,
113 Level CHAR(1) NOT NULL,
114 ClientId INTEGER DEFAULT 0,
115 JobStatus CHAR(1) NOT NULL,
116 SchedTime TIMESTAMP WITHOUT TIME ZONE,
117 StartTime TIMESTAMP WITHOUT TIME ZONE,
118 EndTime TIMESTAMP WITHOUT TIME ZONE,
119 RealEndTime TIMESTAMP WITHOUT TIME ZONE,
120 JobTDate BIGINT DEFAULT 0,
121 VolSessionId INTEGER DEFAULT 0,
122 volSessionTime INTEGER DEFAULT 0,
123 JobFiles INTEGER DEFAULT 0,
124 JobBytes BIGINT DEFAULT 0,
125 ReadBytes BIGINT DEFAULT 0,
126 JobErrors INTEGER DEFAULT 0,
127 JobMissingFiles INTEGER DEFAULT 0,
128 PoolId INTEGER DEFAULT 0,
129 FilesetId INTEGER DEFAULT 0,
130 PriorJobid INTEGER DEFAULT 0,
131 PurgedFiles SMALLINT DEFAULT 0,
132 HasBase SMALLINT DEFAULT 0,
133 HasCache SMALLINT DEFAULT 0,
134 Reviewed SMALLINT DEFAULT 0,
135 Comment VARBYTE(4096),
139 CREATE INDEX job_name_idx ON Job (Name);
141 -- Create a table like Job for long term statistics
142 CREATE SEQUENCE JobHisto_Seq;
143 CREATE TABLE JobHisto
145 JobId INTEGER NOT NULL DEFAULT JobHisto_Seq.nextval,
146 Job VARBYTE(128) NOT NULL,
147 Name VARBYTE(128) NOT NULL,
148 Type CHAR(1) NOT NULL,
149 Level CHAR(1) NOT NULL,
150 ClientId INTEGER DEFAULT 0,
151 JobStatus CHAR(1) NOT NULL,
152 SchedTime TIMESTAMP WITHOUT TIME ZONE,
153 StartTime TIMESTAMP WITHOUT TIME ZONE,
154 EndTime TIMESTAMP WITHOUT TIME ZONE,
155 RealEndTime TIMESTAMP WITHOUT TIME ZONE,
156 JobTDate BIGINT DEFAULT 0,
157 VolSessionId INTEGER DEFAULT 0,
158 volSessionTime INTEGER DEFAULT 0,
159 JobFiles INTEGER DEFAULT 0,
160 JobBytes BIGINT DEFAULT 0,
161 ReadBytes BIGINT DEFAULT 0,
162 JobErrors INTEGER DEFAULT 0,
163 JobMissingFiles INTEGER DEFAULT 0,
164 PoolId INTEGER DEFAULT 0,
165 FilesetId INTEGER DEFAULT 0,
166 PriorJobid INTEGER DEFAULT 0,
167 PurgedFiles SMALLINT DEFAULT 0,
168 HasBase SMALLINT DEFAULT 0,
169 HasCache SMALLINT DEFAULT 0,
170 Reviewed SMALLINT DEFAULT 0,
171 Comment VARBYTE(4096),
175 CREATE INDEX jobhisto_idx ON JobHisto (StartTime);
177 CREATE SEQUENCE Location_Seq;
178 CREATE TABLE Location (
179 LocationId INTEGER NOT NULL DEFAULT Location_Seq.nextval,
180 Location VARBYTE(128) NOT NULL,
181 Cost INTEGER DEFAULT 0,
183 PRIMARY KEY (LocationId)
186 CREATE SEQUENCE Fileset_Seq;
189 FilesetId INTEGER NOT NULL DEFAULT Fileset_Seq.nextval,
190 Fileset VARBYTE(128) NOT NULL,
191 Md5 VARBYTE(128) NOT NULL,
192 Createtime TIMESTAMP WITHOUT TIME ZONE NOT NULL,
193 PRIMARY KEY (filesetid)
196 CREATE INDEX fileset_name_idx ON Fileset (fileset);
198 CREATE SEQUENCE JobMedia_Seq;
199 CREATE TABLE JobMedia
201 JobMediaId INTEGER NOT NULL DEFAULT JobMedia_Seq.nextval,
202 JobId INTEGER NOT NULL,
203 MediaId INTEGER NOT NULL,
204 FirstIndex INTEGER DEFAULT 0,
205 LastIndex INTEGER DEFAULT 0,
206 StartFile INTEGER DEFAULT 0,
207 EndFile INTEGER DEFAULT 0,
208 StartBlock BIGINT DEFAULT 0,
209 EndBlock BIGINT DEFAULT 0,
210 VolIndex INTEGER DEFAULT 0,
211 PRIMARY KEY (jobmediaid)
214 CREATE INDEX job_media_job_id_media_id_idx ON JobMedia (jobid, mediaid);
216 CREATE SEQUENCE Media_Seq;
219 MediaId INTEGER NOT NULL DEFAULT Media_Seq.nextval,
220 VolumeName VARBYTE(128) NOT NULL,
221 Slot INTEGER DEFAULT 0,
222 PoolId INTEGER DEFAULT 0,
223 MediaType VARBYTE(128) NOT NULL,
224 MediaTypeId INTEGER DEFAULT 0,
225 LabelType INTEGER DEFAULT 0,
226 FirstWritten TIMESTAMP WITHOUT TIME ZONE,
227 LastWritten TIMESTAMP WITHOUT TIME ZONE,
228 LabelDate TIMESTAMP WITHOUT TIME ZONE,
229 VolJobs INTEGER DEFAULT 0,
230 VolFiles INTEGER DEFAULT 0,
231 VolBlocks INTEGER DEFAULT 0,
232 VolMounts INTEGER DEFAULT 0,
233 VolBytes BIGINT DEFAULT 0,
234 VolParts INTEGER DEFAULT 0,
235 VolErrors INTEGER DEFAULT 0,
236 VolWrites INTEGER DEFAULT 0,
237 VolCapacitybytes BIGINT DEFAULT 0,
238 VolStatus VARBYTE(128) NOT NULL
239 CHECK (volstatus in ('Full','Archive','Append',
240 'Recycle','Purged','Read-Only','Disabled',
241 'Error','Busy','Used','Cleaning','Scratch')),
242 Enabled SMALLINT DEFAULT 1,
243 Recycle SMALLINT DEFAULT 0,
244 ActionOnPurge SMALLINT DEFAULT 0,
245 VolRetention BIGINT DEFAULT 0,
246 VolUseDuration BIGINT DEFAULT 0,
247 MaxVolJobs INTEGER DEFAULT 0,
248 MaxVolFiles INTEGER DEFAULT 0,
249 MaxVolBytes BIGINT DEFAULT 0,
250 InChanger SMALLINT DEFAULT 0,
251 StorageId BIGINT DEFAULT 0,
252 DeviceId INTEGER DEFAULT 0,
253 MediaAddressing SMALLINT DEFAULT 0,
254 VolReadTime BIGINT DEFAULT 0,
255 VolWriteTime BIGINT DEFAULT 0,
256 EndFile INTEGER DEFAULT 0,
257 EndBlock BIGINT DEFAULT 0,
258 LocationId INTEGER DEFAULT 0,
259 RecycleCount INTEGER DEFAULT 0,
260 InitialWrite TIMESTAMP WITHOUT TIME ZONE,
261 ScratchPoolId INTEGER DEFAULT 0,
262 RecyclePoolId INTEGER DEFAULT 0,
263 Comment VARBYTE(4096),
264 PRIMARY KEY (mediaid)
267 CREATE UNIQUE INDEX media_volumename_id ON Media (VolumeName);
269 CREATE SEQUENCE MediaType_Seq;
270 CREATE TABLE MediaType (
271 MediaTypeId INTEGER NOT NULL DEFAULT MediaType_Seq.nextval,
272 MediaType VARBYTE(128) NOT NULL,
273 ReadOnly INTEGER NOT NULL DEFAULT 0,
274 PRIMARY KEY (MediaTypeId)
277 CREATE SEQUENCE Storage_Seq;
278 CREATE TABLE Storage (
279 StorageId INTEGER NOT NULL DEFAULT Storage_Seq.nextval,
280 Name VARBYTE(128) NOT NULL,
281 AutoChanger INTEGER NOT NULL DEFAULT 0,
282 PRIMARY KEY (StorageId)
285 CREATE SEQUENCE Device_Seq;
286 CREATE TABLE Device (
287 DeviceId INTEGER NOT NULL DEFAULT Device_Seq.nextval,
288 Name VARBYTE(128) NOT NULL,
289 MediaTypeId INTEGER NOT NULL,
290 StorageId INTEGER NOT NULL,
291 DevMounts INTEGER NOT NULL DEFAULT 0,
292 DevReadBytes BIGINT NOT NULL DEFAULT 0,
293 DevWriteBytes BIGINT NOT NULL DEFAULT 0,
294 DevReadBytesSinceCleaning BIGINT NOT NULL DEFAULT 0,
295 DevWriteBytesSinceCleaning BIGINT NOT NULL DEFAULT 0,
296 DevReadTime BIGINT NOT NULL DEFAULT 0,
297 DevWriteTime BIGINT NOT NULL DEFAULT 0,
298 DevReadTimeSinceCleaning BIGINT NOT NULL DEFAULT 0,
299 DevWriteTimeSinceCleaning BIGINT NOT NULL DEFAULT 0,
300 CleaningDate TIMESTAMP WITHOUT TIME ZONE,
301 CleaningPeriod BIGINT NOT NULL DEFAULT 0,
302 PRIMARY KEY (DeviceId)
305 CREATE SEQUENCE Pool_Seq;
308 PoolId INTEGER NOT NULL DEFAULT pool_Seq.nextval,
309 Name VARBYTE(128) NOT NULL,
310 NumVols INTEGER DEFAULT 0,
311 MaxVols INTEGER DEFAULT 0,
312 UseOnce SMALLINT DEFAULT 0,
313 UseCatalog SMALLINT DEFAULT 0,
314 AcceptAnyVolume SMALLINT DEFAULT 0,
315 VolRetention BIGINT DEFAULT 0,
316 VolUseDuration BIGINT DEFAULT 0,
317 MaxVolJobs INTEGER DEFAULT 0,
318 MaxVolFiles INTEGER DEFAULT 0,
319 MaxVolBytes BIGINT DEFAULT 0,
320 AutoPrune SMALLINT DEFAULT 0,
321 Recycle SMALLINT DEFAULT 0,
322 ActionOnPurge SMALLINT DEFAULT 0,
324 CHECK (pooltype in ('Backup','Copy','Cloned','Archive','Migration','Scratch')),
325 LabelType INTEGER DEFAULT 0,
326 LabelFormat VARBYTE(128) NOT NULL,
327 Enabled SMALLINT DEFAULT 1,
328 ScratchPoolId INTEGER DEFAULT 0,
329 RecyclePoolId INTEGER DEFAULT 0,
330 NextPoolId INTEGER DEFAULT 0,
331 MigrationHighBytes BIGINT DEFAULT 0,
332 MigrationLowBytes BIGINT DEFAULT 0,
333 MigrationTime BIGINT DEFAULT 0,
337 CREATE INDEX pool_name_idx ON Pool (name);
339 CREATE SEQUENCE Client_Seq;
342 ClientId INTEGER NOT NULL DEFAULT Client_Seq.nextval,
343 Name VARBYTE(128) NOT NULL,
344 Uname VARBYTE(256) NOT NULL,
345 AutoPrune SMALLINT DEFAULT 0,
346 FileRetention BIGINT DEFAULT 0,
347 JobRetention BIGINT DEFAULT 0,
348 PRIMARY KEY (clientid)
351 CREATE UNIQUE INDEX client_name_idx ON Client (Name);
353 CREATE SEQUENCE Log_Seq;
356 LogId INTEGER NOT NULL DEFAULT Log_Seq.nextval,
357 JobId INTEGER NOT NULL,
358 Time TIMESTAMP WITHOUT TIME ZONE,
359 LogText VARBYTE(4096) NOT NULL,
362 CREATE INDEX log_name_idx ON Log (JobId);
364 CREATE SEQUENCE LocationLog_Seq;
365 CREATE TABLE LocationLog (
366 LocLogId INTEGER NOT NULL DEFAULT LocationLog_Seq.nextval,
367 Date TIMESTAMP WITHOUT TIME ZONE,
368 Comment VARBYTE(4096) NOT NULL,
369 MediaId INTEGER DEFAULT 0,
370 LocationId INTEGER DEFAULT 0,
371 NewVolStatus VARBYTE(32) NOT NULL
372 CHECK (newvolstatus in ('Full','Archive','Append',
373 'Recycle','Purged','Read-Only','Disabled',
374 'Error','Busy','Used','Cleaning','Scratch')),
376 PRIMARY KEY (LocLogId)
379 CREATE TABLE Counters
381 Counter VARBYTE(128) NOT NULL,
382 MinValue INTEGER DEFAULT 0,
383 MaxValue INTEGER DEFAULT 0,
384 CurrentValue INTEGER DEFAULT 0,
385 WrapCounter VARBYTE(128) NOT NULL,
386 PRIMARY KEY (counter)
389 CREATE SEQUENCE BaseFiles_Seq;
390 CREATE TABLE BaseFiles
392 BaseId INTEGER NOT NULL DEFAULT BaseFiles_Seq.nextval,
393 JobId INTEGER NOT NULL,
394 FileId BIGINT NOT NULL,
400 CREATE INDEX basefiles_jobid_idx ON BaseFiles (JobId);
402 CREATE TABLE unsavedfiles
404 UnsavedId INTEGER NOT NULL,
405 JobId INTEGER NOT NULL,
406 PathId INTEGER NOT NULL,
407 FilenameId INTEGER NOT NULL,
408 PRIMARY KEY (UnsavedId)
411 CREATE TABLE CDImages
413 MediaId INTEGER NOT NULL,
414 LastBurn TIMESTAMP WITHOUT TIME ZONE NOT NULL,
415 PRIMARY KEY (MediaId)
418 CREATE TABLE PathHierarchy
420 PathId INTEGER NOT NULL,
421 PPathId INTEGER NOT NULL,
422 CONSTRAINT pathhierarchy_pkey PRIMARY KEY (PathId)
425 CREATE INDEX pathhierarchy_ppathid ON PathHierarchy (PPathId);
427 CREATE TABLE PathVisibility
429 PathId INTEGER NOT NULL,
430 JobId INTEGER NOT NULL,
431 Size BIGINT DEFAULT 0,
432 Files INTEGER DEFAULT 0,
433 CONSTRAINT pathvisibility_pkey PRIMARY KEY (JobId, PathId)
435 CREATE INDEX pathvisibility_jobid ON PathVisibility (JobId);
439 versionid INTEGER NOT NULL
442 CREATE TABLE Status (
443 JobStatus CHAR(1) NOT NULL,
444 JobStatusLong VARBYTE(128),
446 PRIMARY KEY (JobStatus)
451 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
452 ('C', 'Created, not yet running',15);
453 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
455 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
457 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
458 ('T', 'Completed successfully', 10);
459 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
460 ('E', 'Terminated with errors', 25);
461 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
462 ('e', 'Non-fatal error',20);
463 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
464 ('f', 'Fatal error',100);
465 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
466 ('D', 'Verify found differences',15);
467 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
468 ('A', 'Canceled by user',90);
469 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
470 ('F', 'Waiting for Client',15);
471 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
472 ('S', 'Waiting for Storage daemon',15);
473 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
474 ('m', 'Waiting for new media');
475 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
476 ('M', 'Waiting for media mount',15);
477 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
478 ('s', 'Waiting for storage resource',15);
479 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
480 ('j', 'Waiting for job resource',15);
481 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
482 ('c', 'Waiting for client resource',15);
483 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
484 ('d', 'Waiting on maximum jobs',15);
485 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
486 ('t', 'Waiting on start time',15);
487 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
488 ('p', 'Waiting on higher priority jobs',15);
489 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
490 ('a', 'SD despooling attributes',15);
491 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
492 ('i', 'Doing batch insert file records',15);
494 INSERT INTO Version (VersionId) VALUES (12);
496 -- Make sure we have appropriate permissions
503 echo "Creation of Bacula Ingres tables succeeded."
505 echo "Creation of Bacula Ingres tables failed."