Blame SOURCES/libexec-upgrade-db.sh

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