From Notes Wiki
Jump to: navigation, search
Line 37: Line 37:
# Configure rsnapshot as follows:
# Configure rsnapshot as follows:
#::    backup_script  /usr/bin/ssh root@ '/opt/'
#::    backup_script  /usr/bin/ssh root@ '/opt/'
#::    backup_script  /usr/bin/ssh root@ '/opt/'
#::    backup_script  /usr/bin/ssh root@ '/opt/'
#::    backup  root@        +rsync_long_args=--exclude=/opt/zimbra/data/ldap/ --sparse
#::    backup  root@        +rsync_long_args=--exclude=/opt/zimbra/data/ldap/ --sparse

Latest revision as of 11:30, 1 August 2020

Home > CentOS > CentOS 7.x > Email configuration > Zimbra configuration > Zimbra backup and restore

CentOS 7.x Zimbra backup and restore

Full backup and restore of /opt/zimbra

Zimbra keeps all its required files under /opt/zimbra. A full backup of /opt/zimbra (*Esp when zimbra is not running*) contains consistent backup of email server configuration, user preferences, user emails, etc. A Linux utility such as rsnapshot can be used for full backups at required intervals. For full backup using rsnapshot use:

  1. Create folder for taking ldap backup using:
    mkdir /opt/zimbra-ldap-backup
    chown -R zimbra:zimbra /opt/zimbra-ldap-backup
  2. Create ldap_backup_script on zimbra server at /opt/ with following contents:
    rm -f /opt/zimbra-ldap-backup/*
    su - zimbra -c "/opt/zimbra/libexec/zmslapcat -c /opt/zimbra-ldap-backup/"
    su - zimbra -c "/opt/zimbra/libexec/zmslapcat /opt/zimbra-ldap-backup/"
  3. chmod +x /opt/
  4. Create folder for taking mysql backup using:
    mkdir /opt/zimbra-mysql-backup
    chown -R zimbra:zimbra /opt/zimbra-mysql-backup
  5. Create '/opt/' with following contents:
    export backup_dir="/opt/zimbra-mysql-backup"
    su - zimbra -c '
    source /opt/zimbra/bin/zmshutil;
    /opt/zimbra/common/bin/mysqldump --user=root --password=$mysql_root_password --socket=$mysql_socket --all-databases --single-transaction --flush-logs;
    ' | gzip > $backup_dir/mysqldump.sql.gz
  6. chmod +x /opt/
  7. Configure rsnapshot as follows:
    backup_script /usr/bin/ssh root@ '/opt/'
    backup_script /usr/bin/ssh root@ '/opt/'
    backup root@ +rsync_long_args=--exclude=/opt/zimbra/data/ldap/ --sparse
    Note following
    • Use tabs appropriately instead of spaces in above config for rsnapshot.conf
    • Note that we need to call backup_script before taking backup of complete /opt.
    • Also note use of --exclude=/opt/zimbra/data/ldap which is very crucial for backup to work as there is sparse file in /opt/zimbra/data/ldap/mdb/db which is quite big (80GB sparse).


Full restoration is also straightforward using:

  1. Stop zimbra services.
  2. Rename /opt/zimbra to /opt/zimbra-old if there is enough storage space. Otherwise delete /opt/zimbra
  3. Restore the backup to /opt/zimbra.
  4. If required fix permissions using
    chown -R zimbra:zimbra /opt/zimbra


Limitations of full backup

The most critical limitation of full backup is that there is no partial restore option. Either we should restore fully on a second machine and access required backup emails/accounts or we need to restore fully on production server. Ideally backups should allow restoring individual accounts or emails. This is not possible using the backup process which takes backup of /opt/zimbra as suggested above.

The backup suggested above may not be consistent unless all services are stoppped. To stop all services before backup and to start them again after backup, we need the backup window to be small. Full backup on the other hand (Based on total data) might take considerable time. Thus, there is trade-off between consistent backup and down-time. However, at any cost at least one weekly full backup after shutting down all services should be taken.

Backup and restore of individual accounts

The below is not tested on production extensively, so use with caution.

Backup of individual account is possible. A full backup of account which includes mail, contacts, calendar, tasks, briefcase, etc. using scripts available at The script assumes only one backup per day.

To setup zimbra server to use above scripts use following steps:

  1. Install required software using:
    yum -y install git python-ldap python-requests python-setuptools
  2. Setup Backup scripts using:
    cd /root
    git clone
    cd zimbra-permailbox-backup
    cp zimbra_permailbox_backup.conf /etc
    cp /usr/local/bin/
    chmod +x /usr/local/bin/
    cd /root
    git clone
    cd pynsca
    python install
  3. Edit /etc/zimbra_permailbox_backup.conf as follows:
    #Find using 'zmlocalconfig -s | grep ldap_root_password' as zimbra user <redacted>
    #Zimbra admin user password <redacted>
    #Not using so far, so no nagios configuration
    #Backup destination, should have enough space
    mailbackuptopdir: /mnt/backups/
  4. Optionally, make sure /mnt/backups exists with access to zimbra user
    mkdir /mnt/backups
    chown -R zimbra:zimbra /mnt/backups
    As such backups seem to happen directly as root, so this is not necessary
  5. Test full backup using:
    /usr/local/bin/ -b all -s
  6. List all backups of user1 using:
    /usr/local/bin/ -r '' -d list -s
    Example output is:
    [root@mail ~]# /usr/local/bin/ -r '' -d list -s
    Backup(s) for account: in /mnt/backups/
    Date: 20190214, Size: 5.8 KB
  7. To restore backup of given date use:
    /usr/local/bin/ -r '' -t '' -d 20190214 -s
    Example restore output is:
    [root@mail ~]# /usr/local/bin/ -r '' -t '' -d 20190214 -s
    Running a restore to account on using backup /mnt/backups/
    Restore complete
    Note that restore account -t need not be same as source account -r. Restoration can be done to a different account also. However, the account has to be created before restore.


Home > CentOS > CentOS 7.x > Email configuration > Zimbra configuration > Zimbra backup and restore