Migrate Zimbra from 32bit to 64bit  • • •  回顾会议的几个问题       all posts in Archive

Zimbra Empty Mailbox Detector

In last blog we already talking about Migrate Zimbra from 32bit to 64bit , however Zmmailbox is quite slow when export and import when you have greate many mailboxes. Each mailbox will cost 5 second, so when you have for example more than 10000 account, that would be a disaster. In Zimbra official documentation, it also mentioned, when migrate 30GB data, will cost 5 days and night.

There would be a few ways to accelerate the speed, but it always be a good idea to find out how many data you are facing. The empty mailbox you wont need to migrate mailbox. That's why we can create a script to find out the list of non-empty mailbox account.

Still, I'm using Python to do it.

import os

# Get all accounts in zimbra and write into file
accounts=os.popen('su - zimbra -c "zmprov -l gaa"').read()
file = open('/root/zimbra.all.accounts.txt', 'w')
file.write(accounts)
file.close()

# Iterate to find account with mailbox
wholeAccounts= open('/root/zimbra.all.accounts.txt')
accountsWithMailBox = open('/root/zimbra.accounts.with.mailbox.txt','a')

for line in wholeAccounts:
        try:
                cmd = 'su - zimbra -c "zmmailbox -z -m %s gms"' % line.strip('\n')
                sizeofmailbox = os.popen(cmd).read().strip('\n')

                if sizeofmailbox <> '0 B':
                        print '%s is not empty and the size is %s ' % (line.strip('\n'), sizeofmailbox)
                        accountsWithMailBox.write(line)
                else:
                        print 'skip %s ' % line.strip('\n')
        except:
                print 'encounter exception with %s ' % line.strip('\n')

wholeAccounts.close()
accountsWithMailBox.close()