Maildir sync between cpanel servers
Hi!
Few days ago I needed to migrate a cpanel domain with 3 addon domain, and I wanted to move those addon domains to their own account.
Problem was migrating all email accounts (500+) from addon domains with all emails.
I had user-access (cpanel account) to the old server and root access (whm) to the new server, so I found a possible solution: synchronize maildirs between servers would allow an easy migration.
(Yeah, I could simply copy all email files and dirs, but it took a long time and emails were still reaching the old server)
For this task I used the excelent lftp tool and created a bash script for sync:
Basically I copy /home/username/etc and /home/username/mail content from old server to new one. In each run, I used "mirror --delete" to delete local files (emails already deleted in source server), but after changing dns mx entries, I stopped using the "--delete" parameter I hope this can be useful to someone, someday... P.S be careful with propper directories location for mirroring and chown-ing!
#!/bin/bash
HOST="11.22.33.44"
USER="username"
PASS='s3cret'
FTPURL="ftp://$USER:$PASS@$HOST"
echo "Migrating etc"
LCD="/home/username/etc/example.com"
RCD="/etc/example.com"
/usr/bin/lftp -c "set ftp:list-options -a;
open $FTPURL;
lcd $LCD;
cd $RCD;
mirror --delete --verbose"
echo "Setting etc owners"
chown username:username /home/username/etc/example.com/* -R
chown username:mail /home/username/etc/example.com/passwd*
chown username:mail /home/username/etc/example.com/quota*
echo "Migrating mail"
LCD="/home/username/mail/example.com"
RCD="/mail/example.com"
/usr/bin/lftp -c "set ftp:list-options -a;
open $FTPURL;
lcd $LCD;
cd $RCD;
mirror --delete --verbose"
echo "Setting mail owners"
chown username:username /home/username/mail/example.com/* -R
# Horde symlinks
/usr/local/cpanel/scripts/linksubemailtomainacct usernameBasically I copy /home/username/etc and /home/username/mail content from old server to new one. In each run, I used "mirror --delete" to delete local files (emails already deleted in source server), but after changing dns mx entries, I stopped using the "--delete" parameter I hope this can be useful to someone, someday... P.S be careful with propper directories location for mirroring and chown-ing!
-
Hello :) I am happy to see you were able to find a useful method of syncing email between servers. Thank you for providing us with the method you used. 0 -
Thanks, Michael! Hope you can tell me if you think the script is right or if I'm missing any step for mail migration and owner setting 0 -
One addition to consider would be to run the "/scripts/mailperm" script after the transfer. EX: /scripts/mailperm $username
Thank you.0
Please sign in to leave a comment.
Comments
3 comments