Migration of two different zimbra collaboration suite servers

Zimbra does not support migration of two different versions of Zimbra collaboration suite easily or support tool so we need to manually take everything as a backup in the old server and then transfer to new server.
Requirements :
old server: SSH login with root user
Admin log in as a Zimbra user
Enough Hard disk space to store all backups
New server :
Install the Zimbra suite you want
make sure to set your new servers hostname same as the old one.
Need ssh login as a root user
Zimbra admin logins
Enough HDD space to store backups from old Zimbra server
Do this in both old and new server
cd /
mkdir backups
cd backups
mkdir zmigrate
cd ..
cd ..
chown zimbra:zimbra -R backups
cd /backups/zmigrate
su – zimbra
Perform all operation as a zimbra user else you will encounter error.
Now taking backup of all data from old server

1. Find all domains

cd /backups/zmigrate
zmprov gad > domains.txt
cat domains.txt

2. Find all admin accounts

zmprov gaaa > admins.txt
cat admins.txt

3. Find all email accounts

zmprov -l gaa > emails.txt
cat emails.txt
Please remove all the email accounts from the file /backups/zmigrate/emails.txt with a starting words like spam, virus, ham, galsync .

4. Get all distribution lists

zmprov gadl > distributionlist.txt
cat distributionlist.txt

5. Get all members in distribution lists

mkdir distributionlist_members
for i in cat distributionlist.txt; do zmprov gdlm $i > distributionlist_members/$i.txt ;echo “$i”; done
cat distributionlist_members/tech@mail.serverhelper.ml.txt
distributionList tech@mail.serverhelper.ml memberCount=2

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@mail zmigrate]$ mkdir userpass
[zimbra@mail zmigrate]$ for i in `cat emails.txt`; do zmprov  -l ga $i userPassword | grep userPassword: | awk '{ print $2}' > userpass/$i.shadow; done

7. Backup all user names, Display names and Given Names

Zimbra will accept Names and Display names in email accounts during account creation. So we need to restore those data too. We will create a directory called user data/ which contains these details of each of those email accounts:
[zimbra@mail zmigrate]$ mkdir userdata
[zimbra@mail zmigrate]$ for i in `cat emails.txt`; do zmprov ga $i  | grep -i Name: > userdata/$i.txt ; done

8. Now backup all email account

This will take some time to take the 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 these files to transfer email accounts.
[zimbra@mail zmigrate]$ for email in `cat /backups/zmigrate/emails.txt`; do  zmmailbox -z -m $email getRestURL '/?fmt=tgz' > $email.tgz ;  echo $email ; done
This tgz files contains
  • Mail
  • 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:

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 subfolder called alias/ for storing the backup of Alias.
mkdir -p alias/
[zimbra@mail zmigrate]$ for i in `cat emails.txt`; do zmprov ga  $i | grep zimbraMailAlias |awk '{print $2}' > alias/$i.txt ;echo $i ;done
Some of your email accounts don’t have an alias. So the above-created files may be an empty file. Remove those empty files as follows,’
[zimbra@mail zmigrate]$ find alias/ -type f -empty | xargs -n1 rm -v 
removed 'alias/kailash@geekybum.com.txt'
removed 'alias/kailash@bumserver.ga.txt'
removed 'alias/kailash@serverguy.ml.txt'

10. Now Backup all email signatures

Please use the following script to backup all signatures of email accounts.

mkdir signatures
for i in `cat emails.txt`; do
zmprov ga $i zimbraPrefMailSignatureHTML > /tmp/signature;
sed -i -e "1d" /tmp/signature ;
sed 's/zimbraPrefMailSignatureHTML: //g' /tmp/signature > signatures/$i.signature ;
rm -rf /tmp/signature;
`zmprov ga $i zimbraSignatureName > /tmp/name` ;
sed -i -e "1d" /tmp/name ;
sed 's/zimbraSignatureName: //g' /tmp/name > signatures/$i.name ;
rm -rf /tmp/name ;

11. Backup all email account filters

The email backup doesn’t have the email filters. So it needs to be backed up manually. To download all email accounts filters. Please use the following scripts
# Backup filters of all email accounts
mkdir filter/
for i in `cat emails.txt`; do
zmprov ga $i zimbraMailSieveScript > /tmp/filter
sed -i -e "1d" /tmp/filter
sed 's/zimbraMailSieveScript: //g' /tmp/filter > filter/$i.filter
rm -f /tmp/filter
echo "Filter downloaded for .... $i"

12 Rsync folder to a new server

Now we have all the required data to do the migration process. As a summery :
  • /backups/zmigrate – Have all the backups stored
  • /backups/zmigrate/domains.txt – Contains the domains names
  • /backups/zmigrate/emails.txt – Contains the list of email accounts
  • /backups/zmigrate/distributinlist.txt – Contains the distribution lists
  • /backups/zmigrate/distributinlist_members – Contains the members in each of your distributions
  • /backups/zmigrate/userpass – Contains the encrypted password of your email accounts
  • /backups/zmigrate/userdata – contains the email accounts user information
  • /backups/zmigrate/alias – Contains all the aliases of your email accounts
