Hi There,
I recently had a rather foolish problem which came up through the digital equivalent of self harming. See my woes over here:
Deleted LDAP logs please help
Anyway, I wasn't able to gracefully fix it and restore however I did manage to create a handy little bash script which will help anyone else attempting disaster recovery from the /opt/zimbra/store directory and I though I should share it.
I had around 100 accounts in the store and then probably 100 folders in each of the accounts so the basic zmlmtpinject function was really a bit cumbersome as it will only do a single directory at a time and not drill down into child directories parsing all xxxx.msg files it finds. Also it won't carry the original date once it's restored, i.e. it will insist that the date of reciept is the date it is re-injected into the new mailbox.
So I adapted the script by
gitzc here:
Code:
http://www.zimbra.com/forums/administrators/729-solved-using-zmlmtpinject.html#post4017
so that basically it can run a first pass to do all the dates of every .msg file inside of all child directories of the specified directory.
Heres the new script, save as "zimdates.sh":
Code:
#!/bin/bash
#
# zimdates
# Chris Gitzlaff 2005-11-16
# Adapted by Underdog Ltd. 2010-06-10
#
# This script inserts an X-Zimbra-Received header into each message
# immediately after the Date header.
#
SCRIPTDIR=`pwd`
TMPFILE="$SCRIPTDIR/zimdates.tmp"
show_usage() {
echo "Usage: zimdates DIRECTORY"
echo "Inserts the X-Zimbra-Received header into a directory of messages"
echo
echo "Example: zimdates ./mail/"
}
# check for correct usage: 1 argument (directory)
if [ $# -eq 1 ]; then
MSGDIR=$1
if [ ! -d $MSGDIR ]; then
show_usage
exit 1
fi
else
show_usage
exit 1
fi
# if the temporary file exists, delete it
if [ -f $TMPFILE ]; then
rm -f $TMPFILE
fi
#cd $MSGDIR
for i in $( ls -1 $MSGDIR); do
cd $MSGDIR/$i
for file in *
do
grep "^Date\:\ " $file > $TMPFILE
# use the first Date occurrence
datestring=`sed -n '1p' $TMPFILE`
# remove the 'Date: ' prefix
datestring=${datestring#*\ }
sed -n '1,/^Date\:\ /p' $file > $TMPFILE
echo "X-Zimbra-Received: $datestring" >> $TMPFILE
sed '1,/^Date\:\ /d' $file >> $TMPFILE
mv $TMPFILE $file
echo $MSGDIR/$i/$file
done
done
echo "Done" and call it like:
[code]
./zimdates.sh /path/to/users/store/folder/number/
Next
We needed to do the same recursive thing with the zmlmtpinject function that basically you can use zmlmtpinject to iterate through folders inject them into the new mailbox:
Here's some code (in this case saved as: "zmlmtpinject-all.sh")
Code:
#!/bin/bash
#
# This script uses zmlmtpinject but loops through child directories. adapted from zmdates by Chris Gitzlaff.
#
SCRIPTDIR=`pwd`
TMPFILE="$SCRIPTDIR/zimdates.tmp"
show_usage() {
echo "Usage: zimdates DIRECTORY"
echo "Inserts the X-Zimbra-Received header into a directory of messages"
echo
echo "Example: zimdates ./mail/"
}
# check for correct usage: 1 argument (directory)
if [ $# -eq 2 ]; then
MSGDIR=$1
if [ ! -d $MSGDIR ]; then
show_usage
exit 1
fi
else
show_usage
exit 1
fi
# if the temporary file exists, delete it
if [ -f $TMPFILE ]; then
rm -f $TMPFILE
fi
#cd $MSGDIR
for i in $( ls -1 $MSGDIR); do
cd $MSGDIR/$i
for file in *
do
/opt/zimbra/bin/zmlmtpinject -d $MSGDIR/$i -r $2 -s $2
echo $MSGDIR/$i/$2
done
done
echo "Done" and use it like this:
Code:
./zmlmtpinject-all.sh /path/to/user/store users.em@il.addre.ss
Now for my Question:
I have injected some email but didn't get the scripts right first time. Is there any way to force zmlmtpinject to re-inject the same message as it seems that once injected you cannot inject again?
Thanks