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: pt-brPortuguês (Portuguese (Brazil)) enEnglish esEspañol (Spanish)

This Post Has 3 Comments

  1. A bit rough. The fileset is even missing the level argument.
    It should show *all* config elements involved.
    It should show a completed backup and a completed restore.

    If I may say, you have unique content, much better than many other sources, but please test your examples.

    1. Hello Dark,

      The level is the %l (Bacula character substitution):

      /etc/bacula/bpipe_zimbra.sh %l

      Regards,

      1. Hey 😉
        I found that too, it was in the code. But please fix the examples if you can.
        I’m still trying to make the restore work and it’s really hard with the missing info
        (you’re a genius for figuring all that out yourself)

Leave a Reply

Close Menu