Page 1 of 1

zmmailbox export to tgz [SOLVED]

Posted: Fri Aug 28, 2015 10:42 am
by kilrathi
I've been running into some problems exporting my users mailboxes to tgz format via command line.  I've dug through the forums and read all the guides about how to export with zmmailbox.  After trial and error I figured out what I've been doing wrong.  I thought i would share the information in case anyone else was running into similar problems.


First Issue:
Command used:
/opt/zimbra/bin/zmmailbox -z -m user@domain2.net getRestURL “//?fmt=tgz”
Error:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid uri 'https://host.domain2.net/home/user@doma ... 9C?fmt=tgz”': Invalid query
Solution:
I am running a split dns.  In my case my user's mailbox was part of domain2.  zmmailbox was assuming my server address was the same as my user's domain.  IE domain2.net.  This is wrong.  It should have been domain1.net.  I had to modify zmmailbox to use the correct url.  (Please note ssl is forced on my server.  If you do not force ssl its http instead of https)
/opt/zimbra/bin/zmmailbox -z -m user@domain2.net getRestURL -u "https://host.domain1.net" “//?fmt=tgz”

Second Issue:
Command used:
/opt/zimbra/bin/zmmailbox -z -m user@domain2.net getRestURL -u "https://host.domain1.net" “//?fmt=tgz”

Error:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid uri 'https://host.domain1.net/home/user@doma ... 9C?fmt=tgz”': Invalid query
Solution:
It seems a simple answer now.  You *MUST* be the zimbra user to run this.  Doesn't work as root or any other user.  I wasted 30mins on this one.  Don't fall into the trap.  


After I figured out what happened with those two big problems I was ready to export all my users.  I wrote a fairly simple bash script to export them all for me in a batch.  I thought I would share that as well.

Code: Select all

#!/bin/bash
for i in `zmprov gqu localhost | grep domain2.net|awk {'print $1'}`; do
    echo $i
    file=`echo $i | awk -F '@' '{print $1}'`
    /opt/zimbra/bin/zmmailbox -z -t 0 -m "${i}" getRestURL -u "https://host.domain1.net" "//?fmt=tgz" > /tmp/${file}.tgz
done
I added the -t 0 option to zmmailbox to prevent any timeout issues for users with particularly large mailboxes.  Now all the .tgz files for every user in domain2.net will be exported to /tmp
I hope this is useful for others having similar issues.