Zimbra mailbox import/export and migration of e-mail filter rules

Zimbra has a fantastically useful built in system for exporting an entire mailbox, including the contents of the entire e-mail inbox, calendar, address book and briefcase ready to be imported on another Zimbra server either via the web interface or using zmmailbox from the command line. This makes migrating mailboxes between separate Zimbra installations incredibly easy.

You can export a chosen mailbox from the source Zimbra server with:

zmmailbox -z -m user@test.com getRestURL “//?fmt=tgz” > /tmp/user_test.com.tar.gz

And then import it into the destination server with:

zmmailbox -z -m user@test.com postRestURL “//?fmt=tgz&resolve=reset” /tmp/user_test.com.tar.gz

You need to make sure that the target account exists before attempting to import the archive on the destination server. Using the “reset” resolve method will ensure that everything is wiped from the target account before importing from the archive.

Simply replace “tgz” with “zip” in order to chose between the two archive formats when importing and exporting, making sure to use the right one on the import!

If you want to download a copy of an account from your browser, just visit the appropriate URL (e.g. http://mail.test.com/home/user/?fmt=tgz where “user” is the account’s username) or use the nice Import/Export GUI in the Zimbra preferences tab, which also gives you the option to upload and import an archive.

The Zimbra preference interface to the export function also allows you to easily specify advanced settings such as date ranges, search filters or limiting the export to a certain data type such as calendar items.

The one problem with Zimbra’s import/export system is that user settings such as signatures and mail filters which are stored in an account’s LDAP attributes aren’t included in the exported data. It’s easy enough to manually move signatures between servers, but anything more than a couple of mail filters can be tedious to manually re-create.

Luckily, you can get the information you need from the zimbraMailSieveScript attribute for a chosen account using the zmprov command line utility:

zmprov ga user@test.com zimbraMailSieveScript

This should give you something a copy of your mail filter rules in the sieve format, for example:

require [“fileinto”, “reject”, “tag”, “flag”];

# No Reply
if anyof (header :contains [“to”] “noreply@test.com”) {
fileinto “Inbox/No Reply”;
stop;
}

You can then easily re-import this into LDAP on the destination server by placing single quotes around the result and using “zmprov ma”:

zmprov ma user@test.com zimbraMailSieveScript ‘require [“fileinto”, “reject”, “tag”, “flag”];

# No Reply
if anyof (header :contains [“to”] “noreply@test.com”) {
fileinto “Inbox/No Reply”;
stop;
}’

You can of course apply the same technique to other account details if you wish, you just need to know the appropriate LDAP attribute, such as zimbraPrefMailSignatureHTML for your signature or zimbraPrefOutOfOfficeReply for your out of office auto reply.

Share

1 Response

Leave a Reply