Jump to content

Zimbra Restore Mails From Store Folder: Difference between revisions

From TetraWiki
No edit summary
No edit summary
Line 1: Line 1:
Zimbra Mailbox Structure
== Zimbra Mailbox Structure ==
In Zimbra, each user is assigned a unique 'mailbox ID', which links him/her to their folder in ''/opt/zimbra/store/0''.


Mails are stored in
Therefore a user with say mailbox ID '716', would have folder ''/opt/zimbra/store/0/716''. The emails are stored in '.msg' format.
In Zimbra, each user is assigned a unique 'mailbox ID', which links him/her to


For more information on the structure,
[http://wiki.zimbra.com/wiki/Account_mailbox_database_structure go here]


== The problem ==
Now this information is stored in LDAP, so if LDAP is corrupted or unrecoverable, we cannot associate the mailbox ID with the user ID.
But the store folder is intact.
== The solution ==
We will have to trace which folder belongs to which user. Since each folder belongs to a single user, it is sufficient to determine with a few emails who the inbox belongs to.
So we follow these steps to recover it:
In our case the backup store folder is ''/opt/zimbra/store.old/0''


Go to the backup store folder:
Go to the backup store folder:


  cd /opt/zimbra/store.old/0
  # cd /opt/zimbra/store.old/0
 
Save the script as 'findusers.sh', and the run the script.


Use the following script:
  #!/bin/bash
  #!/bin/bash
   
   
Line 19: Line 34:
  done
  done


This will return a list of top ten users (in '''/tmp/messagelist''') whose name is present in the 'To:' field of the messages stored.
# /opt/zimbra/store.old/0/findusers.sh
 
This will return a list of top ten users (in ''/tmp/messagelist'') whose name is present in the 'To:' field of the messages stored.
Using the output of this, we can make a good estimate of the user's folder, but this needs to be confirmed manually as well, by reading the email.
Using the output of this, we can make a good estimate of the user's folder, but this needs to be confirmed manually as well, by reading the email.


Line 35: Line 53:
  mbox agmadmin@witalsee.com> addMessage /Recovery /opt/zimbra/store.old/0/809/msg/0
  mbox agmadmin@witalsee.com> addMessage /Recovery /opt/zimbra/store.old/0/809/msg/0


'''/opt/zimbra/store.old/0/809/msg/0''' is the path to the folder containing the mails. Some IDs may have a large amount of mails, resulting in '''msg/1''', '''msg/2''', etc. These will have to be run one-by-one.
''/opt/zimbra/store.old/0/809/msg/0'' is the path to the folder containing the mails. Some IDs may have a large amount of mails, resulting in ''msg/1'', ''msg/2'', etc. These will have to be run one-by-one.

Revision as of 12:26, 25 July 2012

Zimbra Mailbox Structure

In Zimbra, each user is assigned a unique 'mailbox ID', which links him/her to their folder in /opt/zimbra/store/0.

Therefore a user with say mailbox ID '716', would have folder /opt/zimbra/store/0/716. The emails are stored in '.msg' format.

For more information on the structure, go here


The problem

Now this information is stored in LDAP, so if LDAP is corrupted or unrecoverable, we cannot associate the mailbox ID with the user ID.

But the store folder is intact.


The solution

We will have to trace which folder belongs to which user. Since each folder belongs to a single user, it is sufficient to determine with a few emails who the inbox belongs to.

So we follow these steps to recover it: In our case the backup store folder is /opt/zimbra/store.old/0

Go to the backup store folder:

# cd /opt/zimbra/store.old/0

Save the script as 'findusers.sh', and the run the script.

#!/bin/bash

for line in `ls`; do
echo $line >> /tmp/messagelist
cat $PWD/$line/msg/0/* | grep To: | sed 's/To: //' | sort | uniq -c | sort -nr | head -5 >> /tmp/messagelist
echo "" >> /tmp/messagelist
done
# /opt/zimbra/store.old/0/findusers.sh

This will return a list of top ten users (in /tmp/messagelist) whose name is present in the 'To:' field of the messages stored. Using the output of this, we can make a good estimate of the user's folder, but this needs to be confirmed manually as well, by reading the email.


The mails can then be recovered by using zmmailbox as the Zimbra user.

Both the commands below give admin rights on zmmailbox prompt, so use any one.

zmmailbox -zadmin

or

zmmailbox adminAuthenticate -u https://server.domain.com:7071 admin@domain.com password

After that we create the 'Recovery' folder, and add messages to that folder from our old store folder.

mbox> selectMailbox agmadmin@witalsee.com
mbox agmadmin@witalsee.com> createfolder /Recovery
mbox agmadmin@witalsee.com> addMessage /Recovery /opt/zimbra/store.old/0/809/msg/0

/opt/zimbra/store.old/0/809/msg/0 is the path to the folder containing the mails. Some IDs may have a large amount of mails, resulting in msg/1, msg/2, etc. These will have to be run one-by-one.