migrate-mail-from-one-server-to-another-with-imapsync

Have you been in the situation where you needed to move everyone’s mail from one provider to another? It’s a pain to do using the mail client one at a time, but with this guide, you’ll be able to create a csv with everyone’s info and run one command to fire it all off. All you need is a Linux machine to do it.

First, you’ll need to install the epel repo (skip if you already have it):

CentOS 5 (as root):

1 2 3 wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm rpm-Uvh remi-release-5*.rpm epel-release-5*.rpm

CentOS 6 (as root):

1 2 3 wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm-Uvh remi-release-6*.rpm epel-release-6*.rpm

Now, use yum to install imapsync. It will automagically install all of the deps.

1 yum install imapsync

Now that it’s installed, let’s print out the help file and take a look at all of the usefulness of imapsync:

host1 – source host2 destination

/bin/imapsync –host1 192.168.0.2 –user1 [email protected] –password1 1raja23 –host2 192.168.0.3 –user2 [email protected] –password2 1raja23

Script for migration all mail from host1 to host2 with imap bulky.

# cat /scripts/imapsync.sh

##############start#######

#!/bin/bash

logfile=”sinklog.txt”

host1=192.168.0.2 # host1 is Source

host2=192.168.0.3 # host2 is Dest

domain=test.com # domain is where email account is

# everything after @ symbol

###### Do not modify past here ######

date=`date +%X_-_%x`

echo “” >> $logfile

echo “————————————” >> $logfile

echo “IMAPSync started.. $date” >> $logfile

echo “” >> $logfile

{ while IFS=’;’ read u1 p1; do

user=$u1″@”$domain

echo “Syncing User $user”

date=`date +%X_-_%x`

echo “Start Syncing User $u1”

echo “Starting $u1 $date” >> $logfile

#echo “imapsync –nosyncacls –syncinternaldates –host1 $host1 –user1 $user –password1 \

#$p1 –host2 $host2 –user2 $user –password2 $p1″

imapsync –nosyncacls –syncinternaldates –host1 $host1 –user1 $user –password1 $p1 –host2 $host2 –user2 $user –password2 $p1

date=`date +%X_-_%x`

echo “User $user done”

echo “Finished $user $date” >> $logfile

echo “” >> $logfile

done ; } < userlist.txt

date=`date +%X_-_%x`

echo “” >> $logfile

echo “IMAPSync Finished.. $date” >> $logfile

echo “————————————” >> $logfile

####end#####

2. userlist.txt file should be like with with username and password

cat /home/satya/migration_list_test.csv |awk -F’,’ ‘{print $1″;”$3}’

    user;password
    user2;password2

Leave a Reply

Your email address will not be published.