Little Script for parallel imapsync .. test it.. Im not really a unix shell script guru, but it works very well for me.
So, here is my little script. It take a text file for argument. This text file its your users and passwords separated by ",". After, they split the file into N files and after, call another script to do the parallell imap sync.
The password used for the users need to be the same for the source and dest server.
This scripts was used to sync Mboxes from Solaris+Cyrus+salsdb to Zimbra
6.x.
launchparallel.sh:
#!/bin/bash
counter=0;
if [ $# -ge 1 ]
then
FILE=$1;
if [ -e $FILE ]
then
echo "How many lines splitted per file: "
#Remember, more files do more imapsync process.
read lines
split -l $lines $FILE
for filesplitted in `ls x*`;
do
./do_imapsync.sh $filesplitted &
((++counter));
done
echo "Launching $counter process"
else
echo "File: $FILE not found.."
fi
else
echo "Use: $0 fileuserlist"
fi
The second script its where the imapsync do all the things.. There, you need to check the variables: DOMAINSOURCE, DOMAINDST using the format "@domain.com" if needed. And also, need check SERVERSOURCE and SERVERDST.
All log is kept on a file called: log-imapsync$1.txt where $1 its the name of the used splitted file.
Take note about the regextrans2 to match the source default folders to zimbra default folders.
do_imapsync.sh:
#!/bin/bash
#---- Some Info needed..------------
# Set domain only if youre working with virtual domains.
DOMAINSOURCE="";
# Set domain for zimbra users
DOMAINDST="@domainzimbra.comx";
# Set Source Server
SERVERSOURCE=server.com
# Set Dst Zimbra Server
SERVERDST=zimbraserver.com
#-------------------------------------
cp /dev/null log-imapsync$1.txt
echo " -----------------------------------------" >>log-imapsync$1.txt
for mbox in `cat $1`;
do
# The Default separator for the user file its ",". Here you could change it.
email=`echo $mbox |cut -f 1 -d ","`
password=`echo $mbox |cut -f 2 -d ","`
echo "Copying MBOX for user: [$email] from [$SERVERSOURCE] to [$SERVERDST]." >>log-imapsync$1.txt
# -- Below all its one line.
imapsync --buffersize 8192000 --nosyncacls --syncinternaldates --host1 $SERVERSOURCE --user1 $email$DOMAINSOURCE --password1 $password --host2 $SERVERDST --user2 $email$DOMAINDST --password2 $password --ssl2 --regextrans2 's/^INBOX.Borradores$/Drafs/i' --regextrans2 's/^sent-mail$/Sent/i' --regextrans2 's/^Sent Items$/Sent/i' --regextrans2 's/^Sent Messages$/Sent/i' --regextrans2 's/^INBOX.Enviados$/Sent/i' --noauthmd5 >> log-imapsync$1.txt
# ---- End of line.
if [ $? = 0 ]
then
echo "MBOX: [$email] from [$SERVERSOURCE] syncronized with [$SERVERDST]"
else
echo "Fail [$email] cant be syncronized"
fi
echo "-------------------------------------------------------" >>log-imapsync$1.txt
done
echo "Sync Done..." >>log-imapsync$1.txt
echo "Removing splitted file $1..."
rm $1
Also, u need to activate the cleartext auth on Zimbra server.
Its really a basic scripts, but its works so well for me.. I hope this scripts will be usefull for someone.
Sorry for my english..
Last edited by sevilla; 01-18-2010 at 08:27 AM..
|