]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/update_postgresql_tables.in
Fix typo in db upgrade scripts
[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 echo " "
7 echo "This script will update a Bacula PostgreSQL database from version 12 to 14"
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=@POSTGRESQL_BINDIR@
13 PATH="$bindir:$PATH"
14 db_name=@db_name@
15
16 DBVERSION=`psql -d ${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 14."
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 ALTER TABLE File ADD COLUMN DeltaSeq smallint default 0;
45
46 UPDATE Version SET VersionId=14;
47 COMMIT;
48
49 ANALYSE;
50
51 END-OF-DATA
52 then
53    echo "Update of Bacula PostgreSQL tables succeeded."
54 else
55    echo "Update of Bacula PostgreSQL tables failed."
56 fi
57 exit 0