]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/update_postgresql_tables.in
Add new upgrade script from DB vers 12 to 13
[bacula/bacula] / bacula / src / cats / update_postgresql_tables.in
1 #!/bin/sh
2 #
3 # Shell script to update PostgreSQL tables from version 12 to 13
4 #  or Bacula Community version 5.0.x to 5.2.x
5 #
6 echo " "
7 echo "This script will update a Bacula PostgreSQL database from version 12 to 13"
8 echo "  which is needed to convert from Bacula Enterprise version 2.6.x to 4.0.x"
9 echo "  or Bacula Community version 5.0.x to 5.2.x"
10 echo " "
11
12 bindir=@SQL_BINDIR@
13 PATH="$bindir:$PATH"
14 db_name=@db_name@
15
16 DBVERSION=`psql ${db_name} -t --pset format=unaligned -c "select VersionId from Version"`
17 if [ $DBVERSION != 12 ] ; then
18    echo " "
19    echo "The existing database is version $DBVERSION !!"
20    echo "This script can only update an existing version 12 database to version 13."
21    echo "Error. Cannot upgrade this database."
22    echo " "
23    exit 1
24 fi
25
26 if psql -f - -d ${db_name} $* <<END-OF-DATA
27 BEGIN; -- Necessary for Bacula core
28 CREATE TABLE RestoreObject (
29    RestoreObjectId SERIAL NOT NULL,
30    ObjectName TEXT NOT NULL,
31    RestoreObject BYTEA NOT NULL,
32    PluginName TEXT NOT NULL,
33    ObjectLength INTEGER DEFAULT 0,
34    ObjectFullLength INTEGER DEFAULT 0,
35    ObjectIndex INTEGER DEFAULT 0,
36    ObjectType INTEGER DEFAULT 0,
37    FileIndex INTEGER DEFAULT 0,
38    JobId INTEGER,
39    ObjectCompression INTEGER DEFAULT 0,
40    PRIMARY KEY(RestoreObjectId)
41    );
42 CREATE INDEX restore_jobid_idx on RestoreObject(JobId);
43
44 UPDATE Version SET VersionId=13;
45 COMMIT;
46
47 ANALYSE;
48
49 END-OF-DATA
50 then
51    echo "Update of Bacula PostgreSQL tables succeeded."
52 else
53    echo "Update of Bacula PostgreSQL tables failed."
54 fi
55 exit 0