]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/update_postgresql_tables.in
Backport from BEE
[bacula/bacula] / bacula / src / cats / update_postgresql_tables.in
1 #!/bin/sh
2 #
3 # Shell script to update PostgreSQL tables from version 12 to 14
4 #  or Bacula Community version 5.0.x to 5.2.x
5 #
6 #
7 #  Bacula® - The Network Backup Solution
8 #
9 #  Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
10 #
11 #  The main author of Bacula is Kern Sibbald, with contributions from many
12 #  others, a complete list can be found in the file AUTHORS.
13 #
14 #  You may use this file and others of this release according to the
15 #  license defined in the LICENSE file, which includes the Affero General
16 #  Public License, v3.0 ("AGPLv3") and some additional permissions and
17 #  terms pursuant to its AGPLv3 Section 7.
18 #
19 #  Bacula® is a registered trademark of Kern Sibbald.
20 #
21
22 echo " "
23 echo "This script will update a Bacula PostgreSQL database from version 12 to 14"
24 echo "  which is needed to convert from Bacula Community version 5.0.x to 5.2.x"
25 echo " "
26
27 bindir=@POSTGRESQL_BINDIR@
28 PATH="$bindir:$PATH"
29 db_name=@db_name@
30
31 DBVERSION=`psql -d ${db_name} -t --pset format=unaligned -c "select VersionId from Version" $*`
32 if [ $DBVERSION != 12 ] ; then
33    echo " "
34    echo "The existing database is version $DBVERSION !!"
35    echo "This script can only update an existing version 12 database to version 14."
36    echo "Error. Cannot upgrade this database."
37    echo " "
38    exit 1
39 fi
40
41 if psql -f - -d ${db_name} $* <<END-OF-DATA
42 BEGIN; -- Necessary for Bacula core
43 CREATE TABLE RestoreObject (
44    RestoreObjectId SERIAL NOT NULL,
45    ObjectName TEXT NOT NULL,
46    RestoreObject BYTEA NOT NULL,
47    PluginName TEXT NOT NULL,
48    ObjectLength INTEGER DEFAULT 0,
49    ObjectFullLength INTEGER DEFAULT 0,
50    ObjectIndex INTEGER DEFAULT 0,
51    ObjectType INTEGER DEFAULT 0,
52    FileIndex INTEGER DEFAULT 0,
53    JobId INTEGER,
54    ObjectCompression INTEGER DEFAULT 0,
55    PRIMARY KEY(RestoreObjectId)
56    );
57 CREATE INDEX restore_jobid_idx on RestoreObject(JobId);
58
59 ALTER TABLE File ADD COLUMN DeltaSeq smallint default 0;
60
61 UPDATE Version SET VersionId=14;
62 COMMIT;
63
64 set client_min_messages = fatal;
65 CREATE INDEX media_poolid_idx on Media (PoolId);
66
67 ANALYSE;
68
69 END-OF-DATA
70 then
71    echo "Update of Bacula PostgreSQL tables succeeded."
72 else
73    echo "Update of Bacula PostgreSQL tables failed."
74 fi
75 exit 0