Migrating from Dovecot 1 to Dovecot 2

Sean Kamath kamath at moltingpenguin.com
Sun Nov 5 06:23:41 EET 2017


On Nov 3, 2017, at 4:23 PM, Dovecot list <cr4shydlo+dovecot at gmail.com> wrote:
> 
> Hello.
> I try to migrate about 200G of mails from one server to another.
> On the old i have Dovecot1 with Maildirs (without master pass etc.), on the
> new one i setup dovecot2 with mdbox. I need now to migrate (partialy, not
> all at once) mails from one to another.
> I can't find any solution that i can use? I dont have master password, and
> i want to mikgrate all mailaccont each other. Can anyone use me a working
> config for this ? Best will be that migratet dont want to be downloaded by
> mail client one more time.
> Thanks for any help.
> Best regards.

Hi.  I just did this.

All things considered, it went without impack.

It wasn’t perfect, as when someone was accessing their mailbox I’d get errors.  So, for the final sync, I turned off the imap service for everything but the transfer (blocked at the firewall).

All things considered, it went well.  I’m sure this is jacked up and wrong and whatnot, but got my wife and kids (and me!) moved over with no hiccups hardly at all!

I still happen to have the config files I used:

I ended up doing some random crap that probably didn’t need to be done: Taking the output of dovecot -n and putting it in a template file (mostly to get the location of the sdbox’s I use).  Then I added the following after it:

imapc_host = old_dovecot1_host
imapc_port = 993
imapc_ssl = imaps
imapc_user = %%USER%%
imapc_password = %%PASSWORD%%
mail_fsync = never
imapc_ssl_verify = no
imapc_features = rfc822.size fetch-headers
# Read multiple mails in parallel, improves performance
mail_prefetch_count = 20

Now, I don’t know if this is all correct or not, but generally worked well.   The imap_ssl_verify = no bit was because my cert expired in the middle of the migration.  Prior to that I had:

ssl_client_ca_file = /home/<me>/dovecot/certs/huh.crt

So, basically, I then wrote a script (I called it ‘synchrotron’ because that’s me):

#!/bin/sh

ACCTS=/home/<me/.act # A list of account:password pairs
TEMPL=/home/<me>/conf.template # (the template file)

if [ `whoami` != "root" ]
then
        echo "You should be root, my friend."
        exit 1
fi

CONF=$(mktemp)

do_sync() {
        UNAME=$1
        PASS=$(grep "^$UNAME:" $ACCTS | cut -d: -f2)
        if [ -z "$PASS" ]
        then
                echo "Unknown user $UNAME: No Password!"
                return
        fi
        sed -e "s/%%USER%%/$UNAME/" -e "s/%%PASSWORD%%/$PASS/" $TEMPL > $CONF
        START=`date +%s`
        CMD="/usr/local/bin/doveadm -v -c $CONF backup -R -u $UNAME imapc:"
        echo "START: $(date)"
        echo "Running $CMD"
        $CMD
        ret=$?
        STOP=`date +%s`
        echo "STOP: Returned $ret $(date)"
        rm -f $CONF
        echo "Duration: $(expr $STOP '-' $START) seconds”
}

# This allows you to specify a user on the command line. . .
if [ $# -gt 0 ]
then
        echo "Only doing a few users"
        while [ $# -gt 0 ]
        do
                do_sync $1
                shift
        done
        exit
fi

# Otherwise, do 'em all

# I like to log everything
exec >> /tmp/synchrotron.out 2>&1

for user in $(cut -d: -f1 $ACCTS)
do
        do_sync $user
done



More information about the dovecot mailing list