3 # Shell script to update MySQL Community version 3.0.x to 5.0.x
6 echo "This script will update a Bacula MySQL database from version 11 to 12"
7 echo " which is needed to convert from Bacula Community version 3.0.x to 5.0.x"
13 mysql ${db_name} -e "select VersionId from Version\G" >/tmp/$$
14 DBVERSION=`sed -n -e 's/^VersionId: \(.*\)$/\1/p' /tmp/$$`
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 mysql $* -f <<END-OF-DATA
27 ALTER TABLE JobMedia DROP Stripe ;
28 ALTER TABLE JobMedia DROP Copy ;
29 ALTER TABLE Job ADD COLUMN HasCache tinyint default 0 after HasBase;
30 ALTER TABLE Job ADD COLUMN Reviewed tinyint default 0 after HasCache;
31 ALTER TABLE Job ADD COLUMN Comment BLOB AFTER Reviewed;
32 ALTER TABLE JobHisto ADD COLUMN HasCache tinyint default 0 after HasBase;
33 ALTER TABLE JobHisto ADD COLUMN Reviewed tinyint default 0 after HasCache;
34 ALTER TABLE JobHisto ADD COLUMN Comment BLOB AFTER Reviewed;
36 ALTER TABLE Status ADD COLUMN Severity int;
37 UPDATE Status SET Severity = 15;
38 UPDATE Status SET Severity = 100 where JobStatus = 'f';
39 UPDATE Status SET Severity = 90 where JobStatus = 'A';
40 UPDATE Status SET Severity = 10 where JobStatus = 'T';
41 UPDATE Status SET Severity = 20 where JobStatus = 'e';
42 UPDATE Status SET Severity = 25 where JobStatus = 'E';
44 CREATE TABLE PathHierarchy
46 PathId integer NOT NULL,
47 PPathId integer NOT NULL,
48 CONSTRAINT pathhierarchy_pkey PRIMARY KEY (PathId)
51 CREATE INDEX pathhierarchy_ppathid
52 ON PathHierarchy (PPathId);
54 CREATE TABLE PathVisibility
56 PathId integer NOT NULL,
57 JobId integer NOT NULL,
60 CONSTRAINT pathvisibility_pkey PRIMARY KEY (JobId, PathId)
62 CREATE INDEX pathvisibility_jobid
63 ON PathVisibility (JobId);
65 CREATE INDEX basefiles_jobid_idx ON BaseFiles ( JobId );
68 INSERT INTO Version (VersionId) VALUES (12);
72 echo "Update of Bacula MySQL tables succeeded."
74 echo "Update of Bacula MySQL tables failed."