]> git.sur5r.net Git - bacula/bacula/blob - bacula/updatedb/update_postgresql_tables_11_to_12.in
Tweak license
[bacula/bacula] / bacula / updatedb / update_postgresql_tables_11_to_12.in
1 #!/bin/sh
2 #
3 # Shell script to update PostgreSQL tables from Bacula Community version 3.0.x to 5.0.0
4 #
5 echo " "
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"
8 echo " "
9
10 bindir=@POSTGRESQL_BINDIR@
11 PATH="$bindir:$PATH"
12 db_name=${db_name:-@db_name@}
13
14 DBVERSION=`psql -d ${db_name} -t --pset format=unaligned -c "select VersionId from Version" $*`
15 if [ $DBVERSION != 11 ] ; then
16    echo " "
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."
20    echo " "
21    exit 1
22 fi
23
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;
34 COMMIT;
35
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';
44 COMMIT;
45
46 BEGIN; -- Can already exists if using 3.1.x release
47 CREATE TABLE PathHierarchy
48 (
49      PathId integer NOT NULL,
50      PPathId integer NOT NULL,
51      CONSTRAINT pathhierarchy_pkey PRIMARY KEY (PathId)
52 );
53
54 CREATE INDEX pathhierarchy_ppathid 
55           ON PathHierarchy (PPathId);
56
57 CREATE TABLE PathVisibility
58 (
59       PathId integer NOT NULL,
60       JobId integer NOT NULL,
61       Size int8 DEFAULT 0,
62       Files int4 DEFAULT 0,
63       CONSTRAINT pathvisibility_pkey PRIMARY KEY (JobId, PathId)
64 );
65
66 CREATE INDEX pathvisibility_jobid
67           ON PathVisibility (JobId);
68
69 COMMIT;
70
71 CREATE INDEX basefiles_jobid_idx ON BaseFiles ( JobId );
72
73 -- suppress output for index modification
74 SET client_min_messages TO 'fatal';
75
76 -- Remove bad PostgreSQL index
77 DROP INDEX file_fp_idx;
78
79 -- Create the good one
80 -- If you want to create this index during production, you can use 
81 -- CREATE INDEX CONCURRENTLY file_jpf_idx ON File (JobId, PathId, FilenameId)
82 -- to make it without locks (require PostgreSQL 8.2 version)
83
84 CREATE INDEX file_jpfid_idx on File (JobId, PathId, FilenameId);
85
86 -- restore output
87 SET client_min_messages TO DEFAULT;
88
89 ANALYSE;
90
91 END-OF-DATA
92 then
93    echo "Update of Bacula PostgreSQL tables succeeded."
94 else
95    echo "Update of Bacula PostgreSQL tables failed."
96 fi
97 exit 0