Last active
August 17, 2023 06:44
-
-
Save igalic/9686319 to your computer and use it in GitHub Desktop.
Restore Zimbra's ldap, mysql and config from backup, as well as the store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# sources | |
# https://wiki.zimbra.com/wiki/LDAP_data_import_export | |
# http://wiki.zimbra.com/wiki/Mysql_Crash_Recovery | |
# http://wiki.zimbra.com/wiki/CLI_zmvolume | |
set -e | |
# set limits as per zmslapadd | |
ulimit -n 32768 | |
ulimit -c unlimited | |
ulimit -v unlimited | |
# utility functions | |
run_as_zimbra() { | |
chroot --userspec zimbra:zimbra / "${@}" | |
} | |
source ~zimbra/bin/zmshutil ; zmsetvars | |
export PATH=${zimbra_home}/bin:$PATH:${zimbra_home}/libexec | |
# global variables we'll use... | |
store_backup=/opt/zbackup/store | |
index_backup=/opt/zbackup/index | |
config_backup=/opt/zbackup/config | |
keystore_backup=/opt/zbackup/keystore | |
mysql_backup=/opt/zbackup/mysql/mysql_dbs.sql.gz | |
ldap_backup=/opt/zbackup/ldap | |
# Parse options... | |
case $1 in | |
-v|--verbose|--debug) verbose=--verbose | |
esac | |
cp="rsync ${verbose} -HaS" | |
## step one, stop the world. | |
/etc/init.d/zimbra stop | |
## restore mysql | |
mkdir -p ~zimbra/backup/mysql_binlog/ | |
run_as_zimbra mysql.server restart | |
databases=( $( run_as_zimbra mysql --batch --skip-column-names -u root --password=${mysql_root_password} -e "show databases" \ | |
| awk '!/(information|performance)_schema|mysql/{print $1}' ) ) | |
for db in "${databases[@]}" ; do | |
run_as_zimbra mysql ${verbose} --batch --skip-column-names -u root --password=${mysql_root_password} -e "drop database ${db};" | |
sleep 0.1; | |
done | |
gunzip < ${mysql_backup} | run_as_zimbra mysql ${verbose} --quick --batch -u root --password=${mysql_root_password} | |
run_as_zimbra mysql.server stop | |
# restore ldap.. | |
rm ${verbose} -rf ~zimbra/data/ldap/config | |
rm ${verbose} -rf ~zimbra/data/ldap/mdb | |
run_as_zimbra mkdir -p ~zimbra/data/ldap/config ~zimbra/data/ldap/mdb/db ~zimbra/data/ldap/accesslog/db | |
run_as_zimbra zmslapadd -c ${ldap_backup}/ldap-config.bak | |
run_as_zimbra zmslapadd ${ldap_backup}/ldap.bak | |
# Restore configurations.. | |
rm ${verbose} -rf ${zimbra_home}/conf | |
rm ${verbose} -rf ${zimbra_home}/.saveconfig | |
${cp} ${config_backup}/conf ${zimbra_home}/. | |
# the following / after saveconfig is important | |
${cp} ${config_backup}/saveconfig/ ${zimbra_home}/.saveconfig | |
# restore keystores | |
${cp} ${keystore_backup}/keystore ${zimbra_home}/mailboxd/etc/. | |
${cp} ${keystore_backup}/cacerts ${zimbra_home}/java/jre/lib/security/. | |
zmlocalconfig -e zimbra_uid=$( id -u zimbra) | |
zmlocalconfig -e mailboxd_keystore_password=1sGyXAm3j | |
# Restore mail store | |
# --delete delete extraneous files from dest dirs | |
${cp} --delete ${store_backup} ${zimbra_home}/. | |
${cp} --delete ${index_backup} ${zimbra_home}/. | |
zmfixperms ${verbose} --extended | |
## start | |
/etc/init.d/zimbra restart | |
# make sure compression is on | |
for id in $( run_as_zimbra zmvolume -l | awk '/Volume id:/{print $3}' ) ; do | |
run_as_zimbra zmvolume -e -id "${id}" -c true | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment