#!/bin/sh # # Copyright (C) 2000-2020 Kern Sibbald # License: BSD 2-Clause; see file LICENSE-FOSS # echo " " echo "This script will update a Bacula PostgreSQL database" echo " from any from version 12-16 or 1014-1021 to version 1022" echo " which is needed to convert from any Bacula Enterprise" echo " version 4.0.x, 6.x.y, 8.x.y, 10.x.y to version 12.4.x" echo " " bindir=@POSTGRESQL_BINDIR@ PATH="$bindir:$PATH" db_name=@db_name@ # Special trick to not do the upgrade from 1015 to 1016 with this script if [ "$1" = "--stop1015" ]; then STOP1015=yes shift # remove this option from $* fi # Special trick to not do the upgrade from 1016 to 1017 with this script if [ "$1" = "--stop1016" ]; then STOP1016=yes shift # remove this option from $* fi ARGS=$* getVersion() { DBVERSION=`psql -d ${db_name} -t --pset format=unaligned -c "select VersionId from Version LIMIT 1" $ARGS` } getVersion if [ "x$DBVERSION" = x ]; then echo " " echo "Unable to detect database version, you can specify connection information" echo "on the command line." echo "Error. Cannot update this database." echo " " exit 1 fi if [ "$DBVERSION" -lt 1014 -o "$DBVERSION" -gt 1021 ] ; then if [ "$DBVERSION" -lt 12 -o "$DBVERSION" -gt 16 ] ; then echo " " echo "The existing database is version $DBVERSION !!" echo "This script can only update an existing version 12-16, 1014-1021 database to version 1022." echo "Error. Cannot update this database." echo " " exit 1 fi fi if [ "$DBVERSION" -eq 12 ] ; then # from 5.0 if psql -f - -d ${db_name} $* < file1017.data if [ $? -ne 0 ]; then echo "Error while dumping file table to $PWD/file1017.data" exit 1 fi if ! psql --set ON_ERROR_STOP=1 -f - -d ${db_name} $* < file1016.data if [ $? -ne 0 ]; then echo "Error while dumping file table to $PWD/file1016.data" exit 1 fi if ! psql --set ON_ERROR_STOP=1 -f - -d ${db_name} $* </dev/null 2>/dev/null set client_min_messages = fatal; CREATE INDEX media_poolid_idx on Media (PoolId); CREATE INDEX media_storageid_idx ON Media (StorageId); END-OF-DATA exit 0