On 29.01.2009 18:29 Uhr, Mike Hobbs wrote:
Hello,
Hi Mike,
I'm upgrading my mail server from UW to Dovecot and I'd like to convert
from mbox to maildir. I've successfully convert myself and a few other
users with the mb2md script. All is well.
My question is, I have somewhere around 500 users and about 122gb of
mail folders to convert (this does not include the inbox at /var/mail).
mb2md needs to be run as each user to convert. Are there any programs or
scripts out there that will allow me to convert everyone at the same time?
I have created such a script which does a few checks before as well.
We didn't do a 'real' batch conversion, because nothing was in a defined
state at the time of the conversion. We did do it in batches of 10 users
per hour and everyone got an email before, telling them in which
timeframe the migration of their account will take place.
A big help for the migration was perdition (imap proxy) so no
reconfiguration of the client was needed.
I know there is a Dovecot plugin to convert mail, but we didn't want to
use this option.
I'm sure someone on this list was in the same situation as me, how did
you handle a massive conversion?
The attached script does a lot of other things as well, maybe just
reading it will give you an idea of what to expect.
Any help or suggestions is much appreciated!
cheers,
dirk
#!/bin/bash
# m2f - mail to fiction Dirk Essl <d...@essl.de>
PROGNAME=`basename $0`
VERSION=0.5
MUSER=$1
# don't convert the root mailbox and exit if $1 is empty
if [ $1 = root ]; then
echo "you try to convert root (stupid)"
exit 1
fi
# MFROM : Server from which will be migrated from
MFROM=mercury
# MFROMDIR : Directory holding the actual INBOX file (with trailing slash)
MFROMDIR=/net/mercury/var/mail/
# MFROMH : Directory holding the actual mbox format mailboxes
MFROMH=/home/$MUSER/MailImap
# MTO : Server beeing migrated to
MTO=fiction
# MTODIR : Directory holding the new maildirectory (with trailing slash)
MTODIR=/var/maildir/
# POPMAPS : Server holding the NIS map for the perdition Imap Proxy
#POPMAPS=poisson
POPMAPS=tweezers
# POPMAP : filename of the NIS map.
POPMAP=/etc/yp/mailserver
################################################################################
# Don't change anything below here
# create lockfile while compiling the nis map and locking the users mailbox
if [ -f /root/m2f.lock ]; then
echo -e "\033[1;33m##############################################"
echo -e "\033[7;5;1;33m# # # # # # # E R R O R # # # # # # # #
#\\033[0m"
echo -e "\033[1;33man instance of m2f is running"
echo -e "\033[1;33mplease wait until the NIS map is compiled"
echo -e "\033[1;33mif you yhink this is an error, remove the file
m2f.lock"
echo -e "\033[1;33m##############################################"
exit 1
fi
id $MUSER
errlv=$?
if [ $errlv != "0" ]; then
echo -e "\033[7;5;1;33muser $MUSER is not in ESO domain\\033[0m"
exit 1
fi
# check if user is currently hosted in kila or sc6
KILA=`ssh r...@mercury grep $MUSER /etc/mail/mailusers.kila`
if [ "X$KILA" != "X" ]; then
echo "$MUSER is active in kila!"
exit 1
fi
SC6=`ssh r...@mercury grep $MUSER /etc/mail/mailusers.sc6`
if [ "X$KILA" != "X" ]; then
echo "$MUSER is active in sc6!"
exit 1
fi
# check if user has sbd files by grep .mailboxlist
NO_SBD=`su - $MUSER -c 'cat ~/.mailboxlist' | egrep '\.sbd$|\.sbd/'| wc -l`
echo -e $NO_SBD "sbd-files inside .mailboxlist"
if [ $NO_SBD != "0" ]; then
echo -e "\033[1;33m##############################################"
echo -e "\033[7;5;1;33m# # # # # # # E R R O R # # # # # # # #
#\\033[0m"
echo -e "\033[1;33mUser's .mailboxlist mentiones *.sbd-files"
echo -e "\033[1;33mplease postpone converting this user"
echo -e "\033[1;33m##############################################"
exit 1
fi
# check if user has sbd files by find
NO_SBD=`su - $MUSER -c 'find ~/MailImap/ -name "*.sbd"' | egrep 'sbd$'| wc -l`
echo -e $NO_SBD "sbd-files inside MailImap"
if [ $NO_SBD != "0" ]; then
echo -e "\033[1;33m##############################################"
echo -e "\033[7;5;1;33m# # # # # # # E R R O R # # # # # # # #
#\\033[0m"
echo -e "\033[1;33mUser has one or more *.sbd-files inside
MailImap-Folder"
echo -e "\033[1;33mplease postpone converting this user"
echo -e "\033[1;33m##############################################"
exit 1
fi
# check if user is logged on
IMAPDAEMONS=`ssh r...@mercury "ps -elf" | grep $MUSER | egrep 'imapd$|ipop3d$'
| grep -v root | wc -l`
echo $IMAPDAEMONS " imap- or pop3-Daemons on Mercury for " $MUSER
if [ $IMAPDAEMONS != "0" ]; then
echo -e "\033[1;33m##############################################"
echo -e "\033[7;5;1;33m# # # # # # # E R R O R # # # # # # # #
#\\033[0m"
echo -e "\033[1;33mUser is still logged on to Mercury"
echo -e "\033[1;33mCall this user by phone"
ssh r...@mercury "/usr/local/bin/phone $MUSER"
# PHONE=`ssh r...@mercury "/usr/local/bin/phone $MUSER"`
# echo $PHONE
exit 1
fi
if [ -f /root/convert/$MUSER ]; then
echo -e "\033[1;33m##############################################"
echo -e "\033[7;5;1;33m# # # # # # # W A R N I N G # # # # # # # #
#\\033[0m"
echo -e "\033[1;33m$MUSER Already converted"
echo -e "\033[1;33mif really want to migrate $MUSER"
echo -e "\033[1;33magain, remove the file '/root/convert/$MUSER'"
echo -e "\033[1;33m##############################################"
exit 1
fi
if [ -f /home/$MUSER/.procmailrc ]; then
echo -e "\033[1;33m##############################################"
echo -e "\033[7;5;1;33m# # # # # # # W A R N I N G # # # # # # # #
#\\033[0m"
echo -e "\033[1;33m$MUSER has a procmail script"
echo -e "\033[1;33mpress 1 to show the content of the script"
echo -e "\033[1;33mpress 2 to continue"
echo -e "\033[1;33mpress 3 to exit"
echo -e
"\033[1;33m##############################################\033[0m"
read option
case $option in
1) cat /home/$MUSER/.procmailrc
exit 1
;;
2)
;;
3) exit 1
;;
*) echo -e "\033[1;33mthis is not an option, script will
exit";exit 1
;;
esac
fi
touch /root/m2f.lock
touch /root/convert/$MUSER
echo "migrating $MUSER"
echo "# lock the users mailbox"
touch $MFROMDIR/$MUSER.lock
echo "# Change the mailusertable"
ssh r...@mercury "echo $MUSER >> /etc/mail/mailusers.fiction"
echo "# restart sendmail"
ssh r...@mercury pkill -HUP sendmail
echo "# point popmap to new server and compile new map"
ssh r...@$popmaps "echo $MUSER fiction.hq.eso.org >> /etc/yp/mailserver"
ssh r...@$popmaps make -C /var/yp/
rm -f /root/m2f.lock
echo "# convert the mbox files"
mkdir $MTODIR/$MUSER
chown $MUSER $MTODIR/$MUSER
su $MUSER -c "/usr/bin/mb2md -s $MFROMDIR$MUSER -R -d $MTODIR/$MUSER/"
su $MUSER -c "/usr/bin/mb2md -s $MFROMH -R -d $MTODIR$MUSER/"
# convert the mbox file in the users home if exists
if [ -f /home/$MUSER/mbox ]; then
su $MUSER -c "/usr/bin/mb2md -s /home/$MUSER/mbox -R -d $MTODIR/$MUSER/"
fi
# read the .mailboxlist file in the homedir and figure out if there are
additional folders subscribed
if [ -f /home/$MUSER/.mailboxlist ]; then
cat /home/$MUSER/.mailboxlist | grep -i -v "^inbox$"| grep -v
"^MailImap/" | grep -v "^~/MailImap" |grep -v "/home/$MUSER/MailImap/"| while
read line
do
echo sorce mbox file: /home/$MUSER/`echo $line| sed -e
"s/^~//g"|sed -e "s/\ /\\\\\ /g"`
TPATH=`echo $line| sed -e 's/^~//'|sed -e 's/\ /\\\\\ /g'`
TARGET=`basename "$TPATH"`
su $MUSER -c "/usr/bin/mb2md -s /home/$MUSER/`echo $line| sed
-e "s/^~//"|sed -e "s/\ /\\\\\ /g"` -R -d $MTODIR/$MUSER/.$TARGET"
done
fi
# if theres an mbx style INBOX file, convert it to mbox and then to maildir
if [ -f /home/$MUSER/INBOX ]; then
ssh sonic su - $MUSER -c '"mailutil -verbose -debug" copy INBOX
fictionmbox'
su - $MUSER -c "/usr/bin/mb2md -s /home/$MUSER/fictionmbox -R -d
$MTODIR/$MUSER/"
su - $MUSER -c "rm -f fictionmbox"
fi
echo "# create subscriptions file"
cd $MTODIR$MUSER/
#su $MUSER -c "find /var/maildir/$MUSER -type d -name '\.*' | sed -e 's/\.\///'
| sed -e 's/^.//'" > $MTODIR$MUSER/subscriptions
su $MUSER -c "find /var/maildir/$MUSER -type d -name '\.*' | sed -e 's/\.\///'
| sed -e 's/^\/var\/maildir\/$MUSER\/\.//'" > $MTODIR$MUSER/subscriptions
chown $MUSER $MTODIR$MUSER/subscriptions
echo "# remove lock file"
rm -f $MFROMDIR/$MUSER.lock
echo "move inbox to $MUSER.old"
su $MUSER -c "mv /net/mercury/var/mail/$MUSER /net/mercury/var/mail/$MUSER.old"
echo "##############################################"
echo "$MUSER has been converted"
if [ -f /home/$MUSER/.forward ]; then
echo -e "\033[7;5;1;33mplease have a look at the .forward file: "
echo -e "\033[1;33m--"
cat /home/$MUSER/.forward
echo -e "\033[1;33m--"
fi
echo "have a nice day!"