Migrate Zimbra From One Server To Another Server | Method-1 | Zimbra

This will be a series of articles. We will write three (3) articles in this series to show you how to migrate your Zimbra server from one server to another. So at the end of this series, you will have a clear idea about the migration process, and you will be able to choose between them.

What To Keep In Mind Before Migration

Migration needs a lot of planning and attention. Therefore, system admins often hesitate to migrate even if it must be done.

Before migration, you should think about three things:

  • Backup
  • Downtime
  • Approach

Backup

Migration is a critical process. If it goes wrong, you might lose all of your data; your system may become unstable/unusable.

Please take a backup of your existing data before starting any backup, restore, or maintenance process.

Your backup will help you to decide what type of approach you are going to follow.

Downtime

Downtime is one of the key factors that you should consider before planning any migration. It will also affect your approach selection.

Approach

There are several approaches to migrating Zimbra from one server to another server. Two key factors to consider selecting approaches.

  • Service migration followed by data migration
  • All Out-migration

Service Migration Followed By Data Migration

In this case, you migrate your service from the old server to the new server by changing necessary DNS records. Once you do this, your email service becomes active in your new server without any data. Then you gradually transfer your data from the old server to the new server.

In this case, your downtime is minimal. But the challenge is your user will get their data gradually.

We will learn some migration techniques in this series that follow this approach.

All out migration

In this migration method, you can migrate the data and service within an estimated time frame. So you can understand there is a down time involved in this method. The bigger the data is the higher the downtime will be. After the downtime as soon as your process completes, your service and data will be available to your users.

Can be useful when:

  • You have relatively mid size data on a single server infrastructure
  • You are just migrating the exiting server to another upgraded hardware
  • The zimbra version of old server and new server would be same

Service Migration Followed By Data Migration – (Method-1)

We will describe all steps so that you can easily follow them.

Let’s assume you have a Zimbra server that needs to be migrated to another server hardware. Let me show you an illustrated overview of this method.

Step-1

Backup/Export User Data without email

Prepare another server hardware. Install your desired OS on the new server. On of our previous articles will help you to choose the best operating system for your server.

Install Zimbra on your new server. Don’t miss the recommendations to prepare the server for the zimbra.

Extract all user information from the old server so we can create them on the new server.

Email migration steps-1

*** You can extract/export this information to your old server or any other storage device. If you are extracting data on the same server, remember that you should have enough free space. To extract this information, use the following commands:

Create a directory and set the necessary permissions

root@mail:~#mkdir -p /opt/backups/zmigrate
root@mail:~#chown zimbra.zimbra /opt/backups/zmigrate
root@mail:~# cd /opt/backups/zmigrate
root@mail:/opt/backups/zmigrate# su zimbra

Export domains, email accounts, and distribution lists

zimbra@mail:/opt/backups/zmigrate$ zmprov gad > domains.txt
zimbra@mail:/opt/backups/zmigrate$ zmprov -l gaa > emails.txt
zimbra@mail:/opt/backups/zmigrate$ zmprov gadl > distributionlist.txt

Export distribution list members’ information

zimbra@zimbra:~$ mkdir /opt/backups/zmigrate/distributionlist_members
zimbra@mail:/opt/backups/zmigrate$ for i in `cat /opt/backups/zmigrate/distributionlist.txt`; do zmprov gdlm $i > /opt/backups/zmigrate/distributionlist_members/$i.txt ;echo "$i"; done

Export email accounts’ passwords

zimbra@mail:/opt/backups/zmigrate$ mkdir userpass
zimbra@mail:/opt/backups/zmigrate$ 
for i in `cat emails.txt`; do zmprov  -l ga $i userPassword | grep userPassword: | awk '{ print $2}' > userpass/$i.shadow; done

Export User Data – All user display name

zimbra@mail:/opt/backups/zmigrate$ mkdir userdata
zimbra@mail:/opt/backups/zmigrate$ 
for i in `cat emails.txt`; do zmprov ga $i  | grep -i Name: > userdata/$i.txt ; done

Step-2

Transfer Data From Old Server To New Server

Again Create a directory and set the necessary permissions in the new server.

