850dc181d865b2be6c1eb95470490b25526c2c56
[citadel.git] / citadel / database_cleanup.sh
1 #!/bin/bash
2
3 die () {
4         echo Exiting.
5         exit 1
6 }
7
8
9 # If we're on an Easy Install system, use our own db_ tools.
10 #
11 if [ -x /usr/local/ctdlsupport/bin/db_dump ] ; then
12         export PATH=/usr/local/ctdlsupport/bin:$PATH
13 fi
14
15 # Ok, let's begin.
16 #
17 clear
18 cat <<!
19
20 Citadel Database Cleanup
21 ---------------------------
22
23 This script exports, deletes, and re-imports your database.  If you have
24 any data corruption issues, this program may be able to clean them up for you.
25  
26 Please note that this program does a Berkeley DB dump/load, not a Citadel
27 export.  The export files are not generated by the Citadel export module.
28
29 WARNING #1:
30   MAKE A BACKUP OF YOUR DATA BEFORE ATTEMPTING THIS.  There is no guarantee
31   that this will work!
32
33 WARNING #2:
34   citserver must NOT be running while you do this.
35
36 WARNING #3:
37   Please try "db_recover -c" from the data/ directory first.  Use this tool
38   only if that one fails to fix your problem.
39
40 !
41
42 echo -n "Do you want to continue? "
43
44 read yesno
45 case "$yesno" in
46         "y" | "Y" | "yes" | "YES" | "Yes" )
47                 echo 
48                 echo DO NOT INTERRUPT THIS PROCESS.
49                 echo
50         ;;
51         * )
52                 exit
53 esac
54
55 for x in 00 01 02 03 04 05 06 07 08 09
56 do
57         filename=cdb.$x
58         echo Dumping $filename
59         db_dump -h ./data $filename >/tmp/CitaDump.$x || die
60         rm -f ./data/$filename
61 done
62
63 echo Removing old databases
64 rm -f ./data/*
65
66 for x in 00 01 02 03 04 05 06 07 08 09
67 do
68         filename=cdb.$x
69         echo Loading $filename
70         db_load -h ./data $filename </tmp/CitaDump.$x && {
71                 rm -f /tmp/CitaDump.$x
72         }
73 done
74
75 echo 
76 echo Dump/load operation complete.  Start your Citadel server now.
77 echo