# http://www.dovecot-buch.de
# Bei neueren Dovecot-Versionen ggf. "doveadm backup/sync" statt "dsync backup/mirror" verwenden!

cd /srv/vmail

for DOMAIN in * ; do
 cd /srv/vmail/$DOMAIN

 for USER in * ; do
  cd /srv/vmail/$DOMAIN/$USER

  if [ -e /root/STOP ] ; then exit 0 ; fi
  if [ -e /root/SLEEP ] ; then sleep 1h ; fi

  if [ -d Maildir ] ; then
   if [! -e sync.LOCK ] ; then
    touch sync.LOCK

    dsync backup -u $USER@$DOMAIN mdbox:/srv/vmail/$DOMAIN/$USER/mdbox-NEU
    dsync backup -u $USER@$DOMAIN mdbox:/srv/vmail/$DOMAIN/$USER/mdbox-NEU

    mv Maildir Maildir-OLD
    mv mdbox-NEU mdbox

    doveadm kick $USER@$DOMAIN
    dsync mirror -u $USER@$DOMAIN maildir:/srv/vmail/$DOMAIN/$USER/Maildir-OLD

    doveadm quota recalc -u $USER@$DOMAIN

    doveadm kick $USER@$DOMAIN

   fi
  fi

 done
done
 
