Sophie

Sophie

distrib > Mageia > 1 > i586 > by-pkgid > 1c17ebc14d88a3bfe3624565c5e27d9d > scriptlet

bacula-dir-pgsql-5.0.3-2.mga1.i586.rpm

POSTIN

/bin/sh
umask 077
for f in create_postgresql_database drop_postgresql_database drop_postgresql_tables \
    grant_postgresql_privileges make_postgresql_tables update_postgresql_tables ; do
    ln -snf $f /usr/lib/bacula/${f/postgresql/bacula}
done
ln -snf bacula-dir-postgresql /usr/sbin/bacula-dir
ln -snf bscan-postgresql /usr/sbin/bscan
ln -snf dbcheck-postgresql /usr/sbin/dbcheck
# NOTE: IF THIS FAILS DUE TO PSQL NEEDING A PASSWORD YOU ARE ON YOUR OWN
# see /etc/bacula/scripts/make_catalog_backup.pl for an example of how it should be done
DB_VER=`su - postgres -c "psql bacula -A -t -c 'select * from Version;'" 2>/dev/null`
if [ -z "$DB_VER" ]; then
    echo "Hmm, doesn't look like you have an existing database."
    if [ -e /var/lib/bacula/rpm_db.log ]; then
	mv /var/lib/bacula/rpm_db.log /var/lib/bacula/rpm_db.log.old
    fi
    echo "Creating PostgreSQL bacula database..."
    su - postgres -c /usr/lib/bacula/create_postgresql_database >> /var/lib/bacula/rpm_db.log 2>&1
    echo "Creating bacula tables..."
    su - postgres -c /usr/lib/bacula/make_postgresql_tables >> /var/lib/bacula/rpm_db.log 2>&1
    echo "Granting privileges for PostgreSQL user bacula..."
    su - postgres -c /usr/lib/bacula/grant_postgresql_privileges >> /var/lib/bacula/rpm_db.log 2>&1
    su - postgres -c "psql bacula -A -t -c 'select * from Version;'" >/dev/null 2>&1
    if [ $? != 0 ]; then
	echo "automatic database creation failed!" 1>&2
	echo "see log file /var/lib/bacula/rpm_db.log" 1>&2
	echo "if this is the first bacula installation" 1>&2
	echo "please check and run the following scripts:" 1>&2
	echo "	/usr/lib/bacula/create_bacula_database" 1>&2
	echo "	/usr/lib/bacula/make_bacula_tables" 1>&2
	echo "	/usr/lib/bacula/grant_bacula_privileges" 1>&2
	echo "else manually update the database to version 12 using the scripts:" 1>&2
	echo "	/usr/lib/bacula/update_mysql_tables_X_to_Y" 1>&2
	echo "and:" 1>&2
	echo "	/usr/lib/bacula/update_bacula_tables" 1>&2
    fi
elif [ "$DB_VER" -lt "7" ]; then
    echo "ERROR: your bacula database version is too old to be upgraded automatically" 1>&2
    echo "save and drop any existing database" 1>&2
    echo "and recreate it using the following scripts:" 1>&2
    echo "	/usr/lib/bacula/grant_bacula_privileges" 1>&2
    echo "	/usr/lib/bacula/create_bacula_database" 1>&2
    echo "	/usr/lib/bacula/make_bacula_tables" 1>&2
elif [ "$DB_VER" -lt "12" ]; then
    echo "Backing up bacula tables"
    su - postgres -c "pg_dump bacula" | bzip2 > /var/lib/bacula/bacula_backup.sql.bz2
    if [ -e /var/lib/bacula/rpm_db.log ]; then
	mv /var/lib/bacula/rpm_db.log /var/lib/bacula/rpm_db.log.old
    fi
    echo "Upgrading bacula tables"
    for v in `seq $DB_VER $(( 12 - 2 ))`; do
	su - postgres -c "/usr/lib/bacula/update_postgresql_tables_${v}_to_$(($v + 1))" >> /var/lib/bacula/rpm_db.log 2>&1
    done
    su - postgres -c "/usr/lib/bacula/update_bacula_tables" >> /var/lib/bacula/rpm_db.log 2>&1
    NDB_VER=`su - postgres -c "psql bacula -A -t -c 'select * from Version;'" 2>/dev/null`
    if [ "$NDB_VER" -lt "12" ]; then
	echo "There was a problem updating Bacula PostgreSQL database from version $DB_VER to 12" 1>&2
	echo "see log file /var/lib/bacula/rpm_db.log" 1>&2
	echo "manually update the database to version 12 using the scripts:" 1>&2
	echo "	/usr/lib/bacula/update_postgresql_tables_X_to_Y" 1>&2
	echo "and:" 1>&2
	echo "	/usr/lib/bacula/update_bacula_tables" 1>&2
    else
	echo "Bacula PostgreSQL database updated to version $NDB_VER"
	echo "see log file /var/lib/bacula/rpm_db.log"
	echo "If bacula works correctly you can remove the backup file /var/lib/bacula/bacula_backup.sql.bz2"
    fi
fi
chown -R bacula:bacula /var/lib/bacula
chmod -R u+rX,go-rwx /var/lib/bacula
/usr/share/rpm-helper/add-service bacula $1 bacula-dir