Zimbra Granular Mailboxes Backup and Automatic Restore with Bacula and bpipe Plugin

The Zimbra server must have the Bacula client installed and configured, and the following script must be on the same machine. The script lists all Zimbra email boxes (zmprov -l gaa) and backs up each of them directly to Bacula through the bpipe plugin.

The process is automatic when restoring the mailbox. Messages, calendar events, and all other user items are automatically restored to Zimbra. Existing similar items are not overwritten (skip).

The script foresees Incremental levels (last 2 days of modifications in the boxes); Differential (last 7 days); and Full (the whole box). You can modify these values in the script itself.

The automatic restore requires some disk space on the Zimbra server because of a postRestURL command limitation that does not allow data to be read directly from the FIFO.

#!/bin/bash
#
# Autoria: Heitor Faria (Copyleft: all rights reversed).
# Testado por: xxxx
#
# Deve ser chamado no sub-recurso INCLUDE do FileSet do bacula-dir.conf, referente ao backup do cliente instalado na máquina do Zimbra (por exemplo):
#
# Plugin = "\\|/etc/bacula/bpipe_zimbra.sh %l"
#

level=$1

if [ $level == Incremental ]
then
yesterday=$(date +"%m-%d-%Y" --date="2 days ago")
query="&query="after:$yesterday""
fi

if [ $level == Differential ]
then
yesterday=$(date +"%m-%d-%Y" --date="7 days ago")
query="&query="after:$yesterday""
fi

zimbra_command="/opt/zimbra/bin/zmmailbox -z -m"

for zimbra_user in $(/opt/zimbra/bin/zmprov -l gaa); do
echo "bpipe:/var/$zimbra_user.tar:$zimbra_command $zimbra_user -t 0 getRestURL '/?fmt=tar$query':dd of=/tmp/$zimbra_user.tar && $zimbra_command $zimbra_user -t 0 postRestURL -i '//?fmt=tar&resolve=skip' /tmp/$zimbra_user.tar"
done

Screenshots

Zimbra Granular Mailboxes Backup and Automatic Restore with Bacula and bpipe Plugin 1 Zimbra Granular Mailboxes Backup and Automatic Restore with Bacula and bpipe Plugin 2

Disponível em: enEnglish

Leave a Reply

Close Menu