]> git.sur5r.net Git - bacula/bacula/blob - bacula/updatedb/update_postgresql_tables_11_to_12.in
Try to fix bug #2349 multiple recycle messages
[bacula/bacula] / bacula / updatedb / update_postgresql_tables_11_to_12.in
1 #!/bin/sh
2 #
3 # Copyright (C) 2000-2015 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
5 #
6 # Shell script to update PostgreSQL tables from Bacula Community version 3.0.x to 5.0.0
7 #
8 echo " "
9 echo "This script will update a Bacula PostgreSQL database from version 11 to 12"
10 echo "  which is needed to convert from Bacula Community version 3.0.x to 5.0.x"
11 echo " "
12
13 bindir=@POSTGRESQL_BINDIR@
14 PATH="$bindir:$PATH"
15 db_name=${db_name:-@db_name@}
16
17 DBVERSION=`psql -d ${db_name} -t --pset format=unaligned -c "select VersionId from Version" $*`
18 if [ $DBVERSION != 11 ] ; then
19    echo " "
20    echo "The existing database is version $DBVERSION !!"
21    echo "This script can only update an existing version 11 database to version 12."
22    echo "Error. Cannot upgrade this database."
23    echo " "
24    exit 1
25 fi
26
27 if psql -f - -d ${db_name} $* <<END-OF-DATA
28 BEGIN; -- Necessary for Bacula core
29 ALTER TABLE JobMedia DROP Copy ;
30 ALTER TABLE Job ADD COLUMN HasCache smallint default 0;
31 ALTER TABLE Job ADD COLUMN Reviewed smallint default 0;
32 ALTER TABLE Job ADD COLUMN Comment text;
33 ALTER TABLE JobHisto ADD COLUMN HasCache smallint default 0;
34 ALTER TABLE JobHisto ADD COLUMN Reviewed smallint default 0;
35 ALTER TABLE JobHisto ADD COLUMN Comment text;
36 UPDATE Version SET VersionId=12;
37 COMMIT;
38
39 BEGIN; -- Can conflict with previous Bweb installation
40 ALTER TABLE Status ADD COLUMN Severity int;
41 UPDATE Status SET Severity = 15;
42 UPDATE Status SET Severity = 100 where JobStatus = 'f';
43 UPDATE Status SET Severity = 90 where JobStatus = 'A';
44 UPDATE Status SET Severity = 10 where JobStatus = 'T';
45 UPDATE Status SET Severity = 20 where JobStatus = 'e';
46 UPDATE Status SET Severity = 25 where JobStatus = 'E';
47 COMMIT;
48
49 BEGIN; -- Can already exists if using 3.1.x release
50 CREATE TABLE PathHierarchy
51 (
52      PathId integer NOT NULL,
53      PPathId integer NOT NULL,
54      CONSTRAINT pathhierarchy_pkey PRIMARY KEY (PathId)
55 );
56
57 CREATE INDEX pathhierarchy_ppathid 
58           ON PathHierarchy (PPathId);
59
60 CREATE TABLE PathVisibility
61 (
62       PathId integer NOT NULL,
63       JobId integer NOT NULL,
64       Size int8 DEFAULT 0,
65       Files int4 DEFAULT 0,
66       CONSTRAINT pathvisibility_pkey PRIMARY KEY (JobId, PathId)
67 );
68
69 CREATE INDEX pathvisibility_jobid
70           ON PathVisibility (JobId);
71
72 COMMIT;
73
74 CREATE INDEX basefiles_jobid_idx ON BaseFiles ( JobId );
75
76 -- suppress output for index modification
77 SET client_min_messages TO 'fatal';
78
79 -- Remove bad PostgreSQL index
80 DROP INDEX file_fp_idx;
81
82 -- Create the good one
83 -- If you want to create this index during production, you can use 
84 -- CREATE INDEX CONCURRENTLY file_jpf_idx ON File (JobId, PathId, FilenameId)
85 -- to make it without locks (require PostgreSQL 8.2 version)
86
87 CREATE INDEX file_jpfid_idx on File (JobId, PathId, FilenameId);
88
89 -- restore output
90 SET client_min_messages TO DEFAULT;
91
92 ANALYSE;
93
94 END-OF-DATA
95 then
96    echo "Update of Bacula PostgreSQL tables succeeded."
97 else
98    echo "Update of Bacula PostgreSQL tables failed."
99 fi
100 exit 0