A chronological documentation test project, nothing serious, really!

02 Aug 2012 Backup of Zimbra MailBox using zmmailbox

Posted by

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 …

Tags: , , , , , ,

Reader's Comments

  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.

  2. |

    Yes, you are right. I should have included a link or something for completeness.
    There is a good blog post about Zimbra mailbox backup and restore on

  3. |

    please check out this little tool i found it backups and restores mail accounts and domains, even settings.

  4. |

    When I try to do a single mailbox backup using sudo -u zimbra /opt/zimbra/bin/zmmailbox -z -m getRestURL “//?fmt=tgz” > user.tgz I get this error:
    “ERROR: service.FAILURE (system failure: GET from failed, status=501. can only handle messages/appointments/tasks/documents)”
    any Ideas??

    • |

      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.

  5. |

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

    • |

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

  6. |

    You cold try another tool like partimage using a linux live-cd.

  7. |

    While using the above script, I’m getting the below error.

    ERROR: service.FAILURE (system failure: GET from failed, status=404. no such item)

    When I run the command individually for any user, the data is backed successfully. But within the script, it fails.

    Any help would be appreciated !

    • |

      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.

  8. |

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

    • |

      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.

  9. |

    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?

    • |


      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.”