The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Maildir sync between cpanel servers

Discussion in 'General Discussion' started by egrueda, Dec 12, 2014.

  1. egrueda

    egrueda Member

    Joined:
    Mar 29, 2011
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Madrid, Spain
    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:
    Code:
    #!/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 username
    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!
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,811
    Likes Received:
    671
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  3. egrueda

    egrueda Member

    Joined:
    Mar 29, 2011
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Madrid, Spain
    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
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,811
    Likes Received:
    671
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    One addition to consider would be to run the "/scripts/mailperm" script after the transfer. EX:

    Code:
    /scripts/mailperm $username
    Thank you.
     
Loading...

Share This Page