3 # Shell script to update PostgreSQL tables from Bacula Community version 3.0.x to 5.0.0
6 echo "This script will update a Bacula PostgreSQL database from version 11 to 12"
7 echo " which is needed to convert from Bacula Community version 3.0.x to 5.0.x"
14 DBVERSION=`psql ${db_name} -t --pset format=unaligned -c "select VersionId from Version"`
15 if [ $DBVERSION != 11 ] ; then
17 echo "The existing database is version $DBVERSION !!"
18 echo "This script can only update an existing version 11 database to version 12."
19 echo "Error. Cannot upgrade this database."
24 if psql -f - -d ${db_name} $* <<END-OF-DATA
25 BEGIN; -- Necessary for Bacula core
26 ALTER TABLE JobMedia DROP Copy ;
27 ALTER TABLE Job ADD COLUMN HasCache smallint default 0;
28 ALTER TABLE Job ADD COLUMN Reviewed smallint default 0;
29 ALTER TABLE Job ADD COLUMN Comment text;
30 ALTER TABLE JobHisto ADD COLUMN HasCache smallint default 0;
31 ALTER TABLE JobHisto ADD COLUMN Reviewed smallint default 0;
32 ALTER TABLE JobHisto ADD COLUMN Comment text;
33 UPDATE Version SET VersionId=12;
36 BEGIN; -- Can conflict with previous Bweb installation
37 ALTER TABLE Status ADD COLUMN Severity int;
38 UPDATE Status SET Severity = 15;
39 UPDATE Status SET Severity = 100 where JobStatus = 'f';
40 UPDATE Status SET Severity = 90 where JobStatus = 'A';
41 UPDATE Status SET Severity = 10 where JobStatus = 'T';
42 UPDATE Status SET Severity = 20 where JobStatus = 'e';
43 UPDATE Status SET Severity = 25 where JobStatus = 'E';
46 BEGIN; -- Can already exists if using 3.1.x release
47 CREATE TABLE PathHierarchy
49 PathId integer NOT NULL,
50 PPathId integer NOT NULL,
51 CONSTRAINT pathhierarchy_pkey PRIMARY KEY (PathId)
54 CREATE INDEX pathhierarchy_ppathid
55 ON PathHierarchy (PPathId);
57 CREATE TABLE PathVisibility
59 PathId integer NOT NULL,
60 JobId integer NOT NULL,
63 CONSTRAINT pathvisibility_pkey PRIMARY KEY (JobId, PathId)
66 CREATE INDEX pathvisibility_jobid
67 ON PathVisibility (JobId);
71 CREATE INDEX basefiles_jobid_idx ON BaseFiles ( JobId );
73 -- Remove bad PostgreSQL index
74 DROP INDEX file_fp_idx;
76 -- Create the good one
77 -- If you want to create this index during production, you can use
78 -- CREATE INDEX CONCURRENTLY file_jpf_idx ON File (JobId, PathId, FilenameId)
79 -- to make it without locks (require PostgreSQL 8.2 version)
81 CREATE INDEX file_jpfid_idx on File (JobId, PathId, FilenameId);
85 UPDATE Version SET VersionId=12;
89 echo "Update of Bacula PostgreSQL tables succeeded."
91 echo "Update of Bacula PostgreSQL tables failed."