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/lib64/bacula/${f/postgresql/bacula}
done
# 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/lib64/bacula/create_postgresql_database >> /var/lib/bacula/rpm_db.log 2>&1
echo "Creating bacula tables..."
su - postgres -c /usr/lib64/bacula/make_postgresql_tables >> /var/lib/bacula/rpm_db.log 2>&1
echo "Granting privileges for PostgreSQL user bacula..."
su - postgres -c /usr/lib64/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/lib64/bacula/create_bacula_database" 1>&2
echo " /usr/lib64/bacula/make_bacula_tables" 1>&2
echo " /usr/lib64/bacula/grant_bacula_privileges" 1>&2
echo "else manually update the database to version 14 using the scripts:" 1>&2
echo " /usr/lib64/bacula/update_mysql_tables_X_to_Y" 1>&2
echo "and:" 1>&2
echo " /usr/lib64/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/lib64/bacula/grant_bacula_privileges" 1>&2
echo " /usr/lib64/bacula/create_bacula_database" 1>&2
echo " /usr/lib64/bacula/make_bacula_tables" 1>&2
elif [ "$DB_VER" -lt "14" ]; 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 $(( 14 - 2 ))`; do
su - postgres -c "/usr/lib64/bacula/update_postgresql_tables_${v}_to_$(($v + 1))" >> /var/lib/bacula/rpm_db.log 2>&1
done
su - postgres -c "/usr/lib64/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 "14" ]; then
echo "There was a problem updating Bacula PostgreSQL database from version $DB_VER to 14" 1>&2
echo "see log file /var/lib/bacula/rpm_db.log" 1>&2
echo "manually update the database to version 14 using the scripts:" 1>&2
echo " /usr/lib64/bacula/update_postgresql_tables_X_to_Y" 1>&2
echo "and:" 1>&2
echo " /usr/lib64/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