Recovery script I had a similar problem, where my EC2 instance running zimbra died and could not be recovered. The /opt/zimbra were not backed up, but all the email was stored on EBS volumes.
Once I reinstalled the server and attached the EBS volumes to it, I was able to access the mail store folder and recovery all the messages using mmorse's Method 1.
I've wrote this simple script to automate recovery - it looks in each "user folder" in the store and scans the message to determine the correct user account by looking for the "delivered for" header in the email. It then runs the recovery procedure on each folder in the user folder automatically:
archive_path=/srv/mail-volume-1/messages-old2; (cd $archive_path/0; for dir in *; do (cd $dir/msg; find . -type f | while read file; do (if file $file | grep gzip; then gunzip < $file; else cat $file; fi) | fgrep 'for <'; done) | perl -nle 'm|for <([^>\s]+)>| and $for{$1}++; END { for $name (sort { $for{$b} <=> $for{$a} } keys %for) { print "'$dir' $name"; last; } }'; done | sed -u -e 's/someuser@somedomain/somotheruser@somedomain/' | while read id name; do (echo "selectmailbox $name"; echo "createfolder /Recovery"; for p in $(ls $id/msg); do echo "addMessage /Recovery $archive_path/0/$id/msg/$p"; done; echo "quit") | su - zimbra -c 'zmmailbox -zadmin'; done)
Note the 'sed' command in the middle there - the detection part will fail to correctly detect the account name if an account is mostly used for receiving email to an alias or using forwards. If that is the case, you can use the sed command to replace the incorrect account name with the correct account name.
If you ever use this script, you should monitor the running process because it will not stop if an error is encountered. In such a case it will fail to recover all email in the folder where it encountered the error, that was not recovered before the error occurred. When such a thing happens (and it does quite often), you will need to go in manually and recover all the lost messages 1-by-1 by hand.
Last edited by Oded Arbel; 06-09-2011 at 04:54 AM..
|