jeff-j of osxroot
2/13/2015 - 12:09 AM

this script was used for admininternet to migrate from OS X 10.5 (cyrus) to a CentOS server. The same script could be used to migrate to OS

this script was used for admininternet to migrate from OS X 10.5 (cyrus) to a CentOS server. The same script could be used to migrate to OS X dovecot, the dovecot path would need the "Maildir" removed if goint to OS X

assumption that this script and cyrus2dovecot are placed at top of mailstore.

#!/bin/bash

# this tracks elapsed time
START_TIME=$SECONDS

# email when started
echo started | mail -s "Migration Started" jdj@mac.com

printf "\n\n############Starting `date`\n\n"

# Stop Mail
/usr/sbin/serveradmin stop mail
# and really make sure its stopped
/bin/launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist 
/bin/launchctl unload /System/Library/LaunchDaemons/edu.cmu.andrew.cyrus.master.plist 

# the target folder is moved (vs deleted) for speed
if [ -d converted ]; then
  mv converted "converted.`date  +"%Y-%m-%d_%H:%M"`.previous"
fi
mkdir converted

# roll through every user
for i in `ls -1 imap/user/`; do 
  id $i > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    ./cyrus2dovecot $i
  else
    echo ">>>> Skipped Orphan  >>>> $i"
  fi
done

printf "\n\n\n## Done Converting - `date` ##  \nNow its time to sync\n\n"

ELAPSED_TIME=$(($SECONDS - $START_TIME))

printf "ELAPSED TIME  --  $(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec\n\n"

# Sync each mailbox individually
for i in `ls -1 converted`; do
 echo Syncing $i
 rsync -rlt --delete --force converted/$i root@208.52.174.43:/var/vmail/1.converted/$i
done

printf "\n\n## Sync Completed `date`\n\n"

printf "Setting Permissions for entire mailstore on remote server\n\n"
ssh root@208.52.174.43 'chown -R vmail:vmail /var/vmail/1.converted ; chmod -R 700 /var/vmail/1.converted'
printf "\n\n## Permissions done `date`  ##\n\n"

printf "\n\n## Done `date`\n\n ## The mailboxes need to be moved to their domain directory\n\n"

ELAPSED_TIME=$(($SECONDS - $START_TIME))

printf "ELAPSED TIME  --  $(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec\n\n"  

printf "`date`\n\nELAPSED TIME  --  $(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec/n/n" | mail -s "migration done `date`" jdj@mac.com

exit 0