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 -f /home/lbkp/zimbra/{ldap*,mysql*}
rm -rf /home/lbkp/zimbra/exports/ rm -rf /home/lbkp/zimbra/exports/
# Remove snapshot mount point # 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 source /opt/zimbra/bin/zmshutil
zmsetvars zmsetvars
echo 'Starting Zimbra backup'
{% if 'ldap' in zcs_enabled_components %} {% if 'ldap' in zcs_enabled_components %}
echo 'Dumping LDAP database'
# Dump ldap data # Dump ldap data
/opt/zimbra/common/sbin/slapcat \ /opt/zimbra/common/sbin/slapcat \
-F /opt/zimbra/data/ldap/config \ -F /opt/zimbra/data/ldap/config \
@ -19,6 +23,7 @@ zmsetvars
{% if 'mailbox' in zcs_enabled_components %} {% if 'mailbox' in zcs_enabled_components %}
# Dump MySQL data # Dump MySQL data
echo 'Dumping MySQL database'
/opt/zimbra/common/bin/mysqldump \ /opt/zimbra/common/bin/mysqldump \
--user=root \ --user=root \
--password=$mysql_root_password \ --password=$mysql_root_password \
@ -31,13 +36,20 @@ zmsetvars
OLDIFS=$IFS OLDIFS=$IFS
IFS=$'\n' IFS=$'\n'
for MAILBOX in $(/usr/local/bin/zmprov getQuotaUsage $(hostname --fqdn) | awk '{ print $1}'); do 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 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"') 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 if echo $DIR | grep -qiP '\([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}:\d+\)$'; then
continue continue
fi fi
TYPE=$(echo $LINE | perl -ne 'm/\s*\d+\s+(\w{4})\s+\d+\s+\d+\s+(\/.*)/ && print "$1\n"') 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 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) mkdir -p /home/lbkp/zimbra/exports/$MAILBOX/$(dirname $DIR)
fi fi
if [ "$TYPE" == "appo" -o "$TYPE" == "task" ]; then if [ "$TYPE" == "appo" -o "$TYPE" == "task" ]; then
@ -50,6 +62,7 @@ done
IFS=$OLDIFS IFS=$OLDIFS
{% endif %} {% endif %}
# Try to snapshot Zimbra tree # 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