software

Recovering messages in Zimbra Open Source Edition

2 min read

Zimbra v7 Open Source Edition does not come with any backup tool. So, after backing up to a backup server with rsync (steps I will post later), it is important to be sure how to recover the files if an account’s messages ever need to be restored. The messages are in the /opt/zimbra/store folder, which contains two subfolders, “0” and “incoming”. The messages are in the “0” folder, and inside it there are several folders, also numbered, one for each user. First problem… which folder belongs to the user in question? The solution I found was to follow these steps: Switch to the zimbra user:

text
su - zimbra

Find the MySQL password:

text
zmlocalconfig -s | grep mysql | grep password

Several lines should appear, one of them being the MySQL root password. Next, find the user’s id:

text
mysql -u root -p

Enter the password obtained earlier.

text
mysql>use zimbra;<br>mysql>SELECT id FROM mailbox where comment like '%<zimbrauser>%';<br>

We get an id that matches the name of the folder (a number) containing the messages. With this we know which folder belongs to the user, and by going into it we can get the messages. Second problem… which folder in the user’s list does each numbered subfolder correspond to? I don’t know 🙂 “trial and error”; what we can do is restore the messages into the user’s account. See the link http://www.zimbra.com/forums/installation/12617-recover-data-store-folders.html, which has some suggestions that may help. What I did was copy the messages from the backup server back to the Zimbra server, into the /opt/zimbra/backup folder, and then import the messages into the user’s account: Assuming the subfolders are in /opt/zimbra/backup/<userid>/, I used the following commands:

text
zmmailbox adminAuthenticate <adminuser> <password><br>zmmailbox -zadmin

Select the mailbox to restore into

text
selectMailbox user@domain

I created a folder for each of the folders I wanted to restore:

text
mbox>createFolder /Recovery<folder number><br>mbox>addMessage /Recovery<folder number> backup/<userid>/<folder number><br>

I repeated createFolder and addMessage for each of the folders I wanted to restore. to leave

text
exit

until you are out of the console/session. In the end the user will have the backed-up messages in those folders and can do whatever they want with them. Note: watch out for user quotas, if they are set, so the limit is not reached. If that is a problem, the best option is to create a new user, import the messages into it, sort them out there and, if needed, sync them with imapsync (or any other tool that syncs IMAP accounts).

#zimbra