Difference between revisions of "CentOS 7.x Zimbra backup and restore"
m |
m |
||
Line 37: | Line 37: | ||
# Configure rsnapshot as follows: | # Configure rsnapshot as follows: | ||
#:<pre> | #:<pre> | ||
#:: backup_script /usr/bin/ssh root@172.26.2.54 '/opt/take_zimbra_ldap_backup.sh' mail. | #:: backup_script /usr/bin/ssh root@172.26.2.54 '/opt/take_zimbra_ldap_backup.sh' mail.sbarjatiya.com/.ignore1/ | ||
#:: backup_script /usr/bin/ssh root@172.26.2.54 '/opt/take_zimbra_mysql_backup.sh' mail. | #:: backup_script /usr/bin/ssh root@172.26.2.54 '/opt/take_zimbra_mysql_backup.sh' mail.sbarjatiya.com/.ignore2/ | ||
#:: backup root@172.26.2.54:/opt/ mail.gbb.co.in/ +rsync_long_args=--exclude=/opt/zimbra/data/ldap/ --sparse | #:: backup root@172.26.2.54:/opt/ mail.gbb.co.in/ +rsync_long_args=--exclude=/opt/zimbra/data/ldap/ --sparse | ||
#:</pre> | #:</pre> |
Revision as of 11:30, 1 August 2020
<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. For full backup using rsnapshot use:
- Create folder for taking ldap backup using:
- mkdir /opt/zimbra-ldap-backup
- chown -R zimbra:zimbra /opt/zimbra-ldap-backup
- Create ldap_backup_script on zimbra server at /opt/take_zimbra_ldap_backup.sh with following contents:
- #!/bin/bash
- 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/"
- chmod +x /opt/take_zimbra_ldap_backup.sh
- Create folder for taking mysql backup using:
- mkdir /opt/zimbra-mysql-backup
- chown -R zimbra:zimbra /opt/zimbra-mysql-backup
- Create '/opt/take_zimbra_mysql_backup.sh' with following contents:
- #!/bin/bash
- export backup_dir="/opt/zimbra-mysql-backup"
- su - zimbra -c '
- source /opt/zimbra/bin/zmshutil;
- zmsetvars;
- /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
- chmod +x /opt/take_zimbra_mysql_backup.sh
- Configure rsnapshot as follows:
- backup_script /usr/bin/ssh root@172.26.2.54 '/opt/take_zimbra_ldap_backup.sh' mail.sbarjatiya.com/.ignore1/
- backup_script /usr/bin/ssh root@172.26.2.54 '/opt/take_zimbra_mysql_backup.sh' mail.sbarjatiya.com/.ignore2/
- backup root@172.26.2.54:/opt/ mail.gbb.co.in/ +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).
Refer:
- https://serverfault.com/questions/680942/backing-up-zimbra-8-0-x-data-mdb-issues
- https://rizvir.com/articles/zimbra-8-production-setup/
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>