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