Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > b9c1a16a341479843a8db13300d7f9f8 > scriptlet

bacula-dir-pgsql-3.0.3-2mdv2010.0.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 MYSQL/PGSQL NEEDING A PASSWORD YOU ARE ON YOUR OWN
DB_VER=`psql bacula -c 'select * from Version;' | tail -n 1 2>/dev/null`
if [ -z "$DB_VER" ]; then
        echo "Hmm, doesn't look like you have an existing database."
        echo "Creating PostgreSQL bacula database..."
	su - postgres -c /usr/lib/bacula/create_postgresql_database
        echo "Creating bacula tables..."
	su - postgres -c /usr/lib/bacula/make_postgresql_tables
        echo "Granting privileges for PostgreSQL user bacula..."
	su - postgres -c /usr/lib/bacula/grant_postgresql_privileges
	echo if any of the above scripts failed, and is the first bacula installation
	echo please check and run the following scripts
	echo 	/usr/lib/bacula/create_bacula_database
	echo 	/usr/lib/bacula/make_bacula_tables
	echo 	/usr/lib/bacula/grant_bacula_privileges
	echo else manually update the database to version 11 using the script
	echo 	/usr/lib/bacula/update_bacula_tables
elif [ "$DB_VER" -lt "11" ]; then
	echo "Backing up bacula tables"
	pg_dump bacula | bzip2 > /var/lib/bacula/bacula_backup.sql.bz2
	echo "Upgrading bacula tables"
	if [ "$DB_VER" -lt "7" ]; then
		echo "your bacula database version is too old to be upgraded automatically"
	else
	    for v in `seq 8 $((11 - 1))`; do
		if [ "$DB_VER" -lt "$v" ]; then
			/usr/lib/bacula/update_postgresql_tables_$((v - 1))_to_$v
		fi
	    done
	fi
	/usr/lib/bacula/update_bacula_tables

	echo "If bacula works correctly you can remove the backup file /var/lib/bacula/bacula_backup.sql.bz2"
fi
chown -R bacula:bacula /var/lib/bacula
chmod -R u+rX,go-rwx /var/lib/bacula