POSTIN
/bin/sh
umask 077
for f in create_mysql_database drop_mysql_database drop_mysql_tables \
grant_mysql_privileges make_mysql_tables update_mysql_tables ; do
ln -snf $f /usr/lib64/bacula/${f/mysql/bacula}
done
ln -snf bacula-dir-mysql /usr/sbin/bacula-dir
ln -snf bscan-mysql /usr/sbin/bscan
ln -snf dbcheck-mysql /usr/sbin/dbcheck
# NOTE: IF THIS FAILS DUE TO MYSQL 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=`mysql bacula -e 'select * from Version;' 2>/dev/null | tail -n 1`
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 MySQL bacula database..."
/usr/lib64/bacula/create_mysql_database >> /var/lib/bacula/rpm_db.log 2>&1
echo "Creating bacula tables..."
/usr/lib64/bacula/make_mysql_tables >> /var/lib/bacula/rpm_db.log 2>&1
echo "Granting privileges for MySQL user bacula..."
/usr/lib64/bacula/grant_mysql_privileges >> /var/lib/bacula/rpm_db.log 2>&1
mysql bacula -e '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 12 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 "4" ]; 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 "12" ]; then
echo "Backing up bacula tables"
mysqldump -f --opt 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
/usr/lib64/bacula/update_mysql_tables_${v}_to_$(($v + 1)) >> /var/lib/bacula/rpm_db.log 2>&1
done
/usr/lib64/bacula/update_bacula_tables >> /var/lib/bacula/rpm_db.log 2>&1
NDB_VER=`mysql bacula -e 'select * from Version;' 2>/dev/null | tail -n 1`
if [ "$NDB_VER" -lt "12" ]; then
echo "There was a problem updating Bacula MySQL 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/lib64/bacula/update_mysql_tables_X_to_Y" 1>&2
echo "and:" 1>&2
echo " /usr/lib64/bacula/update_bacula_tables" 1>&2
else
echo "Bacula MySQL 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