]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/make_postgresql_tables.in
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / cats / make_postgresql_tables.in
1 #!/bin/sh
2 #
3 # shell script to create Bacula PostgreSQL tables
4 #
5 bindir=@SQL_BINDIR@
6
7 if $bindir/psql -f - -d bacula $* <<END-OF-DATA
8
9 CREATE TABLE filename
10 (
11     filenameid        serial      not null,
12     name              text        not null,
13     primary key (filenameid)
14 );
15
16 CREATE INDEX filename_name_idx on filename (name);
17
18 CREATE TABLE path
19 (
20     pathid            serial      not null,
21     path              text        not null,
22     primary key (pathid)
23 );
24
25 CREATE INDEX path_name_idx on path (path);
26
27 CREATE TABLE file
28 (
29     fileid            serial      not null,
30     fileindex         integer     not null  default 0,
31     jobid             integer     not null,
32     pathid            integer     not null,
33     filenameid        integer     not null,
34     markid            integer     not null  default 0,
35     lstat             text        not null,
36     md5               text        not null,
37     primary key (fileid)
38 );
39
40 CREATE INDEX file_jobid_idx on file (jobid);
41 CREATE INDEX file_fp_idx on file (filenameid, pathid);
42
43 --
44 -- Possibly add one or more of the following indexes
45 --  if your Verifies are too slow.
46 --
47 -- CREATE INDEX file_pathid_idx on file(pathid);
48 -- CREATE INDEX file_filenameid_idx on file(filenameid);
49 -- CREATE INDEX file_jpfid_idx on file (jobid, pathid, filenameid);
50
51 CREATE TABLE job
52 (
53     jobid             serial      not null,
54     job               text        not null,
55     name              text        not null,
56     type              char(1)     not null,
57     level             char(1)     not null,
58     clientid          integer,
59     jobstatus         char(1)     not null,
60     schedtime         timestamp   without time zone not null,
61     starttime         timestamp   without time zone,
62     endtime           timestamp   without time zone,
63     jobtdate          bigint      not null,
64     volsessionid      integer     not null default 0,
65     volsessiontime    integer     not null default 0,
66     jobfiles          integer     not null default 0,
67     jobbytes          bigint      not null default 0,
68     joberrors         integer     not null default 0,
69     jobmissingfiles   integer     not null default 0,
70     poolid            integer,
71     filesetid         integer,
72     purgedfiles       smallint    not null default 0,
73     hasbase           smallint    not null default 0,
74     primary key (jobid)
75 );
76
77 CREATE INDEX job_name_idx on job (name);
78
79 CREATE TABLE fileset
80 (
81     filesetid         serial      not null,
82     fileset           text        not null,
83     md5               text        not null,
84     createtime        timestamp without time zone not null,
85     primary key (filesetid)
86 );
87
88 CREATE INDEX fileset_name_idx on fileset (fileset);
89
90 CREATE TABLE jobmedia
91 (
92     jobmediaid        serial      not null,
93     jobid             integer     not null,
94     mediaid           integer     not null,
95     firstindex        integer     not null default 0,
96     lastindex         integer     not null default 0,
97     startfile         integer     not null default 0,
98     endfile           integer     not null default 0,
99     startblock        bigint      not null default 0,
100     endblock          bigint      not null default 0,
101     volindex          integer     not null default 0,
102     copy              integer     not null default 0,
103     stripe            integer     not null default 0,
104     primary key (jobmediaid)
105 );
106
107 CREATE INDEX job_media_job_id_media_id_idx on jobmedia (jobid, mediaid);
108
109 CREATE TABLE media
110 (
111     mediaid           serial      not null,
112     volumename        text        not null,
113     slot              integer     not null default 0,
114     poolid            integer     not null,
115     mediatype         text        not null,
116     labeltype         integer     not null default 0,
117     firstwritten      timestamp   without time zone,
118     lastwritten       timestamp   without time zone,
119     labeldate         timestamp   without time zone,
120     voljobs           integer     not null default 0,
121     volfiles          integer     not null default 0,
122     volblocks         integer     not null default 0,
123     volmounts         integer     not null default 0,
124     volbytes          bigint      not null default 0,
125     volparts          integer     not null default 0,
126     volerrors         integer     not null default 0,
127     volwrites         integer     not null default 0,
128     volcapacitybytes  bigint      not null default 0,
129     volstatus         text        not null
130         check (volstatus in ('Full','Archive','Append',
131               'Recycle','Purged','Read-Only','Disabled',
132               'Error','Busy','Used','Cleaning','Scratch')),
133     recycle           smallint    not null default 0,
134     volretention      bigint      not null default 0,
135     voluseduration    bigint      not null default 0,
136     maxvoljobs        integer     not null default 0,
137     maxvolfiles       integer     not null default 0,
138     maxvolbytes       bigint      not null default 0,
139     inchanger         smallint    not null default 0,
140     StorageId         integer              default 0,
141     mediaaddressing   smallint    not null default 0,
142     volreadtime       bigint      not null default 0,
143     volwritetime      bigint      not null default 0,
144     endfile           integer     not null default 0,
145     endblock          bigint      not null default 0,
146     primary key (mediaid)
147 );
148
149 create unique index media_volumename_id on media (volumename);
150
151  
152 CREATE TABLE MediaType (
153    MediaTypeId SERIAL,
154    MediaType TEXT NOT NULL,
155    ReadOnly INTEGER DEFAULT 0,
156    PRIMARY KEY(MediaTypeId)
157    );
158
159 CREATE TABLE Storage (
160    StorageId SERIAL,
161    Name TEXT NOT NULL,
162    AutoChanger INTEGER DEFAULT 0,
163    PRIMARY KEY(StorageId)
164    );
165
166 CREATE TABLE Device (
167    DeviceId SERIAL,
168    Name TEXT NOT NULL,
169    MediaTypeId INTEGER NOT NULL,
170    StorageId INTEGER NOT NULL,
171    DevMounts INTEGER NOT NULL DEFAULT 0,
172    DevReadBytes BIGINT NOT NULL DEFAULT 0,
173    DevWriteBytes BIGINT NOT NULL DEFAULT 0,
174    DevReadBytesSinceCleaning BIGINT NOT NULL DEFAULT 0,
175    DevWriteBytesSinceCleaning BIGINT NOT NULL DEFAULT 0,
176    DevReadTime BIGINT NOT NULL DEFAULT 0,
177    DevWriteTime BIGINT NOT NULL DEFAULT 0,
178    DevReadTimeSinceCleaning BIGINT NOT NULL DEFAULT 0,
179    DevWriteTimeSinceCleaning BIGINT NOT NULL DEFAULT 0,
180    CleaningDate TIMESTAMP WITHOUT TIME ZONE,
181    CleaningPeriod BIGINT NOT NULL DEFAULT 0,
182    PRIMARY KEY(DeviceId)
183    );
184
185
186 CREATE TABLE pool
187 (
188     poolid            serial      not null,
189     name              text        not null,
190     numvols           integer     not null default 0,
191     maxvols           integer     not null default 0,
192     useonce           smallint    not null default 0,
193     usecatalog        smallint    not null default 0,
194     acceptanyvolume   smallint    not null default 0,
195     volretention      bigint      not null default 0,
196     voluseduration    bigint      not null default 0,
197     maxvoljobs        integer     not null default 0,
198     maxvolfiles       integer     not null default 0,
199     maxvolbytes       bigint      not null default 0,
200     autoprune         smallint    not null default 0,
201     recycle           smallint    not null default 0,
202     pooltype          text                          
203       check (pooltype in ('Backup','Copy','Cloned','Archive','Migration','Scratch')),
204     labeltype         integer     not null default 0,
205     labelformat       text        not null,
206     enabled           smallint    not null default 1,
207     scratchpoolid     integer default 0,
208     recyclepoolid     integer default 0,
209     NextPoolId        integer default 0,
210     MigrationHighBytes BIGINT DEFAULT 0,
211     MigrationLowBytes  BIGINT DEFAULT 0,
212     MigrationTime      BIGINT DEFAULT 0,
213     primary key (poolid)
214 );
215
216 CREATE INDEX pool_name_idx on pool (name);
217
218 CREATE TABLE client
219 (
220     clientid          serial      not null,
221     name              text        not null,
222     uname             text        not null,
223     autoprune         smallint    default 0,
224     fileretention     bigint      not null,
225     jobretention      bigint      not null,
226     primary key (clientid)
227 );
228
229 create unique index client_name_idx on client (name);
230
231
232 CREATE TABLE counters
233 (
234     counter           text        not null,
235     minvalue          integer,
236     maxvalue          integer,
237     currentvalue      integer,
238     wrapcounter       text        not null,
239     primary key (counter)
240 );
241
242
243
244 CREATE TABLE basefiles
245 (
246     baseid            serial                not null,
247     jobid             integer               not null,
248     fileid            integer               not null,
249     fileindex         integer                       ,
250     basejobid         integer                       ,
251     primary key (baseid)
252 );
253
254 CREATE TABLE unsavedfiles
255 (
256     UnsavedId         integer               not null,
257     jobid             integer               not null,
258     pathid            integer               not null,
259     filenameid        integer               not null,
260     primary key (UnsavedId)
261 );
262
263 CREATE TABLE CDImages 
264 (
265    MediaId integer not null,
266    LastBurn timestamp without time zone not null,
267    primary key (MediaId)
268 );
269
270
271 CREATE TABLE version
272 (
273     versionid         integer               not null
274 );
275
276 CREATE TABLE Status (
277    JobStatus CHAR(1) NOT NULL,
278    JobStatusLong TEXT, 
279    PRIMARY KEY (JobStatus)
280    );
281
282 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
283    ('C', 'Created, not yet running');
284 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
285    ('R', 'Running');
286 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
287    ('B', 'Blocked');
288 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
289    ('T', 'Completed successfully');
290 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
291    ('E', 'Terminated with errors');
292 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
293    ('e', 'Non-fatal error');
294 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
295    ('f', 'Fatal error');
296 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
297    ('D', 'Verify found differences');
298 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
299    ('A', 'Canceled by user');
300 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
301    ('F', 'Waiting for Client');
302 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
303    ('S', 'Waiting for Storage daemon');
304 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
305    ('m', 'Waiting for new media');
306 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
307    ('M', 'Waiting for media mount');
308 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
309    ('s', 'Waiting for storage resource');
310 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
311    ('j', 'Waiting for job resource');
312 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
313    ('c', 'Waiting for client resource');
314 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
315    ('d', 'Waiting on maximum jobs');
316 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
317    ('t', 'Waiting on start time');
318 INSERT INTO Status (JobStatus,JobStatusLong) VALUES
319    ('p', 'Waiting on higher priority jobs');
320
321
322 INSERT INTO Version (VersionId) VALUES (9);
323
324 -- Make sure we have appropriate permissions
325
326
327 END-OF-DATA
328 then
329    echo "Creation of Bacula PostgreSQL tables succeeded."
330 else
331    echo "Creation of Bacula PostgreSQL tables failed."
332 fi
333 exit 0