3 # Shell script to update PostgreSQL tables from version 11 to 12
6 echo "This script will update a Bacula PostgreSQL database from version 11 to 12"
7 echo " which is needed to convert from Bacula Enterprise 2.6 to 4.0 or "
8 echo " Standard version 3.0 to 5.0"
12 export PATH="$bindir:$PATH"
15 if psql -f - -d ${db_name} $* <<END-OF-DATA
17 ALTER TABLE JobMedia DROP Copy ;
18 ALTER TABLE Job ADD COLUMN HasCache smallint default 0;
19 ALTER TABLE Job ADD COLUMN Comment text;
20 ALTER TABLE JobHisto ADD COLUMN Comment text;
21 ALTER TABLE JobHisto ADD COLUMN HasCache smallint default 0;
23 ALTER TABLE Status ADD COLUMN Severity int;
24 UPDATE Status SET Severity = 15;
25 UPDATE Status SET Severity = 100 where JobStatus = 'f';
26 UPDATE Status SET Severity = 90 where JobStatus = 'A';
27 UPDATE Status SET Severity = 10 where JobStatus = 'T';
28 UPDATE Status SET Severity = 20 where JobStatus = 'e';
29 UPDATE Status SET Severity = 25 where JobStatus = 'E';
31 CREATE TABLE PathHierarchy
33 PathId integer NOT NULL,
34 PPathId integer NOT NULL,
35 CONSTRAINT pathhierarchy_pkey PRIMARY KEY (PathId)
38 CREATE INDEX pathhierarchy_ppathid
39 ON PathHierarchy (PPathId);
41 CREATE TABLE PathVisibility
43 PathId integer NOT NULL,
44 JobId integer NOT NULL,
47 CONSTRAINT pathvisibility_pkey PRIMARY KEY (JobId, PathId)
50 CREATE INDEX pathvisibility_jobid
51 ON PathVisibility (JobId);
54 UPDATE Version SET VersionId=12;
57 CREATE INDEX basefiles_jobid_idx ON BaseFiles ( JobId );
59 -- Remove bad PostgreSQL index
60 DROP INDEX file_fp_idx;
62 -- Create the good one
63 -- If you want to create this index during production, you can use
64 -- CREATE INDEX CONCURRENTLY file_jpf_idx ON File (JobId, PathId, FilenameId)
65 -- to make it without locks (require PostgreSQL 8.2 version)
67 CREATE INDEX file_jpfid_idx on File (JobId, PathId, FilenameId);
73 echo "Update of Bacula PostgreSQL tables succeeded."
75 echo "Update of Bacula PostgreSQL tables failed."