8 DATA_DIR="/usr/local/citadel"
11 echo "Usage: database_cleanup.sh [ -h citadel_dir ]"
15 PARSED_ARGUMENTS=$(getopt -a -n database_cleanup.sh -o h: -- "$@")
17 if [ "$VALID_ARGUMENTS" != "0" ]; then
21 eval set -- "$PARSED_ARGUMENTS"
29 # -- means the end of the arguments; drop this, and break out of the while loop
31 # If invalid options were passed, then getopt should have reported an error,
32 # which we checked as VALID_ARGUMENTS when getopt was called...
33 *) echo "Unexpected option: $1 - this should not happen."
39 DATA_DIR=$DATA_DIR/data
41 # Find our Berkeley DB utilities.
43 for d in /usr/local/ctdlsupport/bin /usr/local/bin /usr/bin
45 if [ -x ${d}/db_dump ] ; then
46 echo -n "Found Berkeley DB tools in ${d}: "
52 RECOVER=${TOOLSBIN}/db_recover
53 DUMP=${TOOLSBIN}/db_dump
54 LOAD=${TOOLSBIN}/db_load
55 ls ${RECOVER} ${DUMP} ${LOAD} || {
56 echo "database_cleanup.sh cannot find the Berkeley DB utilities. Exiting." 1>&2
64 Citadel Database Cleanup
65 ---------------------------
67 This script exports, deletes, and re-imports your database. If you have
68 any data corruption issues, this program may be able to clean them up for you.
70 Please note that this program does a Berkeley DB dump/load, not a Citadel
71 export. The export files are not generated by the Citadel export module.
74 MAKE A BACKUP OF YOUR DATA BEFORE ATTEMPTING THIS. There is no guarantee
75 that this will work (in case of disk full, power failure, program crash)!
78 citserver must NOT be running while you do this.
81 Please try "cd $DATA_DIR; $RECOVER -c" first. Run citserver afterwards to
82 revalidate whether its fixed or not, No news might be good news. Use this
83 tool only if that one fails to fix your problem.
86 You must have an amount of free space in /tmp that is at least twice
87 the size of your database. see the following output:
91 you will need `du -sh $DATA_DIR|sed "s;/.*;;"` of free space.
95 echo We will attempt to look for a Citadel database in $DATA_DIR
96 echo -n "Do you want to continue? "
100 "y" | "Y" | "yes" | "YES" | "Yes" )
102 echo DO NOT INTERRUPT THIS PROCESS.
109 for x in 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d
112 echo Dumping $filename
113 $DUMP -h $DATA_DIR $filename >/tmp/CitaDump.$x || {
117 rm -vf $DATA_DIR/$filename
120 echo Removing old databases
123 for x in 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d
126 echo Loading $filename
127 $LOAD -h $DATA_DIR $filename </tmp/CitaDump.$x && {
128 rm -f /tmp/CitaDump.$x
133 echo Dump/load operation complete. Start your Citadel server now.