]> git.sur5r.net Git - bacula/bacula/blob - bacula/updatedb/update_postgresql_tables_12_to_14.in
baculum: Tweak trim whitespaces from joblog
[bacula/bacula] / bacula / updatedb / update_postgresql_tables_12_to_14.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 Community version 5.0.x to 5.2.x"
9 echo " "
10
11 bindir=@POSTGRESQL_BINDIR@
12 PATH="$bindir:$PATH"
13 db_name=@db_name@
14
15 DBVERSION=`psql -d ${db_name} -t --pset format=unaligned -c "select VersionId from Version" $*`
16 if [ $DBVERSION != 12 ] ; then
17    echo " "
18    echo "The existing database is version $DBVERSION !!"
19    echo "This script can only update an existing version 12 database to version 14."
20    echo "Error. Cannot upgrade this database."
21    echo " "
22    exit 1
23 fi
24
25 if psql -f - -d ${db_name} $* <<END-OF-DATA
26 BEGIN; -- Necessary for Bacula core
27 CREATE TABLE RestoreObject (
28    RestoreObjectId SERIAL NOT NULL,
29    ObjectName TEXT NOT NULL,
30    RestoreObject BYTEA NOT NULL,
31    PluginName TEXT NOT NULL,
32    ObjectLength INTEGER DEFAULT 0,
33    ObjectFullLength INTEGER DEFAULT 0,
34    ObjectIndex INTEGER DEFAULT 0,
35    ObjectType INTEGER DEFAULT 0,
36    FileIndex INTEGER DEFAULT 0,
37    JobId INTEGER,
38    ObjectCompression INTEGER DEFAULT 0,
39    PRIMARY KEY(RestoreObjectId)
40    );
41 CREATE INDEX restore_jobid_idx on RestoreObject(JobId);
42
43 ALTER TABLE File ADD COLUMN DeltaSeq smallint default 0;
44
45 UPDATE Version SET VersionId=14;
46 COMMIT;
47
48 ANALYSE;
49
50 END-OF-DATA
51 then
52    echo "Update of Bacula PostgreSQL tables succeeded."
53 else
54    echo "Update of Bacula PostgreSQL tables failed."
55 fi
56 exit 0