Blame SOURCES/libexec-upgrade-db.sh

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