Zimbra Server Migration and Zimbra Account Transfer – The Perfect Method
- Category : Linux Helpline (Easy Guide)
- Posted on : Mar 13, 2019
- Views : 2,729
- By : Hagen V.

1. Introduction
Zimbra project doesn’t have a cross migration or proper account transfer documentation. All they tell is to do copy the folder /opt/zimbra to your new servers. But if any of those files infected with a rootkit or other malicious scripts , then your new server also will be compromised. So never sync or copy the entire directory of your zimbra installation. Zimbra also tell you to upgrade your production server to the latest version before migration. But improper upgrade may result in entire data lose. With this procedure you can do:
- Migrate zimbra from one Operating System To another.
- Migrate zimbra account between any hardware and Operating systems configurations.
- No interruption on production server like software upgrade or service disable.
- Migrate zimbra from old version to a new version server
- Zimbra cross migrations without copying entire directories.
2. Requirement
You need an old server with zmibra account and a new fresh server with the Os you wish. Dont’ create or make any custom configuration or setting in you new server. Please make sure to set your new servers hostname same as the old one.
- Old server
- Need ssh root login
- Need zimbra admin logins
- Enough HDD space to store backups
- New server
- Must be installed with latest stable zimbra
- Need ssh root logins
- Need zimbra admin logins
- Enough HDD space to store backups
3. Presetup
You need to setup an ssh key from the new server’s root account to the old server’s root account.
Reduce the TTL of MX records of your domain to 500 seconds . So that you can easily switch the domain’s IP after migration. Please remember to schedule the migration task on non peek hours.
Create a directory in both new and old server into which we store all required files and data for doing the migration
[root@zimbra ~]# mkdir /backups/zmigrate [root@zimbra ~]# chown zimbra.zimbra /backups/zmigrate [root@zimbra ~]# su - zimbra
All operation in your Zimbra server must be performed as Zimbra user itself, otherwise you will get permission and ownership issues in your zimbra server
4. Backup all data from Old server
We are going to copy all data from old server without interrupting the services.
4.1 Find all domains
You need to find all the domains from your old server. We will store the domain list in a file called domains.txt. You need to back all the domains list as follows,
zimbra@zimbra:~$ cd /backups/zmigrate zimbra@zimbra:/backups/zmigrate$ zmprov gad > domains.txt zimbra@zimbra:/backups/zmigrate$ cat domains.txt fun.com myserver.com justfortest.com checkit.com dieanotherday.com gnutest.com foo.com zimbra.foo.com zimbra@zimbra:/backups/zmigrate$
Now remove all domains and subdomains related with the main hostname of your server foo.com , from this list (domains.txt) because it was already created in your new server. So there is no need to create a new domain with the same name.
4.2 Find all admin accounts
Most of these servers will have only one admin. But some servers have multiple admins. So it will be good to find all admin accounts. We will store the admins list in admins.txt
zimbra@zimbra:/backups/zmigrate$ zmprov gaaa > admins.txt zimbra@zimbra:/backups/zmigrate$ cat admins.txt admin@foo.com zimbra@zimbra:/backups/zmigrate
4.3 Find all email accounts
Next step is to find all the email accounts hosted in your old server. Get a list of your email accounts and save in the file emails.txt . So from this file we can see how many accounts that need to migrate.
zimbra@zimbra:/backups/zmigrate$ zmprov -l gaa >emails.txt zimbra@zimbra:/backups/zmigrate$ cat emails.txt gm@fun.com forest@fun.com galsync@fun.com fax@myserver.com paul@myserver.com angela@myserver.com brooke@myserver.com hnmobile1@myserver.com maria@justfortest.com samantha@justfortest.com backupmail@justfortest.com admin@checkit.com sandra@checkit.com zimbra@zimbra:/backups/zmigrate$
Please remove all the email accounts from the file /backups/zmigrate/emails.txt with a starting words like spam, virus, ham, galsync . There is no need to restore these accounts. Even if you still need to restore , you can do it. I don’t like spam and virus emails.
4.4 Get all distribution lists
You need to get all the distributions list and store it in a file called distributinlist.txt.
zimbra@zimbra:~$ zmprov gadl > /backups/zmigrate/distributinlist.txt zimbra@zimbra:~$ cat /backups/zmigrate/distributinlist.txt budgetrtodomainusers@fun.com healthnowdomainusers@myserver.com checkit.comdomainusers@checkit.com northpointessdomainusers@dieanotherday.com parkatnorthhillsdomainusers@gnutest.com zimbra@zimbra:~$
4.5 Get all members in distribution lists
In this step we are going to collect all members in each of these distributions. We will create a folder called distributinlist_members and create a file under this folder named distributinlist.txt , then store all the distributions members.
zimbra@zimbra:~$ mkdir /backups/zmigrate/distributinlist_members zimbra@zimbra:~$ for i in `cat /backups/zmigrate/distributinlist.txt`; do zmprov gdlm $i > /backups/zmigrate/distributinlist_members/$i.txt ;echo "$i"; done budgetrtodomainusers@fun.com healthnowdomainusers@myserver.com checkit.comdomainusers@checkit.com
4.6 Find all email account’s passwords
Now need to find the encrypted password of all of your old email accounts and store it under a folder named userpass/ as follows:
zimbra@zimbra:/backups/zmigrate$ mkdir userpass
zimbra@zimbra:/backups/zmigrate$ for i in `cat emails.txt`; do zmprov -l ga $i userPassword | grep userPassword: | awk '{ print $2}' > userpass/$i.shadow; done
4.7 Backup all user names , Display names and Given Names
Zimbra will accept a Names and Disaplay names in email accounts during account creation. So we need to restore those data too. We will create a directory called userdata/ which contains these details of each of those email accounts
zimbra@zimbra:/backups/zmigrate$ mkdir userdata zimbra@zimbra:/backups/zmigrate$ for i in `cat emails.txt`; do zmprov ga $i | grep -i Name: > userdata/$i.txt ; done
4.8 Now backup all email account
This will take some time to take backup of all email accounts. So you can run this command behind “screen”. A tgz file will be created with each emails name. We will use this files to transfer email accounts.
zimbra@zimbra:/backups/zmigrate$ for email in `cat /backups/zmigrate/emails.txt`; do zmmailbox -z -m $email getRestURL '/?fmt=tgz' > $email.tgz ; echo $email ; done gm@fun.com forest@fun.com galsync@fun.com fax@myserver.com fax2@myserver.com paul@myserver.com
This tgz files contains
- Contacts
- Calendars
- Briefcase
- Tasks
- Searches
- Tags
- Folders
All subfolders are included, except Junk and Trash. There is no way to include these in the big dump, but they can be exported separately:
4.9 Now backup alias
Some times your server may have email aliases for certain accounts. So you need to copy those aliases too. We will create a sub folder called alias/ for storing the backup of Alias.
zimbra@zimbra:/backups/zmigrate$ mkdir -p alias/
zimbra@zimbra:/backups/zmigrate$ for i in `cat emails.txt`; do zmprov ga $i | grep zimbraMailAlias |awk '{print $2}' > alias/$i.txt ;echo $i ;done
gm@fun.com
forest@fun.com
Some of your email accounts don’t have alias. So the above created files may be an empty file. Remove those empty files as follows,’
zimbra@zimbra:/backups/zmigrate$ find alias/ -type f -empty | xargs -n1 rm -v
4.10 Now Backup all email signatures
Please use the following script to backup all signatures of email accounts. Special thanks for Antonio Díaz Meneses for giving the inputs.
#!/bin/bash mkdir signature for i in `cat emails.txt`; do zmprov ga $i zimbraPrefMailSignatureHTML > /tmp/signature; sed -i -e "1d" /tmp/signat