root@mail:~#mkdir -p /opt/backups/zmigrate
root@mail:~#chown zimbra.zimbra /opt/backups/zmigrate
root@mail:~# cd /opt/backups/zmigrate
root@mail:/opt/backups/zmigrate# su zimbra

Now you have all required information except email data in the OLD server. Transfer them to the new server. You can use rsync or any other tool to transfer these data. For example:

[In OLD Server]
rsync -avp -e /opt/backups/zmigrate/* root@new_server_ip:/opt/backups/zmigrate/* 

Step-3

Import User Data To the New Server

Import all transferred data into the new server using the following processes.

Email migration steps-3

Follow the below-mentioned process in the NEW server.

Restore all domains

zimbra@mail:/opt/backups/zmigrate$for i in `cat /opt/backups/zmigrate/domains.txt `; do  zmprov cd $i zimbraAuthMech zimbra ;echo $i ;done

Create/Restore all email accounts with old passwords and user data in the NEW server

[Create below mentioned script and execute it]
#!/bin/bash
#Script for creating the email accounts createacct.sh
USERPASS="/opt/backups/zmigrate/userpass"
USERDATA="/opt/backups/zmigrate/userdata"
USERS="/opt/backups/zmigrate/emails.txt"
for i in `cat $USERS`
do
givenName=$(grep givenName: $USERDATA/$i.txt | cut -d ":" -f2)
displayName=$(grep displayName: $USERDATA/$i.txt | cut -d ":" -f2)
shadowpass=$(cat $USERPASS/$i.shadow)
tmpPass="CHANGEme"
zmprov ca $i CHANGEme cn "$givenName" displayName "$displayName" givenName "$givenName"
zmprov ma $i userPassword "$shadowpass"
done

This script will create all email addresses with their existing display name and password in the new server.

Recreate distribution list

zimbra@mail:/opt/backups/zmigrate$ for i in `cat distributionlist.txt`; do zmprov cdl $i ; echo "$i -- done " ; done

Restore distribution list members as per previous arrangements

[Create below mentioned script and execute it]
#!/bin/bash
# add all members to each of these distribution lists
for i in `cat distributionlist.txt`
do
          for j in `grep -v '#' distributionlist_members/$i.txt |grep '@'`
          do
          zmprov adlm $i $j
          echo " $j member has been added to list $i"
          done
 
done

This script will create all distribution lists with their existing members.

Step-4

Service Migration From Old Server To New Server

So far, we have exported all user information from the OLD server to the NEW server. So now we can change necessary DNS records so that the NEW server can be the active email server.

Change DNS records to make the NEW server an active server.

As soon as DNS records propagate, all users can log in to their email account using their existing credentials. But in their account, there will be no previous data. Now we will work to transfer email data.

Step-5

Email Data Migration

Export all email data from OLD server

zimbra@mail:/opt/backups/zmigrate$ mkdir MBOX
zimbra@mail:/opt/backups/zmigrate/MBOX$for email in `cat /opt/backups/zmigrate/emails.txt`; do zmmailbox -z -m $email getRestURL '/?fmt=zip' > $email.zip ; echo $email ; done

Step-6

Transfer Email Data to New Server
Transfer these data from the OLD server to the NEW server using rsync or any other tool.

Step-7

Import All Email Data To The NEW Server

zimbra@mail:/opt/backups/zmigrate/MBOX$for i in `cat /opt/backups/zmigrate/emails.txt`; do zmmailbox -z -m $i -t 0 postRestURL "/?fmt=zip&resolve=skip" /opt/backups/zmigrate/MBOX/$i.zip ; echo "$i -- finished "; done

After finishing this task, all users will get their previous email data in their email accounts.

As you can see from this method, it is platform-independent. Also, it does not transfer OLD server settings to the new server. You have to set all settings as per previous arrangements manually in the new server.

This is a customized manual method of server migration. But if you think your server infrastructure is a bit complex to manage and need enterprise expertise to help you migrate, you can check Zextras Suite.

So this is it. In the next article, we will discuss another method of migration.

Till then, stay safe.
Have a good day.

:slight_smile:
Download Zextras Suite for Zimbra OSE

Post your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Cloud computing & data sovereignty for dummies: What's the cloud? | Blog
Security vs. Privacy: What's The Difference? | Blog