If you read my book Mac OS X Server 10.5 als Groupware-Server and built up your own personal Mac OS X mail server, you might want to move existing email data to your new server.

If your server serves mails for a couple of users only, you can do this using your mail client: simply point it to you old mail server as well as to your new machine and move data within your mail application. This has to be done for each user.

If you support multiple users, you might want to automate the data migration without user interaction.

One way to do this is to use the perl app imapsync, which can be found here.

This short article explains how we migrated about 2000 mail accounts including existing emails and subfolders from a Novell IMAP server to a 10.4 mail server. This should work fine with a 10.5 server, too.

Install imapsync

First you need to install imapsync. This can be either done on any Mac OS X client or the server itself.
If you use a Mac OS X client, mails will be copied from the old server to the client and then to the new server, so the most effective way for big mail servers would be to install imapsync on the server as there’s less network traffic necessary on the ethernet interface if you copy data only once.

The easiest way to do install imapsync is to use MacPorts for the installation procedure.

If you haven’t done so before, get your copy of MacPorts at http://www.macports.org/install.php.
The easiest way is to use the Mac OS X package installer, which automatically updates MacPorts to the latest branch during installation.

imapsync needs the Perl module MAIL::IMAP-Client version 2.2.9 as a prerequisite, which you can download from here.
Unzip the downloaded file, cd into the folder “Mail-IMAPClient-2.2.9″ and type:

perl Makefile.PL

After this command has completed, type

make install

Now use MacPorts to actually install imapsync:

port install imapsync

After installation you find imapsync at /opt/local/bin/imapsync.

Move mails from old to new server

imapsync has a lot of options available. Read

imapsync --help

to learn the details.

In our environment we used the following script to migrate mail data:


#!/bin/bash
#
# MailCopy 1.0, July 2007, Andre Aulich, www.andre-aulich.de
#
# This script copies your users' mails to the new mailserver.
# It needs a file with all users for whom you want to copy
# mails to your server.
# The file holds a single user's shortname per line.
#
# Define the path to this file:

USERS=/USERS_FILE.TXT

# This script assumes you have imapsync installed.
# Change the path in the script if your shell doesn't
# know about it.

# Now let's do some work:

for i in $(cat USERS)
do
echo "Copying $i's mails..."

# Change the IP addresses, passwords, etc. to match your environment:
imapsync --noauthmd5 --host1 IPADDRESSOFOLDSERVER --user1 $i --password1 PASSWORDFOROLDSERVER --host2 IPADDRESSOFNEWSERVER --user2 $i --PASSWORDFORNEWSERVER test --sep1 : --prefix1 "" --sep2 : --prefix2 "" --syncinternaldates || echo "Something went wrong with user $i."

# As you might have seen, this script assumes, that your
# user names are the same on the source and the target.
#
# It also assumes, that you use the same password for all your users.

done

Depending on the type of your old mail server you might need to adapt some settings.

It’s also possible to exclude TRASH or SPAM mailboxes.

If you need any help in migrating existing mail data feel free to get in touch with me.

Good luck!

Please use at your own risk!

This entry was posted in Mac OS X Server.

Comments are closed.