3 # This script is intended to be used to mirror two gforge
4 # installations both based on the debian packages available
5 # at gforge.grazian.org
7 # The purpose of this script is to have a hot-standby gforge
8 # server ready to go if something bad happens to the primary
11 # NOTE WELL: You need to alter your /etc/php4/apache2/php.ini
13 # -pgsql.auto_reset_persistent = Off
14 # +pgsql.auto_reset_persistent = On
15 # to avoid getting errors when you try to use the mirror.
16 # Author: David Partain
18 # SRCSERVER is the server you want to replicate from
19 # DSTSERVER is the server to which you are replicating
20 SRCSERVER=the.machine.you.want.to.mirror # e.g., gforge.company.com
21 DSTSERVER=the.mirror.machine # e.g., gforge2.company.com
22 export SRCSERVER DSTSERVER
24 # Some global flags... Customize as you wish
25 DO_DB=1 # sync DB. turn off with -d
26 DO_MAILMAN=1 # sync mailman. turn off with -m
27 DO_SVN=1 # sync subversion. turn off with -s
28 DO_CUSTOM=1 # sync custom stuff. turn off with -z
29 # USE_SSH_ADD=0 # if you want to try to do things password-less (not there yet)
30 VERBOSE=0 # this set to 1 if you use -v, prints a bit to stdout
31 SEND_MAIL=1 # if you want a report sent. Set next value
32 REPORTEE=gforge-admin@invalid.email.address # your email address
34 export DO_DB DO_MAILMAN DO_SVN DO_CUSTOM USE_SSH_ADD VERBOSE SEND_MAIL REPORTEE
36 LOGFILE=/tmp/gforge-mirror-log.$$.$RANDOM
37 GFORGEDIR=/var/lib/gforge
38 RSYNC_CMD='rsync -avz --delete -e ssh' # I find --progress annoying
41 DATE=`date +%F-%H-%M-%S`
42 DBDUMPFILE=/root/gforgedump.$RANDOM.$DATE
43 MAILMANDIR=/var/lib/mailman
44 export LOGFILE GFORGEDIR RSYNC_CMD RSYNC_RSH DBNAME MAILMANDIR DBDUMPFILE
46 ################################################################
50 usage: `basename $0` [-v] [-h]
51 -v : print some information to stdout
52 -l : do not send mail report
53 -d : sync the database
54 -s : do not sync subversion
55 -m : do not sync mailman
56 -z : do not sync local files
57 -r emailaddress : send mail report to this email address
58 -h : prints this usage information
74 echo "Huh? $LOGFILE exists? Now I am really confused."
78 while [ $# -gt 0 ]; do
81 -v) shift; VERBOSE=1;;
82 -l) shift; SEND_MAIL=0;;
85 -z) shift; DO_CUSTOM=0;;
86 -m) shift; DO_MAILMAN=0;;
91 log "Sending mail to $REPORTEE"
101 ################################################################
102 # Careful where you run this...
103 if [ `hostname --fqdn` != $DSTSERVER ]
105 echo "Do not run this on `hostname --fqdn`!"
106 echo "Only run this script on $DSTSERVER!"
110 # You _really_ want all of this to happen without passwords. Get
111 # things set up for doing rsync over ssh without passwords, but
112 # that's beyond the scope of this script.
113 # Maybe something like this?
114 # don't really think this will work...
115 # if [ $USE_SSH_ADD == 1 ]
117 # exec ssh-agent /bin/bash
121 log "gforge mirror sync run on"
124 ################################################################
125 # gforge database stuff
126 # Note: user sessions are deleted from the database.
129 log "################################################################"
130 log "Replicating gforge database"
132 ssh root@$SRCSERVER "su -s /bin/sh $DBNAME -c \"/usr/lib/postgresql/bin/pg_dump $DBNAME\"" > $DBDUMPFILE
133 log "Backup of original db dump kept in $DBDUMPFILE.orig"
134 [ -f $DBDUMPFILE ] && /bin/cp $DBDUMPFILE $DBDUMPFILE.orig
135 [ -f $DBDUMPFILE ] && log "Adjusting $DBDUMPFILE" && perl -pi -e "s/connect - sourceforge/connect - gforge/" $DBDUMPFILE
136 [ -f $DBDUMPFILE ] && log "Adjusting database for new site" && perl -pi -e "s/$SRCSERVER/$DSTSERVER/" $DBDUMPFILE
137 log "running /usr/lib/gforge/bin/install-db.sh restore $DBDUMPFILE"
138 /usr/lib/gforge/bin/install-db.sh restore $DBDUMPFILE >>$LOGFILE 2>&1
139 log "su -s /bin/sh gforge -c /usr/lib/gforge/bin/db-upgrade.pl"
140 su -s /bin/sh gforge -c /usr/lib/gforge/bin/db-upgrade.pl >>$LOGFILE 2>&1
141 log "Removing user sessions from database"
142 su -s /bin/sh - $DBNAME psql $DBNAME >> $LOGFILE 2>&1 <<-END
143 delete from user_session ;
147 ################################################################
148 # gforge-specific directories
149 log "################################################################"
150 log "Replicating gforge-specific directories"
152 log "rsync'ing $GFORGEDIR/download"
153 $RSYNC_CMD root@$SRCSERVER:$GFORGEDIR/download $GFORGEDIR/ >>$LOGFILE 2>&1
154 log "rsync'ing $GFORGEDIR/ftp"
155 $RSYNC_CMD root@$SRCSERVER:$GFORGEDIR/ftp $GFORGEDIR/ >>$LOGFILE 2>&1
156 log "rsync'ing $GFORGEDIR/tmp"
157 $RSYNC_CMD root@$SRCSERVER:$GFORGEDIR/tmp $GFORGEDIR/ >>$LOGFILE 2>&1
158 log "rsync'ing $GFORGEDIR/scmtarballs"
159 $RSYNC_CMD root@$SRCSERVER:$GFORGEDIR/scmtarballs $GFORGEDIR/ >>$LOGFILE 2>&1
160 log "rsync'ing $GFORGEDIR/scmsnapshots"
161 $RSYNC_CMD root@$SRCSERVER:$GFORGEDIR/scmsnapshots $GFORGEDIR/ >>$LOGFILE 2>&1
162 log "rsync'ing $GFORGEDIR/chroot/home"
163 $RSYNC_CMD root@$SRCSERVER:$GFORGEDIR/chroot/home $GFORGEDIR/chroot/ >>$LOGFILE 2>&1
164 log "rsync'ing $GFORGEDIR/chroot/cvsroot"
165 $RSYNC_CMD root@$SRCSERVER:$GFORGEDIR/chroot/cvsroot $GFORGEDIR/chroot/ >>$LOGFILE 2>&1
166 log "rsync'ing /var/log/gforge/"
167 $RSYNC_CMD root@$SRCSERVER:/var/log/gforge/ /var/log/gforge/ >>$LOGFILE 2>&1
169 ################################################################
170 # Mailman replication
171 if [ $DO_MAILMAN == 1 ]
173 log "################################################################"
174 log "Replicating mailman directories"
175 log "rsync'ing $MAILMANDIR/archives/"
176 $RSYNC_CMD root@$SRCSERVER:$MAILMANDIR/archives/ $MAILMANDIR/archives/ >>$LOGFILE 2>&1
177 log "rsync'ing $MAILMANDIR/data/"
178 $RSYNC_CMD root@$SRCSERVER:$MAILMANDIR/data/ $MAILMANDIR/data/ >>$LOGFILE 2>&1
179 log "rsync'ing $MAILMANDIR/lists/"
180 $RSYNC_CMD root@$SRCSERVER:$MAILMANDIR/lists/ $MAILMANDIR/lists/ >>$LOGFILE 2>&1
181 # Don't know if I should do this or not....
182 # log "rsync'ing $MAILMANDIR/qfiles/"
183 # $RSYNC_CMD root@$SRCSERVER:$MAILMANDIR/qfiles/ $MAILMANDIR/qfiles/ >>$LOGFILE 2>&1
186 ################################################################
187 # Subversion - we don't want the transactions directory, which are
188 # commits that are currently underway. This seems relatively safe.
189 # See http://web.mit.edu/ghudson/info/fsfs for some relevant info.
192 log "################################################################"
193 log "Replicating subversion directories"
194 log "rsync'ing $GFORGEDIR/chroot/svnroot/"
195 $RSYNC_CMD --exclude=transactions root@$SRCSERVER:$GFORGEDIR/chroot/svnroot/ $GFORGEDIR/chroot/svnroot/ >>$LOGFILE 2>&1
198 ################################################################
199 # Local files - If you have customized things on the source
200 # gforge that you need to sync, put them here
201 if [ $DO_CUSTOM == 1 ]
203 log "################################################################"
204 log "Replicating local customized directories"
205 log "rsync'ing /usr/share/gforge/www/tools/"
206 $RSYNC_CMD root@$SRCSERVER:/usr/share/gforge/www/tools/ /usr/share/gforge/www/tools/ >>$LOGFILE 2>&1
207 log "rsync'ing /usr/share/gforge/www/static/"
208 $RSYNC_CMD root@$SRCSERVER:/usr/share/gforge/www/static/ /usr/share/gforge/www/static/ >>$LOGFILE 2>&1
211 ################################################################
212 if [ $SEND_MAIL == 1 ]
214 if [ -n "$REPORTEE" ]
216 /usr/bin/Mail -s "gforge mirror log" $REPORTEE < $LOGFILE
219 echo "Cannot send report - set REPORTEE in script"
220 echo "Delete $LOGFILE manually"
223 echo "Log of this mirroring run is in $LOGFILE"