Migrating Zimbra to Zimbra: A Step-by-Step Guide (ZCS to ZCS)


Migrating from one Zimbra mail server to another can be necessary for various reasons. The most common motive is running low on disk storage. Other motivations might include the need for a failover mail server to ensure business continuity in case of a catastrophic event. This migration technique also enables you to create a clone of your existing email server for redundancy.

SysadminCorner help to inform by tutorials and ensure a virtually zero downtime during the migration process, follow these steps:

1. Prepare for Migration

  • Set DNS TTL Entries: Adjust the DNS Time-to-Live (TTL) settings for your mail server to the shortest possible time. Ideally, perform this step a day prior to migration to allow for adequate propagation.
  • Prepare a New Server: Ensure you have a fully operational new server ready for Zimbra installation.

2. Server Preparation

  1. Install Zimbra: Install the same version of Zimbra on your new server as on the old one. You can follow the official Zimbra installation guide.
  2. Configure the New Server: Set up the new mail server with identical settings to the old server, but use a different IP and domain name. If multiple domains exist on the old server, create only the primary domain on the new server, as others will be imported later.
  3. Certificate Consideration: If you plan to install a Let’s Encrypt certificate, ensure your server name matches https://webmail.yourdomain.com.

3. Exporting Data from the Old Server

Before exporting, confirm that you have sufficient storage space accessible from both servers. This could be on the old server or through an NFS share from the new server. Follow these steps:

Create a Directory for Migration:

# mkdir -p /migration/zimbra chmod -R 777 /migration/zimbra chown -R zimbra:zimbra /migration/zimbra

Export Domains:

# su – zimbra mkdir -p /migration/zimbra/domains

# cd /migration/zimbra/domains zmprov gad | tee -a domains.txt

Export Accounts:

# mkdir -p /migration/zimbra/accounts

# cd /migration/zimbra/accounts

# zmprov gaaa | tee -a admins.txt zmprov -l gaa | tee -a users.txt

Export Account Details:

mkdir -p /migration/zimbra/account_details

cd /migration/zimbra/account_details

for user in `cat ../accounts/users.txt`; do zmprov ga $user | grep -i Name: | tee -a $user.txt; done

Export Passwords:

mkdir -p /migration/zimbra/passwords

cd /migration/zimbra/passwords

for user in `cat ../accounts/users.txt`; do zmprov -l ga $user userPassword | grep userPassword: | awk ‘{ print $2}’ | tee -a $user.shadow; done

Export Distribution Lists:

mkdir -p /migration/zimbra/distribution_lists

cd /migration/zimbra/distribution_lists

zmprov gadl | tee -a distribution_lists.txt for list in `cat distribution_lists.txt`; do zmprov gdlm $list > $list.txt; echo “$list”; done

Export Aliases:

mkdir -p /migration/zimbra/aliases

cd /migration/zimbra/aliases

for user in `cat ../accounts/users.txt`; do zmprov ga $user | grep zimbraMailAlias | awk ‘{print $2}’ | tee -a $user.txt; echo $user; done

find /migration/zimbra/aliases -type f -empty | xargs -n1 rm -v

Export Mailbox Data :

This is often the most time-consuming step. Make sure to run it in a console session or via screen to avoid interruptions.

mkdir /migration/zimbra/mailbox_data

cd /migration/zimbra/mailbox_data

for user in `cat ../accounts/users.txt`; do echo “Exporting mailbox $user”; zmmailbox -z -m $user getRestURL ‘/?fmt=tgz’ > ./$user.tgz; done

Export Filters :

mkdir /migration/zimbra/filters

cd /migration/zimbra/filters

vim export_filters.sh

Paste the following script:

#!/bin/bash
mkdir tmp
set -x
clear
for user in `cat ../accounts/users.txt`;
do
    filter=`zmprov ga $user zimbraMailSieveScript > ./tmp/$user`
    sed -i -e "1d" ./tmp/$user
    sed 's/zimbraMailSieveScript: //g' ./tmp/$user > ./$user;
    rm ./tmp/$user
    echo "Export filter for $user"
done
rm -rf tmp

4. Importing Data to the New Server

Restore Domains:

cd /migration/zimbra/domains

for domain in `cat domains.txt`; do zmprov cd $domain zimbraAuthMech zimbra; echo $domain; done

Restore Accounts and Passwords

mkdir -p /migration/zimbra/scripts

cd /migration/zimbra/scripts

vim restore_accounts.sh

Paste the following code:

#!/bin/bash
PASSWDS="../passwords"
ACCOUNT_DETAILS="../account_details"
USERS="../accounts/users.txt"
for i in `cat $USERS`
do
    givenName=$(grep givenName: $ACCOUNT_DETAILS/$i.txt | cut -d ":" -f2)
    displayName=$(grep displayName: $ACCOUNT_DETAILS/$i.txt | cut -d ":" -f2)
    shadowpass=$(cat $PASSWDS/$i.shadow)
    zmprov ca $i "TeMpPa55^()" cn "$givenName" displayName "$displayName" givenName "$givenName"
    zmprov ma $i userPassword "$shadowpass"
done

Make the script executable and run it:

chmod 777 restore_accounts.sh

./restore_accounts.sh

Restore Distribution Lists:

for list in `cat distribution_lists/distribution_lists.txt`; do zmprov cdl $list; echo “$list — done”; done

Populate the lists with:

vim restore_dist_lists.sh
#!/bin/bash
for list in `cat distribution_lists.txt`
do
    for mbmr in `grep -v '#' ./$list.txt | grep '@'`
    do
        zmprov adlm $list $mbmr
        echo " $mbmr has been added to $list"
    done
done

Restore Aliases

Create restore_aliases.sh

cd /migration/zimbra/aliases
vim restore_aliases.sh
#!/bin/bash
for user in `cat ../accounts/users.txt`
do
    if [ -f "./$user.txt" ]; then
        for alias in `grep '@' ./$user.txt`
        do
            zmprov aaa $user $alias
            echo "$user ALIAS $alias - Restored"
        done
    fi
done

Import Mailboxes

cd /migration/zimbra/mailbox_data

for mailbox in `cat ../accounts/users.txt`; do zmmailbox -z -m $mailbox postRestURL “/?fmt=tgz&resolve=skip” ./$mailbox.tgz; echo “$mailbox – done”; done

Import Filters

Create import_filters.sh

cd /migration/zimbra/filters
vim import_filters.sh
#!/bin/bash
for file in /migration/zimbra/filters/*
do
    StrFilter=`cat "$file"`
    Acc=`echo $file | cut -d "/" -f5`
    su - zimbra -c "zmprov ma $Acc zimbraMailSieveScript '$StrFilter'"
    echo "Process filter $Acc"
done

5. Finalizing the Migration

  1. Bring the New Server Online: Restart Zimbra services and check their status.
    • zmcontrol restart
    • zmcontrol status
  2. Verify User Accounts: Log in to the web interface to confirm the number of accounts matches the old server. Ensure users can send emails without issues.
  3. Assist Users: If users miss their email signatures, temporarily make the old server accessible via a subdomain (e.g., oldmail.domain.com) for easy access to previous emails.

6. Conclusion

Migrating from one Zimbra server to another can be daunting, but with careful preparation and execution, you can achieve a seamless transition. By following this comprehensive guide, you can minimize downtime and ensure a successful migration of your email environment.


Leave a Reply

Your email address will not be published. Required fields are marked *