X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fdatabase_cleanup.sh;h=81b395ec9f686869c3ec9b16bb746cc60bd8dae2;hb=55a6d74dded2e0472732b248fba548f611f2a7aa;hp=850dc181d865b2be6c1eb95470490b25526c2c56;hpb=53d1ee078554ea93d4260a0ee9223cc97b352398;p=citadel.git diff --git a/citadel/database_cleanup.sh b/citadel/database_cleanup.sh index 850dc181d..81b395ec9 100755 --- a/citadel/database_cleanup.sh +++ b/citadel/database_cleanup.sh @@ -5,15 +5,83 @@ die () { exit 1 } +DATA_DIR="/usr/local/citadel" + +usage() { + echo "Usage: database_cleanup.sh [ -h citadel_dir ]" + exit 2 +} + +PARSED_ARGUMENTS=$(getopt -a -n database_cleanup.sh -o h: -- "$@") +VALID_ARGUMENTS=$? +if [ "$VALID_ARGUMENTS" != "0" ]; then + usage +fi + +eval set -- "$PARSED_ARGUMENTS" +while : +do + case "$1" in + -h | --alpha) + DATA_DIR=${2} + shift 2 + ;; + # -- means the end of the arguments; drop this, and break out of the while loop + --) shift; break ;; + # If invalid options were passed, then getopt should have reported an error, + # which we checked as VALID_ARGUMENTS when getopt was called... + *) echo "Unexpected option: $1 - this should not happen." + usage + ;; + esac +done + +DATA_DIR=$DATA_DIR/data + +# If we're on an AppDir system, use the embedded db_tools. +if [ "${APPDIR}" != "" ] ; then + export PATH=${APPDIR}/usr/bin:$PATH + RECOVER=${APPDIR}/usr/bin/db_recover + DUMP=${APPDIR}/usr/bin/db_dump + LOAD=${APPDIR}/usr/bin/db_load # If we're on an Easy Install system, use our own db_ tools. -# -if [ -x /usr/local/ctdlsupport/bin/db_dump ] ; then +elif [ -x /usr/local/ctdlsupport/bin/db_dump ] ; then export PATH=/usr/local/ctdlsupport/bin:$PATH + RECOVER=/usr/local/ctdlsupport/bin/db_recover + DUMP=/usr/local/ctdlsupport/bin/db_dump + LOAD=/usr/local/ctdlsupport/bin/db_load + +# usual install +else + if test -f /usr/bin/db_dump; then + RECOVER=/usr/bin/db_recover + DUMP=/usr/bin/db_dump + LOAD=/usr/bin/db_load + else + if test -n "`ls /usr/bin/db?*recover`"; then + # seems we have something debian alike thats adding version in the filename + if test "`ls /usr/bin/db*recover |wc -l`" -gt "1"; then + echo "Warning: you have more than one version of the Berkeley DB utilities installed." 1>&2 + echo "Using the latest one." 1>&2 + RECOVER=`ls /usr/bin/db*recover |sort |tail -n 1` + DUMP=`ls /usr/bin/db*dump |sort |tail -n 1` + LOAD=`ls /usr/bin/db*load |sort |tail -n 1` + else + RECOVER=`ls /usr/bin/db*recover` + DUMP=`ls /usr/bin/db*dump` + LOAD=`ls /usr/bin/db*load` + fi + else + echo "database_cleanup.sh cannot find the Berkeley DB utilities. Exiting." 1>&2 + die + fi + + fi fi # Ok, let's begin. -# + clear cat </tmp/CitaDump.$x || die - rm -f ./data/$filename + $DUMP -h $DATA_DIR $filename >/tmp/CitaDump.$x || { + echo error $? + die + } + rm -vf $DATA_DIR/$filename done echo Removing old databases -rm -f ./data/* +rm -vf $DATA_DIR/* -for x in 00 01 02 03 04 05 06 07 08 09 +for x in 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d do filename=cdb.$x echo Loading $filename - db_load -h ./data $filename