rsync or scp script for moving emails from one server to another

albatroz

Well-Known Member
Mar 6, 2003
401
6
168
Virtual Orbis / Peru
cPanel Access Level
Root Administrator
Twitter
Hello,
We recently moved a domain to another server but some new emails were not moved
so I am looking for a sample scp or rsync command that I could use to move the
emails from the old server. The idea is something like this:

Source: IP1 /home/account/mail/domain.com/*/new
Destination: IP2 /home/account/mail/domain.com/*/new

I did something like this for one account but I need to repeat the process for
all the email accounts: scp * [email protected]:/home/account/mail/domain.com/username/new

Any suggestion?
 

24x7server

Well-Known Member
Apr 17, 2013
1,911
96
78
India
cPanel Access Level
Root Administrator
Twitter
Hello :),

Yes, you can migrate your all email accounts mail from old server to new server with the following command.

Code:
rsync -av --progress /home/account/mail/domain.com/* DestinationServerIP:/home/account/mail/domain.com/
 
  • Like
Reactions: Jean Boudreau

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,225
463
Hello,

Yes, it's possible to use a command like the one referenced in the previous response. Note you may want to run the following command on the destination server after copying the email data:

Code:
/scripts/mailperm --username
Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,225
463
is there a way to force the recreation of index files of Dovecot after this sync process?
Yes, you can remove the index files via the following script, as they are regenerated upon login:

Code:
# /scripts/remove_dovecot_index_files
/scripts/remove_dovecot_index_files

Utility to remove Dovecot index files. Available options:

    --user [cPanel username]

        Remove Dovecot index files from all email accounts setup under the specified cPanel user.
        Can be specified more than once, to process multiple users at once.

    --reseller [reseller username]

        Remove Dovecot index files from all email accounts setup under all the cPanel accounts owned by the specified Reseller.
        Can be specified more than once, to process multiple resellers at once.

    --all

        Remove Dovecot index files from all email accounts setup on the server.

    --verbose

        Prints the full paths of the files being removed.

    --help

        Prints this help text.
Thank you.
 

ulti

Registered
Feb 28, 2005
1
0
151
Hi,

after:
rsync -av --progress /home/username/mail/domain.com/* DestinationServerIP:/home/username/mail/domain.com/

I have problem: No such user for all emails on domain.com

/scripts/mailperm --username didn't help

Any ideas ?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,225
463
I have problem: No such user for all emails on domain.com
Hello,

You'd need to first re-create the email accounts via cPanel before syncing over the email data.

Thank you.
 

HostT

Member
Dec 7, 2010
17
2
53
For reference, here's the rsync command I used to copy mail from a remote server, to the server the command is running on:

Code:
rsync -avzh --progress [email protected]:/home/account/mail/domain.com/* /home/account/mail/domain.com/
 
  • Like
Reactions: cPanelMichael