Backup and restore Zimbra

From wiki.techunit.org
Jump to: navigation, search

Backup

Create Directories

mkdir -p /path/to/backup/dir/{mysql,ldap,data}

MySQL

Make a dump of Zimbra dtatabases

source /opt/zimbra/bin/zmshutil
zmsetvars
/opt/zimbra/mysql/bin/mysqldump --user=root --password=$mysql_root_password \
--socket=$mysql_socket --all-databases --single-transaction --flush-logs > /path/to/backup/dir/mysql/dump_zimbra.sql

LDAP

su - zimbra -c "/opt/zimbra/libexec/zmslapcat /path/to/backup/dir/ldap"
su - zimbra -c "/opt/zimbra/libexec/zmslapcat -c /path/to/backup/dir/ldap"
su - zimbra -c "/opt/zimbra/libexec/zmslapcat -a /path/to/backup/dir/ldap"

Datas

  • /opt/zimbra/store
  • /opt/zimbra/index
rsync --delete -axvzKHS /opt/zimbra/{store,index} /path/to/backup/dir/data

localconfig

cp /opt/zimbra/conf/localconfig.xml /path/to/backup/dir/

Restore

Prepare new server

  • Install Zimbra : use the same version
  • Copy the backup directory
  • Set appropriate permissions
rsync -a <backup server>:/path/to/backup/dir /path/to/backup/dir
chown -R zimbra: /path/to/backup/dir

LDAP

  • Stop zimbra service and import LDAP schemas
su - zimbra -c "zmcontrol stop"
mkdir -p /backup/ldap_old
#backup default config
mv -f /opt/zimbra/data/ldap/mdb /backup/ldap_old
mv -f /opt/zimbra/data/ldap/config /backup/ldap_old
mv -f /opt/zimbra/data/ldap/accesslog /backup/ldap_old
#Recreate empty directories
mkdir -p /opt/zimbra/data/ldap/mdb/db
mkdir -p /opt/zimbra/data/ldap/config
mkdir -p /opt/zimbra/data/ldap/accesslog/db
chown -R zimbra: /opt/zimbra/data/ldap/{mdb,config,accesslog}
su - zimbra
#Import config
/opt/zimbra/libexec/zmslapadd -c /path/to/backup/dir/ldap-config.bak
/opt/zimbra/libexec/zmslapadd /path/to/backup/dir/ldap.bak
/opt/zimbra/libexec/zmslapadd -a /path/to/backup/dir/ldap-accesslog.bak

MySQL

su - zimbra
mysql.server start
source ~/bin/zmshutil
zmsetvars
mysql < /path/to/backup/dir/dump_zimbra.sql

Recreate certificates

#As root
/opt/zimbra/bin/zmcertmgr createca -new
/opt/zimbra/bin/zmcertmgr createcrt -new -days 365
/opt/zimbra/bin/zmcertmgr deploycrt self
/opt/zimbra/bin/zmcertmgr deployca
/opt/zimbra/bin/zmcertmgr viewdeployedcrt

Localconfig

  • Set old passwords values by:
    • Edit /opt/zimbra/conf/localconfig.xml
    • or
    • Use zmlocalconfig command
  • Print values:
zmlocalconfig -x -s | grep password

Start services

su - zimbra -c "zmcontrol start"

#To debug
#as root
/opt/zimbra/libexec/zmsetup.pl
/opt/zimbra/libexec/zmfixperms -extended

Elliot
techUnit's cofounder