Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Migration

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-11-2009, 12:32 AM
New Member
 
Posts: 3
Default Migration from Maildir File Format to Zimbra SUCCESS!

After searching high and low to find a way to import mail from an old server to Zimbra, I've settled on this Maildir to Zimbra method. I began with Imapsync, but found it to be unreliable. It would complete, but Zimbra would still be missing lots of emails.

This solution is a modified version of a script found elsewhere on these forums. I made a few upgrades so that:
- Subfolders import correctly! The original scripts would make each folder show up at the root level with this syntax: "Folder1.Subfolder1.Sub-Subfolder1" instead of the intended hierarchical format.
- It runs successfully! I've moved GB's worth of email over already, and it hasn't had an issue so far.

I've found this to be the most reliable solution so far. I suggest you give it a try if you're looking to migrate mail.

Here's what you'll need to do:
1. Begin by adding the users to Zimbra in advance. The user accounts *must* match what you're importing. The only exception is if you import the mail below, and rename the folders to whatever account name you set up in this step.
2. Start with a "scratchpad" folder on your Zimbra system. This is a workplace where the Maildir files can sit while you're transferring them.
3. Copy the user mail folders from your old server. The result should be multiple folders inside this work area, such as user1, user2, user3, etc.
4. Make a file called run.sh in this work area. Copy the code below into it. Make sure you update the domain name in the script. Close it and CHMOD 777 it.
5. Now, run the script. Type ./run.sh. It will run for a while. You'll know it's complete when you are returned to a command prompt.

Code:
#!/bin/bash

#
# Maildir to Zimbra import
# Drop in your user root and run as superuser.
#
shopt -s extglob

domain="domain.com" # change to your domain!

for user in `ls -d1 */|sed s/\\\///`
do
echo
echo "User $user"
echo
#
#
find $user -maxdepth 10 -type d -name cur | awk '{ print length($0),$0 | "sort -n"}' | while read line;
do


line=`echo $line | sed -e 's/^[0123456789]*[[:space:]]//'`
#echo "PARSED LINE: " $line

folder=`echo ${line}|cut -f3 -d"/"|sed s/\\\.//`
# replace _ with a space (IMPORTANT! This makes the imported subfolders come out correctly!)
newfolder=$( echo $folder|sed 's/[.]/\//g')
line2=`echo ${line/%cur/new}`
echo "FOLDER $folder"
if [ "$folder" = "cur" ]
then
echo "Transferring inbox..."
/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "Inbox" "$PWD/$user/Maildir/cur"
/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "Inbox" "$PWD/$user/Maildir/new"
echo "Finished transferring inbox."
else
if [ "$folder" != "Sent" ] && [ "$folder" != "Drafts" ] && [ "$folder" != "Junk" ] && [ "$folder" != "Trash" ]
then
echo "Creating folder '/$newfolder'..."
/opt/zimbra/bin/zmmailbox -z -m $user@$domain createFolder /"$newfolder"
echo "Finished creating folder." 
fi

/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "/$newfolder" "${PWD}/${line}"
/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "/$newfolder" "${PWD}/${line2}"

fi
done

done
I hope this helps someone down the road! I know I could have used it. It would have saved a LOT of time.
Reply With Quote
  #2 (permalink)  
Old 09-18-2009, 12:35 AM
Active Member
 
Posts: 42
Default

Hi Dear
This is very important script to migrate mail from old system to newly zimbra server, but u dont think it still need some modification. Because i am using this script to migrate my mail account but after migrating all mails it shows all mail as read while i have lots of unread mails. pls provide the solution to get rid off the problem.
Thanks
Reply With Quote
  #3 (permalink)  
Old 09-19-2009, 05:09 PM
New Member
 
Posts: 3
Default

Hello,

Yes, it would be nice if it were able to retain the read/unread settings. However, the original script that I found online did not do this either. I didn't add the feature, I just made this script reliable so it works every time.

In my case, having all old mail imported and marked as read was acceptable.
Reply With Quote
  #4 (permalink)  
Old 09-22-2009, 05:50 AM
Active Member
 
Posts: 42
Default

can you please edit this feature to me?
because i am not expert in scripting as you.
pls help me.
Thanks in advance
Reply With Quote
  #5 (permalink)  
Old 10-12-2009, 10:43 AM
Senior Member
 
Posts: 57
Default

Yep, I wrote/posted the original script, it worked but I quit on it because of the flag issue, and very little interest in the script a the time.
Reply With Quote
  #6 (permalink)  
Old 10-27-2009, 04:10 PM
Senior Member
 
Posts: 55
Question Migrating home/usr/maildir folder "cur" to Zimbra - questions.

Can you help me understand that if I use this script I can move my old user mail folders having this layout to Zimbra?

/Home/User/Maildir
>cur
>new
>tmp
.Archives
.Drafts
.Sent
.Trash

So if I try your script I can see where to change the domain. But when I copy mail to a working folder do I need to include the folders /home/user/maildir ...... and subfolder "cur" or just /user/maildir/cur?

Steven
Reply With Quote
  #7 (permalink)  
Old 09-10-2011, 09:52 AM
Starter Member
 
Posts: 1
Default This worked for me 3 months ago, now it seems broken

I get a failure on line 7 of the script --> shopt: not found

My default shell is bash, so this should work. shopt -s extglob works fine from the terminal but not in the script. Any ideas?

I am attempting to import maildirs into Zimbra on Ubuntu Lucid.
Reply With Quote
  #8 (permalink)  
Old 09-26-2011, 05:45 PM
New Member
 
Posts: 3
Default

Try changing line 7 to reflect the full path to shopt. I'm not sure what it is off hand, so you'll need to find it.
Reply With Quote
  #9 (permalink)  
Old 10-09-2011, 04:14 AM
Starter Member
 
Posts: 1
Default Updated Script

I've been in need to import also subfolders so i've changed a little your script.

Maybe it's useful for someone
Code:
#!/bin/bash
#
# Maildir to Zimbra import
# Drop in your user root and run as superuser.
#



ZMM="/opt/zimbra/bin/zmmailbox"

domain="domain.com" # change to your domain!
defaultpass="xxxxyyyy"

for user in `ls -d1 */|sed s/\\\///`
do
  echo
  echo "User $user"
  echo

  #
  #
  find $user -maxdepth 10 -type d -name cur | while read line;
  do


      folder=$(echo ${line}|cut -f3 -d"/"|sed s/\\\.//)
      line2=$(echo ${line/%cur/new})
      #echo "LINE2 $line2"
      #echo "FOLDER $folder"
      if [ "$folder" = "cur" ]
      then
          $ZMM -z -m $user@$domain addMessage Inbox $PWD/$user/Maildir/cur
          $ZMM -z -m $user@$domain addMessage Inbox $PWD/$user/Maildir/new
      else
          if [ "$folder" != "Sent" ] && [ "$folder" != "Drafts" ] && [ "$folder" != "Junk" ] && [ "$folder" != "Trash" ]
          then

              echo $folder | tr '\.' '\n' > /tmp/qq

              folder=""
              while read x;
              do
                  folder="$folder/$x"

                  if [ $($ZMM -z -m $user@$domain gaf | grep "$folder" | wc -l) == 0 ]; then
                      $ZMM -z -m $user@$domain createFolder "$folder"
                  fi
              done < /tmp/qq
          else
              folder="/$folder"
          fi

          $ZMM -z -m $user@$domain addMessage "$folder" "${PWD}/${line}"
          $ZMM -z -m $user@$domain addMessage "$folder" "${PWD}/${line2}"
      fi

  done

done
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.