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
BackupFolder="/backup/zimbra"
MailBox="user1 user2 user3 userN"
DateToday=`date -I`
for name in $MailBox
do
sudo -u zimbra /opt/zimbra/bin/zmmailbox -z -m $name@pario.no getRestURL "//?fmt=tgz" > mailbox-$name-$DateToday.tgz
done
The backup files are named mailbox-user1-20120802.tgz mailbox-user2-20120802.tgz …
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.
Thanks!
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 http://blog.zimbra.com/blog/archives/2008/09/zcs-to-zcs-migrations.html
please check out this little tool i found http://www.zextras.com it backups and restores mail accounts and domains, even settings.
When I try to do a single mailbox backup using sudo -u zimbra /opt/zimbra/bin/zmmailbox -z -m user@server.com getRestURL “//?fmt=tgz” > user.tgz I get this error:
“ERROR: service.FAILURE (system failure: GET from https://mail.server.com.pe/home/user@domain.com/.?fmt=tgz. 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 username@pario.no getRestURL “//?fmt=tgz” > usermail.tgz
I tested it on my Zimbra 8.0 installation and it should work.
Hi
is it possible to backup zimbra mailbox by specifying “start” and “end” dates?!!
Thanks
Yes, it is possible using the query option.
query=’before:”12/15/2013″ after:”10/1/2011″‘
You cold try another tool like partimage using a linux live-cd.
While using the above script, I’m getting the below error.
ERROR: service.FAILURE (system failure: GET from https://mail.xxxxxx.co.in:443/home/test@xxxxxxx.co.in//=tgz 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.
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.
Thanks! This is exactly what I needed.
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?
Hi,
I suggest you read comment #2 about restore and the link http://blog.zimbra.com/blog/archives/2008/09/zcs-to-zcs-migrations.html
Then import with:
/opt/zimbra/bin/zmmailbox -z -m user@domain.com 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.”