Update to 2021-11-22 10:00

master
Daniel Berteaud 3 years ago
parent 1602d96a32
commit a817d48eed
  1. 8
      roles/zimbra/templates/post_backup.sh.j2
  2. 17
      roles/zimbra/templates/pre_backup.sh.j2

@ -1,7 +1,11 @@
#!/bin/bash -e
#!/bin/sh
set -eo pipefail
echo 'Removing Zimbra database dumps'
rm -f /home/lbkp/zimbra/{ldap*,mysql*}
rm -rf /home/lbkp/zimbra/exports/
# Remove snapshot mount point
systemd-cat /opt/zimbra/bin/zmbh --post --shutdown=ldap --verbose --mount=/home/lbkp/zimbra/mount
echo 'Cleanup backup mount point and snapshot'
/opt/zimbra/bin/zmbh --post --shutdown=ldap --verbose --mount=/home/lbkp/zimbra/mount

@ -7,7 +7,11 @@ mkdir -p /home/lbkp/zimbra/mount
source /opt/zimbra/bin/zmshutil
zmsetvars
echo 'Starting Zimbra backup'
{% if 'ldap' in zcs_enabled_components %}
echo 'Dumping LDAP database'
# Dump ldap data
/opt/zimbra/common/sbin/slapcat \
-F /opt/zimbra/data/ldap/config \
@ -19,6 +23,7 @@ zmsetvars
{% if 'mailbox' in zcs_enabled_components %}
# Dump MySQL data
echo 'Dumping MySQL database'
/opt/zimbra/common/bin/mysqldump \
--user=root \
--password=$mysql_root_password \
@ -31,13 +36,20 @@ zmsetvars
OLDIFS=$IFS
IFS=$'\n'
for MAILBOX in $(/usr/local/bin/zmprov getQuotaUsage $(hostname --fqdn) | awk '{ print $1}'); do
echo ''
echo "Cheking contact and calendar folders for $MAILBOX"
for LINE in $(/usr/local/bin/zmmailbox -z -m $MAILBOX -t 0 getAllFolders); do
# Skip folders whose ID indicates it's a shared folder
if echo $LINE | grep -qiP '^\s*[a-z0-9]{8}\-[a-z0-9]'; then
continue
fi
DIR=$(echo $LINE | perl -ne 'm/\s*\d+\s+(\w{4})\s+\d+\s+\d+\s+(\/.*)/ && print "$2\n"')
if echo $DIR | grep -qiP '\([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}:\d+\)$'; then
continue
fi
TYPE=$(echo $LINE | perl -ne 'm/\s*\d+\s+(\w{4})\s+\d+\s+\d+\s+(\/.*)/ && print "$1\n"')
if [ "$TYPE" == "appo" -o "$TYPE" == "task" -o "$TYPE" == "cont" ]; then
echo "Exporting folder $DIR (account $MAILBOX, type $TYPE)"
mkdir -p /home/lbkp/zimbra/exports/$MAILBOX/$(dirname $DIR)
fi
if [ "$TYPE" == "appo" -o "$TYPE" == "task" ]; then
@ -50,6 +62,7 @@ done
IFS=$OLDIFS
{% endif %}
# Try to snapshot Zimbra tree
systemd-cat /opt/zimbra/bin/zmbh --pre --snap-size=10G --verbose --mount=/home/lbkp/zimbra/mount --shutdown=ldap
echo ''
echo "Handle /opt/zimbra snapshot / bind mount on /home/lbkp/zimbra/mount"
/opt/zimbra/bin/zmbh --pre --snap-size=10G --verbose --mount=/home/lbkp/zimbra/mount --shutdown=ldap

Loading…
Cancel
Save