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 # If we're on a Docker or Easy Install system, use our own db_ tools.
42 if [ -x /usr/local/ctdlsupport/bin/db_dump ] ; then
43 export PATH=/usr/local/ctdlsupport/bin:$PATH
44 RECOVER=/usr/local/ctdlsupport/bin/db_recover
45 DUMP=/usr/local/ctdlsupport/bin/db_dump
46 LOAD=/usr/local/ctdlsupport/bin/db_load
50 if test -f /usr/bin/db_dump; then
51 RECOVER=/usr/bin/db_recover
55 if test -n "`ls /usr/bin/db?*recover`"; then
56 # seems we have something debian alike thats adding version in the filename
57 if test "`ls /usr/bin/db*recover |wc -l`" -gt "1"; then
58 echo "Warning: you have more than one version of the Berkeley DB utilities installed." 1>&2
59 echo "Using the latest one." 1>&2
60 RECOVER=`ls /usr/bin/db*recover |sort |tail -n 1`
61 DUMP=`ls /usr/bin/db*dump |sort |tail -n 1`
62 LOAD=`ls /usr/bin/db*load |sort |tail -n 1`
64 RECOVER=`ls /usr/bin/db*recover`
65 DUMP=`ls /usr/bin/db*dump`
66 LOAD=`ls /usr/bin/db*load`
69 echo "database_cleanup.sh cannot find the Berkeley DB utilities. Exiting." 1>&2
81 Citadel Database Cleanup
82 ---------------------------
84 This script exports, deletes, and re-imports your database. If you have
85 any data corruption issues, this program may be able to clean them up for you.
87 Please note that this program does a Berkeley DB dump/load, not a Citadel
88 export. The export files are not generated by the Citadel export module.
91 MAKE A BACKUP OF YOUR DATA BEFORE ATTEMPTING THIS. There is no guarantee
92 that this will work (in case of disk full, power failure, program crash)!
95 citserver must NOT be running while you do this.
98 Please try "cd $DATA_DIR; $RECOVER -c" first. Run citserver afterwards to
99 revalidate whether its fixed or not, No news might be good news. Use this
100 tool only if that one fails to fix your problem.
103 You must have an amount of free space in /tmp that is at least twice
104 the size of your database. see the following output:
108 you will need `du -sh $DATA_DIR|sed "s;/.*;;"` of free space.
112 echo We will attempt to look for a Citadel database in $DATA_DIR
113 echo -n "Do you want to continue? "
117 "y" | "Y" | "yes" | "YES" | "Yes" )
119 echo DO NOT INTERRUPT THIS PROCESS.
126 for x in 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d
129 echo Dumping $filename
130 $DUMP -h $DATA_DIR $filename >/tmp/CitaDump.$x || {
134 rm -vf $DATA_DIR/$filename
137 echo Removing old databases
140 for x in 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d
143 echo Loading $filename
144 $LOAD -h $DATA_DIR $filename </tmp/CitaDump.$x && {
145 rm -f /tmp/CitaDump.$x
150 echo Dump/load operation complete. Start your Citadel server now.