Blame SOURCES/libexec-upgrade-db.sh

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