Backup of Zimbra MailBox using zmmailbox

This is a short script I use to backup the Zimbra mailbox content for my users.
This has been used on a Zimbra Collaboration Server (ZCS Open Source Edition) 7.2 installation, but should work on earlier versions as well.
I use another script to backup the whole Zimbra installation, but that might be another blog post.

#!/bin/bash -x
# Backup of Zimbra mailboxes using zmmailbox
# Restore of mailbox should be performed using:
# /opt/zimbra/bin/zmmailbox -z -m user@host postRestURL -u https://HOST "//?fmt=tgz&resolve=skip" mailbox-name-date.tgz
MailBox="user1 user2 user3 userN"
DateToday=`date -I`
for name in $MailBox
sudo -u zimbra /opt/zimbra/bin/zmmailbox -z -m $ getRestURL "//?fmt=tgz" > mailbox-$name-$DateToday.tgz

The backup files are named mailbox-user1-20120802.tgz mailbox-user2-20120802.tgz …

15 thoughts on “Backup of Zimbra MailBox using zmmailbox

  1. How do you restore a mailbox backed up this way. Saw how a while ago but can’t find the reference. Would be good to include here for completeness.

    1. Hi Renzo,

      Can you run his command on the mail server and see if that is working:
      $ sudo -u zimbra /opt/zimbra/bin/zmmailbox -z -m getRestURL “//?fmt=tgz” > usermail.tgz

      I tested it on my Zimbra 8.0 installation and it should work.

  2. Hi
    is it possible to backup zimbra mailbox by specifying “start” and “end” dates?!!

    1. Yes, it is possible using the query option.
      query=’before:”12/15/2013″ after:”10/1/2011″‘

    1. Hi Vin,

      There is probably some formatting error when you copied the script using you internet browser.
      Try to replace the code you used individually and place them in the script.

  3. Is this backup “hot”? do you have to disable access to the server for users??

    1. Hi rj, this backup is “hot” in the same way that you can perform it without stopping the server.
      The users are not affected by this backup method at all.

  4. Good news/bad news
    Good news: Got this working with a cron and a string to backup the last 7 days of activity.
    bad news: a “firedrill” (walkthrough of the restore process to a user named “firedrill” reloads the compressed mail account but on subsequent testing not all of the data is recovered.

    I have used/reused the firedrill user id more than once. Is it possible that I need to somehow purge the user account before reloading from the backup? Or, is there a switch on zmmail that indicates the backsup should be a 100% replacement for any existing content in the user accout?

    1. Hi,

      I suggest you read comment #2 about restore and the link

      Then import with:
      /opt/zimbra/bin/zmmailbox -z -m postRestURL “//?fmt=tgz&resolve=reset” /tmp/account.tgz
      The resolve= parameter has several options:
      “skip” ignores duplicates of old items, it’s also the default conflict-resolution.
      “modify” changes old items.
      “reset” will delete the old subfolder (or entire mailbox if /).
      “replace” will delete and re-enter them.
      ‘Reset’ will be a bit faster on an empty destination mailbox because it skips most dupe checks.”

Comments are closed.