[Dovecot] basic dsync wrapper for migration from another server

Alan McGinlay alanm at sics.se
Fri Mar 28 13:45:05 UTC 2014


Hi,

I cobbled together this somewhat shoddy Bash script to migrate email 
accounts from our Cyrus server to a new dovecot system. Feel free to 
use, or laugh at it as you wish :)

#!/bin/bash

##
# Migrate email accounts via IMAP from one server to another
##

trap "kill 0" SIGINT

workdir=/root/migrate

# Load list of users into array. The file "migration_map" should 
contain one user at domain.tld per line.
mapfile userList < $workdir/migration_map

# Number of symultanious migrations
num=10

index=0

# Loop over the array of user accounts
function process_userlist {
   procs=$(ps aux | grep "dsync" | grep -v "grep" | wc -l)
   # Perform $num operations at a time for the length of the userList
   while [[ $procs -lt $num ]] && [[ ${#userList[@]} -gt $index ]]; do
     procs=$(ps aux | grep "dsync" | grep -v "grep" | wc -l)
     dsync -o mail_fsync=never mirror -f -R -u ${userList[$index]} 
imapc:&
     echo "procs: $procs user: ${userList[$index]} index: $index"
     let index++
   done
}

# Until the userList is empty, keep going
until [ ${#userList[@]} -eq $index ]; do
   process_userlist
done

exit 0



More information about the dovecot mailing list