Blame SOURCES/libexec-upgrade-db.sh

adf540
#!/bin/sh
adf540
# Author: Jan Vcelak <jvcelak@redhat.com>
adf540
adf540
. /usr/libexec/openldap/functions
adf540
adf540
if [ `id -u` -ne 0 ]; then
adf540
	error "You have to be root to run this command."
adf540
	exit 4
adf540
fi
adf540
adf540
load_sysconfig
adf540
retcode=0
adf540
adf540
for dbdir in `databases`; do
adf540
	upgrade_log="$dbdir/db_upgrade.`date +%Y%m%d%H%M%S`.log"
adf540
	bdb_files=`find "$dbdir" -maxdepth 1 -name "*.bdb" -printf '"%f" '`
adf540
adf540
	# skip uninitialized database
adf540
	[ -z "$bdb_files"]  || continue
adf540
adf540
	printf "Updating '%s', logging into '%s'\n" "$dbdir" "$upgrade_log"
adf540
adf540
	# perform the update
adf540
	for command in \
adf540
		"/usr/bin/db_recover -v -h \"$dbdir\"" \
adf540
		"/usr/bin/db_upgrade -v -h \"$dbdir\" $bdb_files" \
adf540
		"/usr/bin/db_checkpoint -v -h \"$dbdir\" -1" \
adf540
	; do
adf540
		printf "Executing: %s\n" "$command" &>>$upgrade_log
adf540
		run_as_ldap "$command" &>>$upgrade_log
adf540
		result=$?
adf540
		printf "Exit code: %d\n" $result >>"$upgrade_log"
adf540
		if [ $result -ne 0 ]; then
adf540
			printf "Upgrade failed: %d\n" $result
adf540
			retcode=1
adf540
		fi
adf540
	done
adf540
done
adf540
adf540
exit $retcode