Also the parent folder /backups/zmigrate contains a lot of zip file which are the data inside emails.
Now rsync the files as follows,
[zimbra@mail zmigrate]$ rsync -avhe 'ssh -p 22' /backups/zmigrate/ username@newserverip:/home/

5. Restore in new server

So after finishing the rsync process , we need to restore this in your new server as follows:
All this operations must be carried out as zimbra sudo user itself. Don’t use root account to store the backups
[root@zimbra ~]# su - zimbra

5.1 Restore all domains

Now create all the domains that we have from the file /backups/zmigrate/domains.txt
[zimbra@zimbra zmigrate]$ for i in `cat /backups/zmigrate/domains.txt `; do  zmprov cd $i zimbraAuthMech zimbra ;echo $i ;done
You can also verify the domains created from the zimbra admin panel too

5.2 Create email accounts and set the old password

We need to create the email accounts for storing the mails. We also need to set the old passwords too. We already collected the account info and passwords.
To Create email accounts and restore passwords . Please use the following script to create it
#Scrit for creating the email accounts createacct.sh
for i in `cat $USERS`
givenName=$(grep givenName: $USERDDATA/$i.txt | cut -d ":" -f2)
displayName=$(grep displayName: $USERDDATA/$i.txt | cut -d ":" -f2)
shadowpass=$(cat $USERPASS/$i.shadow)
zmprov ca $i CHANGEme cn "$givenName" displayName "$displayName" givenName "$givenName"
zmprov ma $i userPassword "$shadowpass"

5.3 Restore email accounts

Now we are going to restore the emails from the Zip file. This process may take some hours. So it will be good to run behind “screen” command.
[zimbra@zimbra zmigrate]$ for i in `cat /backups/zmigrate/emails.txt`; do zmmailbox -z -m $i postRestURL "/?fmt=tgz&resolve=skip" /backups/zmigrate/$i.tgz ;  echo "$i -- finished "; done
gm@fun.com -- finished
forest@fun.com -- finished

5.4 Now recreate the distribution lists

It is time to recreate all the distribution lists as follows.
[zimbra@zimbra zmigrate]$ for i in `cat distributinlist.txt`; do zmprov cdl $i ; echo "$i -- done " ; done
budgetrtodomainusers@fun.com -- done

5.5 Restore the distribution lists

After creating the distribution lists we need to add all the members inside the distribution lists. We have the distribution lists in the folder distributinlist_members/ and the list is in distributionlist.txt file. Please use the following small script to restore the distribution lists.
[zimbra@zimbra zmigrate]$ cat restoredist.sh 
# add all memebers to each of these distribution lists
for i in `cat distributinlist.txt`
for j in `grep -v '#' distributinlist_members/$i.txt |grep '@'`
zmprov adlm $i $j
echo " $j member has been added to list $i"


5.6 Restore Alias accounts

Please use the following script to restore alias. This will add all the aliases in your email accounts.
for i in `cat /backups/zmigrate/emails.txt`
if [ -f "alias/$i.txt" ]; then
for j in `grep '@' /backups/zmigrate/alias/$i.txt`
zmprov aaa $i $j
echo "$i HAS ALIAS $j --- Restored"

5.7 Restore Email Signatures

No please use the following script to restore email signatures
for i in `cat emails.txt`; do
zmprov ma $i zimbraSignatureName "`cat signatures/$i.name`";
zmprov ma $i zimbraPrefMailSignatureHTML "`cat signatures/$i.signature`";
zmprov ga $i zimbraSignatureId > /tmp/firmaid; sed -i -e "1d" /tmp/firmaid;
firmaid=`sed 's/zimbraSignatureId: //g' /tmp/firmaid`;
zmprov ma $i zimbraPrefDefaultSignatureId "$firmaid";
zmprov ma $i zimbraPrefForwardReplySignatureId "$firmaid";
rm -rf /tmp/firmaid;
echo $i "done!";

5.8 Restore Email Filters

You may use the following scripts to restore all your email accounts filters
for i in `cat emails.txt`; do
zmprov ma $i zimbraMailSieveScript "`cat filter/$i.filter`";
echo "Filter Restore for account ... $i";


6. Conclusion

So now we migrated all our email accounts. It is time for DNS change. You need to shut down the old zimbra services and change the DNS. After that send some test emails and make sure everything is working fine. Next step is to secure your zimbra server. You need to install ssl certificates and firewall in your new zimbra server. Now you have a new server with new packages and files with the same old email accounts and its data.

7. References


Leave a Comment

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

To Resolve this issue at just 5$ from ServerExpert


For Hosting please visit Hostingwebsite.io

You have Successfully Subscribed!

Open chat