CentOS 7.x Zimbra backup and restore
<yambe:breadcrumb self="Zimbra backup and restore">CentOS_7.x_Zimbra_configuration|Zimbra configuration</yambe:breadcrumb>
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.
Full restoration is also straightforward using:
- Stop zimbra services.
- Rename /opt/zimbra to /opt/zimbra-old if there is enough storage space. Otherwise delete /opt/zimbra
- Restore the backup to /opt/zimbra.
- If required fix permissions using
- chown -R zimbra:zimbra /opt/zimbra
- /opt/zimbra/libexec/zmfixperms
Refer:
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 https://github.com/garithd/zimbra-permailbox-backup/wiki/Installation The script assumes only one backup per day.
To setup zimbra server to use above scripts use following steps:
- Install required software using:
- yum -y install git python-ldap python-requests python-setuptools
- Setup Backup scripts using:
- cd /root
- git clone https://github.com/garithd/zimbra-permailbox-backup.git
- cd zimbra-permailbox-backup
- cp zimbra_permailbox_backup.conf /etc
- cp zimbra_permailbox_backup.py /usr/local/bin/
- chmod +x /usr/local/bin/zimbra_permailbox_backup.py
- cd /root
- git clone https://github.com/djmitche/pynsca.git
- cd pynsca
- python setup.py install
- Edit /etc/zimbra_permailbox_backup.conf as follows:
- [auths]
- #Find using 'zmlocalconfig -s | grep ldap_root_password' as zimbra user
- mail.zimbra.sbarjatiya.com: <redacted>
- [zimbraauths]
- #Zimbra admin user password
- mail.zimbra.sbarjatiya.com: <redacted>
- [nagioshosts]
- #Not using so far, so no nagios configuration
- [backupdir]
- #Backup destination, should have enough space
- mailbackuptopdir: /mnt/backups/
- 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
- Test full backup using:
- /usr/local/bin/zimbra_permailbox_backup.py -b all -s mail.zimbra.sbarjatiya.com
- List all backups of user1 using:
- /usr/local/bin/zimbra_permailbox_backup.py -r 'user1@zimbra.sbarjatiya.com' -d list -s mail.zimbra.sbarjatiya.com
-
- Example output is:
- [root@mail ~]# /usr/local/bin/zimbra_permailbox_backup.py -r 'user1@zimbra.sbarjatiya.com' -d list -s mail.zimbra.sbarjatiya.com
- Backup(s) for account: user1@zimbra.sbarjatiya.com in /mnt/backups/mail.zimbra.sbarjatiya.com/mailboxes/
- Date: 20190214, Size: 5.8 KB
- Example output is:
- To restore backup of given date use:
- /usr/local/bin/zimbra_permailbox_backup.py -r 'user1@zimbra.sbarjatiya.com' -t 'user1@zimbra.sbarjatiya.com' -d 20190214 -s mail.zimbra.sbarjatiya.com
-
- Example restore output is:
- [root@mail ~]# /usr/local/bin/zimbra_permailbox_backup.py -r 'user1@zimbra.sbarjatiya.com' -t 'user1@zimbra.sbarjatiya.com' -d 20190214 -s mail.zimbra.sbarjatiya.com
- Running a restore to account user1@zimbra.sbarjatiya.com on mail.zimbra.sbarjatiya.com using backup /mnt/backups/mail.zimbra.sbarjatiya.com/mailboxes/20190214/user1@zimbra.sbarjatiya.com.tgz
- 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.
- Example restore output is:
Refer:
<yambe:breadcrumb self="Zimbra backup and restore">CentOS_7.x_Zimbra_configuration|Zimbra configuration</yambe:breadcrumb>