Restore the Zimbra Mail Server from Backup

Purpose

Zimbra Email server is hosted on VPS. VPS backup generate backup snapshot (incremental) after every 1 hour with retention of 2 weeks. We need to implement routine that can generate data/database/LDAP backup to some external system. This backup can serve us in case of disaster on VPS.

Export ldap and mysql conent 

Create directory in the tmp folder and in this directory we will export the ldap and mysql content. Below are the steps for exporting the ldap and Mysql. All step perform with Zimbra user.
·         #su - zimbra

·         #mkdir /tmp/migration (This directory rights are owned by Zimbra user)

·         #/opt/zimbra/libexec/zmslapcat  /tmp/migration
  • Below are the steps of exporting the Mysql content in which databases and list of accounts are included
#source /opt/zimbra/bin/zmshutil; zmsetvars

#/opt/zimbra/mysql/bin/mysqldump -u root --password=$mysql_root_password
socket=$mysql_socket --all-databases --single-transaction >>
/tmp/migration/mysqlinfo.sql

#mysql --batch --skip-column-names -e "show databases" | grep -e mbox -e zimbra >
/tmp/migration/mysql.db.list

All the important data has been exported in migration folder, now the procedure of importing them are below listed.

Install ZCS on New Machine (Importing data)

Make sure to install the same ZCS package/version it is running on production server. After the install, make sure you use the same ldap and mysql passwords from the production machine. To view the passwords from the production machine, run the following command.

·       #zmlocalconfig -s | grep pass | grep -e ldap -e mysql (Run On Production)

So we have to change the ldap and mysql passwords. Below are the commands.(New machine, By Zimbra user)

·       #zmldappasswd Prod_Pass         (ldap )
·       #zmldappasswd -r Prod_Pass      (ldap root )
·       #zmmypasswd Prod_Pass           (Mysql )
·       #zmmypasswd -root Prod_Pass   (Mysql root )

After the password changes, restart ZCS services on the new machine.
Copy the ldap and mysql data from production server by rsync command.

·   #rsync -av -e ssh root@10.10.202.X:/tmp/migration /tmp/production
  • Drop mysql DB's, below are the command
     source /opt/zimbra/bin/zmshutil; zmsetvar for db in `mysql --batch --skip-column-names -e "show databases" | grep -e ^mbox -e zimbra`; do mysql -u root password=$mysql_root_password -e \ "drop database $db"; echo -e "Dropped $db"; done

  • Create the necessary DB's

for db in `cat /tmp/migration/mysql.db.list`; do mysql -e "create database $db character set utf8"; echo "created $db"; done
  • Import production mysql data into the new machine db
·         mysql < /tmp/migration/mysqlinfo.sql
  • Import ldap data from the new machine
·         #ldap stop
·         #cd /opt/zimbra/data/ldap
·         #mv hdb OLD.hdb
·         #mkdir hdb; cd hdb;mkdir db logs
·         #/opt/zimbra/openldap/sbin/slapadd -q -b "" -F /opt/zimbra/data/ldap/config -cv -l /tmp/migration/ldap.bak
·         #ldap start
  • Copy store and index files from the production machine to the new machine
·         #rm -rf /opt/zimbra/store/*
·         #rsync -av -e ssh root@10.10.202.X:/opt/zimbra/store/ /opt/zimbra/store/
·         #rm -rf /opt/zimbra/index/*
·         #rsync -av -e ssh root@10.10.202.X:/opt/zimbra/index/ /opt/zimbra/index/
·         #zmcontrol stop
·         #zmcontrol start

After this all process we can successfully import our accounts and their mails with all production configurations.

Note: While copying the commands paste it under notepad rearrange it and remove extra spaces



Comments

  1. Let's try out this and hope I can recover my mail server

    ReplyDelete

Post a comment

Please give your review or ask question ?