Ok.. since no one answered, I have it worked out..
Since we have a lot of emails, and spread to multiple folders, we need to separate those in database and those which are not..
Make sure you copy these... er.. broken data folder into another folder. So if something goes wrong, you can always put them back together.
So first step, is of course shutdown zimbra
service zimbra stop
then copy older working mysql database to non working zimbra.
cp /mnt/mail/db/* /opt/zimbra/db -R
Now, we need to compare those mails in ~/store in July backup, versus mails in ~/store in running zimbra. Then I moved every mail not in july to another corresponding folder at /opt/backup. The script below is to scan all available .msg in all stores and volumes, and move to another folder. Save this script below to i.e. compare.sh
SOURCE=/opt/zimbra/store/0
DESTINATION=/opt/backup
COMPARE=/mnt/mail/store/0
for f in $SOURCE/*;
do
echo "scanning folder ${f##*/}";
for v in $f/msg/*;
do
comp=$COMPARE/${f##*/}/msg/${v##*/}
dst=$DESTINATION/${f##*/}
if [ ! -d $dst ]; then
echo "create $dst"
mkdir $dst;
fi
echo "comparing volume $v to $comp"
if [ -d $comp ] ; then
for m in $v/*; do
if [ ! -f $comp/${m##*/} ]; then
echo "move $m to $dst"
mv -b $m $dst
fi
done
else
echo "move $v/* to $dst"
mv -b $v/* $dst
fi
done;
done;
Make sure you modify SOURCE, COMPARE dan DESTINATION variables to mirror your own folders.
SOURCE: Current running zimbra store folder
DESTINATION: Where do you want your missing files moved
COMPARE: Where your old working zimbra backup resides, the one that you use its database.
Then chmod a+x compare.sh
to make it executable then ./compare.sh
to execute it.
result will be /opt/backup/1 to /opt/backup/xx where xx is mailbox stores. All messages that moved to /opt/backup/x are not in original mailbox, and will be added.
So now we have 2 folders. /opt/backup/xx
which contains files not in database, and /opt/zimbra/
which should be largely identical /mnt/mail/
Start Zimbra back
service zimbra start
Now, we need to get all mailboxes
mysql "zimbra" -e"select id,comment from mailbox"
The rest is easy, we only need to call CreateFolder and addMessage like these to re-attach those missing mails:
zmmailbox -z -m <[email protected]> cf "/Inbox/Recovered"
zmmailbox -z -m <[email protected]> am "/Inbox/Recovered" "/opt/backup/<xx>"
for example:
Let's say we have from step 2 above
+----+----------------------------------------------------+
| id | comment |
+----+----------------------------------------------------+
| 1 | [email protected] |
| 2 | [email protected] |
+----+----------------------------------------------------+
We should add those messages as:
zmmailbox -z -m [email protected] cf "/Inbox/Recovered"
zmmailbox -z -m [email protected] am "/Inbox/Recovered" "/opt/backup/1"
zmmailbox -z -m [email protected] cf "/Inbox/Recovered"
zmmailbox -z -m [email protected] am "/Inbox/Recovered" "/opt/backup/2"
Feel free to change that /Inbox/Recovered to anything you like.