]> git.sur5r.net Git - bacula/bacula/blob - bacula/updatedb/update_postgresql_tables_12_to_13.in
Backport from Bacula Enterprise
[bacula/bacula] / bacula / updatedb / update_postgresql_tables_12_to_13.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
7 #
8 echo " "
9 echo "This script will update a Bacula PostgreSQL database from version 12 to 13"
10 echo "  which is needed to convert from Bacula"
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 != 12 ] ; then
19    echo " "
20    echo "The existing database is version $DBVERSION !!"
21    echo "This script can only update an existing version 12 database to version 13."
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 CREATE TABLE RestoreObject (
30    RestoreObjectId SERIAL NOT NULL,
31    ObjectName TEXT NOT NULL,
32    RestoreObject BYTEA NOT NULL,
33    PluginName TEXT NOT NULL,
34    ObjectLength INTEGER DEFAULT 0,
35    ObjectFullLength INTEGER DEFAULT 0,
36    ObjectIndex INTEGER DEFAULT 0,
37    ObjectType INTEGER DEFAULT 0,
38    FileIndex INTEGER DEFAULT 0,
39    JobId INTEGER,
40    ObjectCompression INTEGER DEFAULT 0,
41    PRIMARY KEY(RestoreObjectId)
42    );
43
44 CREATE INDEX restore_jobid_idx on RestoreObject(JobId);
45 UPDATE Version SET VersionId=13;
46 COMMIT;
47 END-OF-DATA
48 then
49    echo "Update of Bacula PostgreSQL tables succeeded."
50 else
51    echo "Update of Bacula PostgreSQL tables failed."
52 fi
53 exit 0