Monday, January 15, 2018

Migrate Emails from Gmail to Zimbra


Description: Here I have explained how to migrate emails from google apps account to zimbra server. For migration I have used imapsync utility.
  • Install imapsync in destination Zimbra server using yum 
          # yum install imapsync
  • Login user in gmail and allow Imap from account settings as follow:




  • Create Email Account in Zimbra Mail Server
  • Run below command in zimbra as root:
   # imapsync --host1 74.125.133.108 --user1 user@googleaccount.co.in --password1 password --host2 hostname.zimbradomain.com --user2 user@zimbradomain.com --password2 password --syncinternaldates --ssl1 -ssl2 --noauthmd5  --exclude All Mail --useheader 'Message-ID'


Mass email migration from Google Apps to using imapsync
  • ·         Create one user.txt file which contains source and destination users and their passwords like as follow:
          user1@source.tld;user1sourcepassword;user1@destination.tld;user1destinationpassword
          user2@source.tld;user2sourcepassword;user2@destination.tld;user2destinationpassword
          user3@source.tld;user3sourcepassword;user3@destination.tld;user3destinationpassword

  • ·         Create shell script in same location and paste below content in it.
#!/bin/bash

#Configure servers
SERVER1= imap.gmail.com
SERVER2=imap.destination.com

#Uncomment to hide folder sizes
#FAST="--nofoldersizes"

#Uncomment to do a dry run (no actual changes)
#DRY="--dry"

#Uncomment to just sync folders (no messages)
#JUSTFOLDERS="--justfolders"

#Uncomment to just connect (no syncs at all)
#JUSTCONNECT="--justconnect"

#Set the path to your imapsync binary
imapsync=imapsync

#Users file
if [ -z "$1" ]
then
echo "No users text file given."
exit
fi

if [ ! -f "$1" ]
then
echo "Given users text file \"$1\" does not exist"
exit
fi

{ while IFS=';' read  u1 p1 u2 p2; do

$imapsync --usecache --tmpdir /var/tmp \
--host1 ${SERVER1} --user1 "$u1" \
--password1 "$p1" --ssl1 \
--host2 ${SERVER2} \
--port2 993 --user2 "$u2" \
--password2 "$p2" --ssl2 \
${FAST} ${DRY} ${JUSTFOLDERS} ${JUSTCONNECT} \
--regextrans2 's{Sent$}{[Gmail]/Sent Mail}' \
--regextrans2 's{Sent Items$}{[Gmail]/Sent Mail}' \
--regextrans2 's{Sent Messages$}{[Gmail]/Sent Mail}' \
--regextrans2 's{Drafts$}{[Gmail]/Drafts}' \
--exclude 'INBOX.Trash|INBOX.spam|INBOX.Apple Mail To Do'

done ; } < $1

Note:  Change as Source and Destination server.

  • ·         Run script using below comman
          ./migration.sh users.txt
  • ·         The script can take a long time to run, so I suggest using nohup and redirecting the output to a log file:
          nohup ./migration.sh users.txt > migrationlog.txt 2>&1 &

No comments:

Post a Comment