* Removed some temporary diagnostics that had been left in serv_sieve.c
[citadel.git] / citadel / database_cleanup.sh.in
blobf7deb835ed4fb4c5054005fd637d37715471768e
1 #!/bin/bash
3 die () {
4 echo Exiting.
5 exit 1
8 # data dir from autoconf?
9 DATA_DIR="@MAKE_DATA_DIR@"
10 if test -z "$DATA_DIR" ; then
11 DATA_DIR="/usr/local/citadel"
13 DATA_DIR=$DATA_DIR/data
15 # If we're on an Easy Install system, use our own db_ tools.
17 if [ -x /usr/local/ctdlsupport/bin/db_dump ] ; then
18 export PATH=/usr/local/ctdlsupport/bin:$PATH
19 RECOVER=/usr/local/ctdlsupport/bin/db_recover
20 DUMP=/usr/local/ctdlsupport/bin/db_dump
21 LOAD=/usr/local/ctdlsupport/bin/db_load
23 else
24 # ok usual install?
25 if test -f /usr/bin/db_dump; then
26 RECOVER=/usr/bin/db_recover
27 DUMP=/usr/bin/db_dump
28 LOAD=/usr/bin/db_load
29 else
30 if test -n "`ls /usr/bin/db?*recover`"; then
31 # seems we have something debian alike thats adding version in the filename
32 if test "`ls /usr/bin/db*recover |wc -l`" -gt "1"; then
33 echo "Warning: you have more than one version of the Berkeley DB utilities installed." 1>&2
34 echo "Using the latest one." 1>&2
35 RECOVER=`ls /usr/bin/db*recover |sort |tail -n 1`
36 DUMP=`ls /usr/bin/db*dump |sort |tail -n 1`
37 LOAD=`ls /usr/bin/db*load |sort |tail -n 1`
38 else
39 RECOVER=`ls /usr/bin/db*recover`
40 DUMP=`ls /usr/bin/db*dump`
41 LOAD=`ls /usr/bin/db*load`
43 else
44 echo "database_cleanup.sh cannot find the Berkeley DB utilities. Exiting." 1>&2
45 die
51 # Ok, let's begin.
54 clear
55 cat <<!
57 Citadel Database Cleanup
58 ---------------------------
60 This script exports, deletes, and re-imports your database. If you have
61 any data corruption issues, this program may be able to clean them up for you.
63 Please note that this program does a Berkeley DB dump/load, not a Citadel
64 export. The export files are not generated by the Citadel export module.
66 WARNING #1:
67 MAKE A BACKUP OF YOUR DATA BEFORE ATTEMPTING THIS. There is no guarantee
68 that this will work (in case of disk full, power failure, program crash)!
70 WARNING #2:
71 citserver must NOT be running while you do this.
73 WARNING #3:
74 Please try "cd $DATA_DIR; $RECOVER -c" first. Use this tool
75 only if that one fails to fix your problem.
77 WARNING #4:
78 You must have an amount of free space on your disk that is at least twice
79 the size of your database, see the following output:
80 (for substantially better performance you should specify a location that is
81 on another disk than $DATA_DIR)
83 `df -h`
85 you will need `du -sh $DATA_DIR|sed "s;/.*;;"` of free space.
89 echo -n "Do you want to continue? "
91 read yesno
92 case "$yesno" in
93 "y" | "Y" | "yes" | "YES" | "Yes" )
94 echo
95 echo DO NOT INTERRUPT THIS PROCESS.
96 echo
98 * )
99 exit
100 esac
102 for x in 00 01 02 03 04 05 06 07 08 09 0a 0b 0c
104 filename=cdb.$x
105 echo Dumping $filename
106 $DUMP -h $DATA_DIR $filename >/tmp/CitaDump.$x || die
107 rm -f $DATA_DIR/$filename
108 done
110 echo Removing old databases
111 rm -f ./data/*
113 for x in 00 01 02 03 04 05 06 07 08 09 0a 0b 0c
115 filename=cdb.$x
116 echo Loading $filename
117 $LOAD -h $DATA_DIR $filename </tmp/CitaDump.$x && {
118 rm -f /tmp/CitaDump.$x
120 done
122 echo
123 echo Dump/load operation complete. Start your Citadel server now.
124 echo