Blame SOURCES/libexec-upgrade-db.sh

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