Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Clone Server-A to Server-B

Discussion in 'General Discussion' started by SeanLee, Jan 28, 2005.

  1. camillemoussett

    camillemoussett Member

    Joined:
    Oct 19, 2004
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    151
    Hi,

    I am about to move servers from a Fecora Core 2 machine to a CentOS machine. Do you think this clone script is still good considering the OS change? Are the accounts' files specific to an OS? I plan to use the same Apache/PHP/MySQL/FTP settings.

    Thanks in advance.

    Camille
     
  2. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    168
    The script should be good for any OS - just note any network setting files that need to be manually edited, relevant to your OS - Fedora/Redhat/Centos is all still as I wrote.
     
  3. camillemoussett

    camillemoussett Member

    Joined:
    Oct 19, 2004
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    151
    Just a quick note to thanks DigitalN and the others who have contributed to this thread.

    I completed a server migration using the script and it worked marvelously. Much much simpler and painless than I expected. From a Fedora Core 2 machine to a CentOS 4.4 one. I made a first rsync pass for the user files (about 2-3 hours).

    Code:
    for SITE in `ls /var/cpanel/users`
    do
    rsync -avz -e ssh /home/$SITE $HOST:/home/
    done
    date | mail -s "Restore completed for $HOST" $EMAIL
    fi
    
    Then a full run of the script (10 mins) just prior to the IP switch and reboot.

    Works like a charm :)

    Thanks again
     
  4. myusername

    myusername Well-Known Member PartnerNOC

    Joined:
    Mar 6, 2003
    Messages:
    693
    Likes Received:
    1
    Trophy Points:
    168
    Location:
    chown -R us.*yourbase*
    cPanel Access Level:
    DataCenter Provider
    Twitter:
    Good idea. Here is a way to take it a step further though:

    Code:
    rsync -avz -e ssh --delete --exclude="mail/" /home/$SITE $HOST:/home/
    What this does is exclude the maildir so that your IMAP users don't wonder why files that they already deleted are in their inbox when you run the main script later.

    When you run the main script it will grab everyone's mail.

    Then you should be able to run the smaller script over the course of a few days until you are ready to do the big one.

    The --delete flag in there will remove files on the new server that may have been deleted from the old one by the user while you were waiting around to run the main script. Usefull if you plan to spread the migration out over a few days and take your time with it.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    #24 myusername, May 26, 2007
    Last edited: May 26, 2007
  5. Mindlash

    Mindlash Well-Known Member

    Joined:
    Jul 7, 2003
    Messages:
    77
    Likes Received:
    0
    Trophy Points:
    156
    I've been preparing for a move to be done this coming weekend.

    This is not a full cloning as we'll be migrating to another DC.

    Has anyone successfully Migrated/Cloned using this (or modified) script

    A) to a server with different IP's?
    B) from a very old Redhat 7 to new CentOS4/5

    If so, are there any Best Practices prior to moving?

    Thus far I've created an excel list of all domains/IP's with their new IP's so I can verify once all have been moved over.

    I also have a pre-flight script that I'm going to run on the new server which backs up everything that will ultimately be over-written as just-in-case

    I'm thinking, since the IP addresses will be different, that I should comment out the following:

    # rsync -avz -e ssh /etc/ips $HOST:/etc/

    Does anyone have suggestions for post-script execution on the new server to best migrate the old IP's to the new IP's based on the excel list I've created? Mixed Dedicatd IP's, SSL's, Reseller Block of IP's...

    Thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. 10101

    10101 Well-Known Member

    Joined:
    Sep 4, 2003
    Messages:
    151
    Likes Received:
    0
    Trophy Points:
    166
    I've used this for a server migration and it works great. Would this method be suitalbe for a backup system. By this I mean run this script to a backup server so that you have a full backup of your server should you need to restore later on?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. bazzi

    bazzi Well-Known Member

    Joined:
    May 23, 2004
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    166
    I am thinking to use this system to migrate one old server(centos 4.5) to a new server(centos 5).
    But is it better than using the copy from another server function in WHM?

    Sorry but if customer data and downtime is in danger I won't take a risk...
     
  8. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    168
    It depends upon your definition of better, it would be a lot quicker for sure and hold everything exactly how it was configuration wise. The whm copy account script is much improved than it used to be (from 2004) but it's a slower method. If you are cloning or backing up (regards 10101's post), it's still my pick to do this method but it's up to you how confident you feel with it.
     
  9. viktor_smk

    viktor_smk Member

    Joined:
    Feb 18, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    51
    Thank you for the script, it looks fine.

    I just have one question: when the first server transfers the files to the second via rsync with the user "root", which owner:group and permissions will have the transfered files and directories on the destination server? Root:root with the default permissions or the same owner/group and permissions like on the source server?

    Thank you for the help!
     
  10. myusername

    myusername Well-Known Member PartnerNOC

    Joined:
    Mar 6, 2003
    Messages:
    693
    Likes Received:
    1
    Trophy Points:
    168
    Location:
    chown -R us.*yourbase*
    cPanel Access Level:
    DataCenter Provider
    Twitter:
    rsync should maintain the old owners and groups. If you have any doubts run a test on your system and see if they are preserved after transfer.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    168
    Indeed, rsync with those options will retain the original permissions and ownerships (uid's).
     
  12. ed.kalk

    ed.kalk Well-Known Member

    Joined:
    Jun 19, 2008
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    56
    Location:
    Minneapolis, MN
    Is there a new script version?

    It's now 2008 and version 11.23, so, is there a new version of the script?
     
  13. ed.kalk

    ed.kalk Well-Known Member

    Joined:
    Jun 19, 2008
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    56
    Location:
    Minneapolis, MN
    Please comment back about the two concerns my colo had.....



    The only problem I see with the script off of the bat is that rsync is only using the flags- avz. I would think you would want to do rsync –avogz to preserve owner and group permissions during the copy.

    - Also, Any custom configuration you did to exim will need to be manually copied over.

    - The way MySQL is copied is a little scary as the files are just hot copied from one server to the other. After you’ve performed the move you’ll want to make sure MySQL works and compare the userlist on both sides to ensure that all MySQL users that were created initially are copied over and that the databases work.
     
  14. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    168
    Rsync -avz will work just fine to copy permissions and ownerships. Do a 'man rsync'.

    Also, if you are worried about corrupt Mysql tables, just stop mysql on the server while you rsync it, or setup mysql replication instead.. anyways, it will work still (you are only copying files after all). The original poster in 2004 got what he wanted anyways :)
     
  15. chriswebj2

    chriswebj2 Registered

    Joined:
    Jun 5, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    51
    On server migration using the script by DigitalN

    Dear friends,

    I have used the script provided by DigitalN to migrate my main server A to secondary server B (both are running WHM 11.23.2 on CentOS 5.2). The migration seems to work, when I contacted their support they listed a few more things which is missing in the original script.

    I am hoping DigitalN could help to look through this list. I have tested it on my servers and it works! May I ask does this script also migrate the WHM & CentOS settings as well?

    Code:
    /home
    /var/lib/mysql
    /var/cpanel
    /usr/local/apache/conf
    /usr/local/apache/domlogs
    /usr/local/frontpage
    /var/named
    /var/ssl
    /var/spool/cron (do this at your discretion)
    /usr/share/ssl
    
    in etc copy over these files:
    
    userdomains
    trueuserdomains
    trueuserowners
    nameserverips
    ips
    ips.dnsmaster
    ips.remotedns
    ipaddrpool
    cpanelbackup.conf
    cpupdate.conf
    demodomains
    demouser
    domainips
    localaliases
    localdomains
    named.conf
    wwwacct.conf
    proftpd.conf
    remotedomains
    exim.conf
    exim.pl
    exim.pl.local
    vfilter/
    proftpd/
    valiases/
    domainaliases/
    vmail/
    ssl/
    passwd
    group
    shadow
    gshadow
    Why did the support personnel stated do this at your discretion for /var/spool/cron, is there something I should take note of?

    Anyway I have amended the original script for my version of the cPanel.

    Code:
    #!/bin/sh
    # /////////////////////////////////////////
    # //      SG 09/2004 CPanel              //
    # //    CPanel transfer config script    //
    # /////////////////////////////////////////
    #
    # HOST = User + IP / Hostname to copy files TO.
    # All files copied from this server to the destinations server.
    # Use this iscript to transfer THIS server to a new server.
    HOST="root@$1"
    EMAIL="your@email.com"
    if [ "$1" == "" ]; then
    echo "Usage: $0 IP"
    echo "Example: $0 123.123.123.123"
    echo "Will remotely transfer all files from THIS server over to this server IP 123.123.123.123"
    exit 1
    fi
    echo "	WARNING - YOU ARE GOING TO COPY FILES FROM THIS SERVER TO $1"
    echo "  THIS WILL OVERWRITE THE FILES ON THE REMOTE HOST AT $1 !!"
    echo ""
    echo "	Is this correct? Enter y/n"
    read confirm
    if [ "$confirm" == "n" ]; then
    echo "	User aborted. Type y to transfer files."
    exit 1
    elif [ "$confirm" == "N" ]; then
    echo "  User aborted. Type y to transfer files."
    exit 1
    elif [ "$confirm" != "y" ]; then
    echo "	Sorry I don't know what you need, enter y or n"
    exit 1
    else
    
    rsync -avz -e ssh /etc/passwd $HOST:/etc/
    rsync -avz -e ssh /etc/shadow $HOST:/etc/
    rsync -avz -e ssh /etc/gshadow $HOST:/etc/
    rsync -avz -e ssh /etc/group $HOST:/etc/
    rsync -avz -e ssh /etc/wwwacct.conf $HOST:/etc/
    rsync -avz -e ssh /etc/quota.conf $HOST:/etc/
    rsync -avz -e ssh /etc/domainalias $HOST:/etc/
    rsync -avz -e ssh /etc/remotedomains $HOST:/etc/
    rsync -avz -e ssh /etc/exim.conf $HOST:/etc/
    rsync -avz -e ssh /etc/exim.pl $HOST:/etc/
    rsync -avz -e ssh /etc/exim.pl.local $HOST:/etc/
    rsync -avz -e ssh /etc/reservedipreasons $HOST:/etc/
    rsync -avz -e ssh /etc/reservedips $HOST:/etc/
    rsync -avz -e ssh /etc/secondarymx $HOST:/etc/
    rsync -avz -e ssh /etc/localdomains $HOST:/etc/
    rsync -avz -e ssh /etc/userdomains $HOST:/etc/
    rsync -avz -e ssh /etc/true* $HOST:/etc/
    rsync -avz -e ssh /etc/nameserverips $HOST:/etc/
    rsync -avz -e ssh /etc/valiases $HOST:/etc/
    rsync -avz -e ssh /etc/domainaliases $HOST:/etc/
    rsync -avz -e ssh /etc/vfilters $HOST:/etc/
    rsync -avz -e ssh /etc/vmail $HOST:/etc/
    rsync -avz -e ssh /etc/ips $HOST:/etc/
    rsync -avz -e ssh /etc/ips.dnsmaster $HOST:/etc/
    rsync -avz -e ssh /etc/ips.remotedns $HOST:/etc/
    rsync -avz -e ssh /etc/ipaddrpool $HOST:/etc/
    rsync -avz -e ssh /etc/cpanelbackup.conf $HOST:/etc/
    rsync -avz -e ssh /etc/cpupdate.conf $HOST:/etc/
    rsync -avz -e ssh /etc/demodomains $HOST:/etc/
    rsync -avz -e ssh /etc/demousers $HOST:/etc/
    rsync -avz -e ssh /etc/domainips $HOST:/etc/
    rsync -avz -e ssh /etc/localaliases $HOST:/etc/
    rsync -avz -e ssh /etc/services $HOST:/etc/
    rsync -avz -e ssh /etc/ssl $HOST:/etc/
    
    rsync -avz -e ssh /etc/sysconfig/pure-ftpd $HOST:/etc/sysconfig/
    rsync -avz -e ssh /etc/pure-ftpd.conf $HOST:/etc/
    rsync -avz -e ssh /etc/pure-ftpd $HOST:/etc/
    rsync -avz -e ssh /etc/proftpd.conf $HOST:/etc/
    rsync -avz -e ssh /etc/proftpd $HOST:/etc/
    
    # /var
    rsync -avz -e ssh /var/cpanel $HOST:/var/
    rsync -avz -e ssh /var/spool/cron $HOST:/var/spool/
    
    # /usr config - 3rdparty
    rsync -avz -e ssh /usr/share/ssl $HOST:/usr/share/
    rsync -avz -e ssh /usr/local/cpanel $HOST:/usr/local/
    
    # Apache
    rsync -avz -e ssh /usr/local/apache/conf $HOST:/usr/local/apache/
    rsync -avz -e ssh /usr/local/apache/domlogs $HOST:/usr/local/apache/
    rsync -avz -e ssh /usr/local/frontpage $HOST:/usr/local/
    
    # Mysql config
    rsync -avz -e ssh /root/.my.cnf $HOST:/root/
    rsync -avz -e ssh /etc/my.cnf $HOST:/etc/
    
    # Named
    rsync -avz -e ssh /var/named $HOST:/var/
    rsync -avz -e ssh /var/ssl $HOST:/var/
    rsync -avz -e ssh /etc/named.conf $HOST:/etc/
    rsync -avz -e ssh /etc/rndc.conf $HOST:/etc/
    
    #User Files
    # Mysql
    rsync -avz -e ssh /var/lib/mysql $HOST:/var/lib/
    
    for SITE in `ls /var/cpanel/users`
    do
    rsync -avz -e ssh /home/$SITE $HOST:/home/
    done
    date | mail -s "Restore completed for $HOST" $EMAIL
    fi
    exit 0
     
  16. ed.kalk

    ed.kalk Well-Known Member

    Joined:
    Jun 19, 2008
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    56
    Location:
    Minneapolis, MN
    Thanks

    Thanks for sharing
     
  17. Zion Ahead

    Zion Ahead Well-Known Member

    Joined:
    Nov 10, 2006
    Messages:
    347
    Likes Received:
    0
    Trophy Points:
    166
    How can this script be used to migrate from the secondary drive (which was the original primary drive, /home and all). The os crashed, had to be reloaded on a new drive, so we switched the original primary to secondary. Would this script work for that?
     
  18. ed.kalk

    ed.kalk Well-Known Member

    Joined:
    Jun 19, 2008
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    56
    Location:
    Minneapolis, MN
    Problem with the script...

    I'm trying this on cent os 5.2 with latest version of cpanel

    When I ran the script, it started by coping the first file /etc/passwd
    as soon as that was done it asked for the root password?!?!

    I did have the ssh keys setup and they were working before the script...

    The really bad thing is that the root password does not work now...?!?!?

    I cannot login to the target box anymore!!!
    I totally reinstalled it and tried it again... Same thin happened...?!?!
    Please HELP!! is there a way to fix this with out having to reinstall. Why did this happen???????
     
    #38 ed.kalk, Dec 9, 2008
    Last edited: Dec 9, 2008
  19. chriswebj2

    chriswebj2 Registered

    Joined:
    Jun 5, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    51
    root password changed

    ed.kalk,

    You said "it started by coping the first file /etc/passwd".

    You are right, so the root password of the destination(target) server became the password of the source server - try with your source server password then.
     
    #39 chriswebj2, Jan 16, 2009
    Last edited: Jan 16, 2009
  20. Imai

    Imai Well-Known Member

    Joined:
    Aug 11, 2003
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    156
    hello ed.kalk,

    I am wondering if the above post solved the problem.
    Were you able to login to the new server with the old server's password?
    Did you encounter any other problems?

    If you could walk me through the process, I will be more than grateful.
    Imai
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice