Get the most out of your Centmin Mod LEMP stack
Become a Member

How To Transfer cPanel/WHM Sites To Centmin Mod LEMP Servers

Discussion in 'Centmin Mod Insights' started by eva2000, May 4, 2017.

Thread Status:
Not open for further replies.
  1. eva2000

    eva2000 Administrator Staff Member

    30,160
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,135
    Local Time:
    8:18 PM
    Nginx 1.13.x
    MariaDB 5.5
    There seems to be more cPanel/WHM migrations to Centmin Mod LEMP stack based servers these days so I thought it would be the right time to write up a guide showing Centmin Mod users how to migrate their cPanel/WHM sites to Centmin Mod LEMP stack based servers.

    Notes
    • Transferring data won't automatically make your cPanel/WHM site domain work on Centmin Mod LEMP as cPanel/WHM uses Apache web server with Apache mod_rewrite/htaccess support and Centmin Mod LEMP uses Nginx web server which doesn't support mod_rewrite/htaccess so you need you own Nginx rules equivalent to Apache htaccess. Some examples of such configurations outlined at https://centminmod.com/nginx_configure.html
    • The data migration process can take a very long time for large data set sized site accounts so you will want to run the below SSH based commands in a Screen session or Tmux session which allows the session to survive SSH disconnections. If your ISP or SSH connection is disconnected, you just re-attach the Screen or Tmux session once you log back into SSH and proceed where you left off of.
    Assumptions

    This guide below will borrow steps and concepts from the Centmin Mod to Centmin Mod migration guide. There are a few assumptions being made

    1. That you have root user access to both cPanel/WHM (to use pkgacct method) and Centmin Mod servers
    2. That you already on Centmin Mod server created the domain Nginx vhost site via centmin.sh menu option 2, 22 or nv command as outlined Nginx Vhost & NSD DNS Setup - CentminMod.com LEMP Nginx web stack for CentOS
    3. That both cPanel/WHM and Centmin Mod LEMP stacks have CSF Firewall installed. Centmin Mod LEMP stacks auto install and configure CSF Firewall. While cPanel/WHM can optionally install CSF Firewall or your web host may have auto installed CSF Firewall for your protection. If unsure, ask web host or in cPanel/WHM server log in via SSH and type the command to get the CSF Firewall version number
      Code (Text):
      csf -v
    4. MySQL backup and restore commands are same as outlined on official MySQL documentation manual.

    CSF Firewall Whitelisting



    First, properly whitelist source and remote server's IP address and sshd ports in CSF Firewall.

    On cPanel/WHM source data server add to /etc/csf/csf.allow the following which whitelists TCP connections to destination default sshd port 22 on remote destination server IP 111.222.333.444. Change sshd port if it is not 22 on remote destination server.
    Code (Text):
    tcp|out|d=22|d=111.222.333.444

    then restart CSF Firewall service
    Code (Text):
    csf -r

    On Centmin Mod LEMP remote destination server add to /etc/csf/csf.allow which whitelists TCP connections to destination default sshd port 22 from source data server's IP 1.2.3.4
    Code (Text):
    tcp|in|d=22|s=1.2.3.4

    then restart CSF Firewall service
    Code (Text):
    csf -r
     
    Last edited: May 6, 2017
  2. eva2000

    eva2000 Administrator Staff Member

    30,160
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,135
    Local Time:
    8:18 PM
    Nginx 1.13.x
    MariaDB 5.5

    Understanding cPanel/WHM Structure



    First step is to understand cPanel/WHM's site account structure and what you would typically need to backup and where it is. This is in comparison to Centmin Mod's structure outlined here.
    • /home/username is where your site domain account is where username is your username used for SSH, SFTP logins and cPanel web GUI login access. Centmin Mod LEMP stack equivalent would be at /home/nginx/domains/yourdomain.com
    • /home/username/public_html is your cPanel/WHM public web root location. This is where you upload your site files to which are displayed on your domain. So to access local file /home/username/public_html/logo.png you would browser at yourdomain.com/logo.png. Centmin Mod LEMP stack equivalent would be at web root located at /home/nginx/domains/yourdomain.com/public
    • /home/username/mail is where your local hosted email for imap/pop3 is located. There is not Centmin Mod LEMP stack equivalent as Centmin Mod doesn't do local inbound @yourdomain.com emails. It's recommended to use 3rd party @yourdomain.com providers as outlined officially here and on forums here.
    • MySQL databases on cPanel/WHM servers are prefixed with your site account username by default. So if you created via MySQL wizard in cPanel a MySQL database called mysql1, it would be created as username_mysql1
    • MySQL usernames on cPanel/WHM are also prefixed with your site account username by default. So if you created a MySQL username called user1, it would be created as username_user1
    • MySQL databases are stored at /var/lib/mysql which is the same place Centmin Mod LEMP stack servers store MariaDB MySQL databases
    Here's an example of cPanel/WHM site account for test domain = cpdomain.com with cPanel username = cpdomain and with MySQL database created called cpdomain_mysql1 with assigned and created MySQL username called cpdomain_user1.

    The main /home/cpdomain/ username location for site domain cpdomain.com
    Code (Text):
    ls -lah /home/cpdomain/
    total 68K
    drwx--x--x 11 cpdomain cpdomain 4.0K May  4 13:12 ./
    drwx--x--x 17 root     root     4.0K May  4 13:09 ../
    -rw-r--r--  1 cpdomain cpdomain   18 May  4 13:09 .bash_logout
    -rw-r--r--  1 cpdomain cpdomain  176 May  4 13:09 .bash_profile
    -rw-r--r--  1 cpdomain cpdomain  124 May  4 13:09 .bashrc
    -rw-r-----  1 cpdomain cpdomain   30 May  4 13:09 .contactemail
    drwx------  4 cpdomain cpdomain 4.0K May  4 13:14 .cpanel/
    drwx------  4 cpdomain cpdomain 4.0K May  4 13:09 .cphorde/
    drwxr-x---  3 cpdomain mail     4.0K May  4 13:12 etc/
    drwxr-x---  2 cpdomain nobody   4.0K May  4 13:09 .htpasswds/
    -rw-------  1 cpdomain cpdomain   41 May  4 13:12 .lastlogin
    drwxr-x--x 10 cpdomain cpdomain 4.0K May  4 13:09 mail/
    drwxr-x---  3 cpdomain cpdomain 4.0K May  4 13:09 public_ftp/
    drwxr-x---  3 cpdomain nobody   4.0K May  4 13:14 public_html/
    drwxr-xr-x  5 cpdomain cpdomain 4.0K May  4 13:09 ssl/
    drwxr-xr-x  3 cpdomain cpdomain 4.0K May  4 13:12 tmp/
    lrwxrwxrwx  1 cpdomain cpdomain   11 May  4 13:09 www -> public_html/
    -rw-r--r--  1 cpdomain cpdomain  658 May  4 13:09 .zshrc
    


    cPanel cpdomain.com's public web root files at /home/cpdomain/public_html/
    Code (Text):
    ls -lah /home/cpdomain/public_html/
    total 3.3M
    drwxr-x---  3 cpdomain nobody   4.0K May  4 13:14 ./
    drwx--x--x 12 cpdomain cpdomain 4.0K May  4 13:24 ../
    -rw-r--r--  1 cpdomain cpdomain  86K May  1 14:49 001.png
    -rw-r--r--  1 cpdomain cpdomain 5.7K May  1 14:49 001.png.webp
    -rw-r--r--  1 cpdomain cpdomain  93K May  1 14:49 002.png
    -rw-r--r--  1 cpdomain cpdomain 8.7K May  1 14:49 002.png.webp
    -rw-r--r--  1 cpdomain cpdomain  63K May  1 14:49 003.png
    -rw-r--r--  1 cpdomain cpdomain 5.7K May  1 14:49 003.png.webp
    -rw-r--r--  1 cpdomain cpdomain  81K May  1 14:49 004.png
    -rw-r--r--  1 cpdomain cpdomain 9.9K May  1 14:49 004.png.webp
    -rw-r--r--  1 cpdomain cpdomain 110K May  1 14:49 005.png
    -rw-r--r--  1 cpdomain cpdomain  15K May  1 14:49 005.png.webp
    -rw-r--r--  1 cpdomain cpdomain  71K May  1 14:49 bees.png
    


    Listing of MySQL databases on cPanel/WHM server for cpdomain_mysql1 database. The rest are cPanel/WHM default required databases
    Code (Text):
    mysql -e "show databases;"
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | cpdomain_mysql1    |
    | cphulkd            |
    | leechprotect       |
    | modsec             |
    | mysql              |
    | performance_schema |
    | roundcube          |
    +--------------------+
    


    Physical location of your MySQL database cpdomain_mysql1 is at /var/lib/mysql/cpdomain_mysql1 - DO NOT manually touch, move or backup these files, you can corrupt your database data !

    Code (Text):
    ls -lah /var/lib/mysql/cpdomain_mysql1
    total 200K
    drwx------  2 mysql mysql 4.0K May  4 13:14 ./
    drwxr-x--x 23 mysql mysql 4.0K May  4 13:14 ../
    -rw-rw----  1 mysql mysql   65 May  4 13:12 db.opt
    -rw-rw----  1 mysql mysql 8.9K May  4 13:14 t1.frm
    -rw-rw----  1 mysql mysql 176K May  4 13:14 t1.ibd
    


    Test cpdomain_mysql1 database has only 1 InnoDB table for this dummy database demo.

    Code (Text):
    mysql -e "show tables;" cpdomain_mysql1
    +---------------------------+
    | Tables_in_cpdomain_mysql1 |
    +---------------------------+
    | t1                        |
    +---------------------------+
    

    list tables changing the last part of command LIKE 'cpdomain_mysql1';" to your databasename
    Code (Text):
    mysql -t -e "SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows,2),' Rows') AS 'Number of Rows',ENGINE AS 'Storage Engine',CONCAT(ROUND(data_length/(1024*1024),2),'MB') AS 'Data Size',CONCAT(ROUND(index_length/(1024*1024),2),'MB') AS 'Index Size' ,CONCAT(ROUND((data_length+index_length)/(1024*1024),2),'MB') AS'Total', ROW_FORMAT, TABLE_COLLATION FROM information_schema.TABLES WHERE table_schema LIKE 'cpdomain_mysql1';"
    

    Code (Text):
    +--------------------+----------------+----------------+-----------+------------+--------+------------+-------------------+
    | Table Name         | Number of Rows | Storage Engine | Data Size | Index Size | Total  | ROW_FORMAT | TABLE_COLLATION   |
    +--------------------+----------------+----------------+-----------+------------+--------+------------+-------------------+
    | cpdomain_mysql1.t1 | 0 Rows         | InnoDB         | 0.02MB    | 0.08MB     | 0.09MB | Compact    | latin1_swedish_ci |
    +--------------------+----------------+----------------+-----------+------------+--------+------------+-------------------+
    

    The MySQL username's grant privileges and permissions for cpdomain_user1
    Code (Text):
    mysql -e "show grants for cpdomain_user1@'localhost';"
    +-----------------------------------------------------------------------------------------------------------------------+
    | Grants for cpdomain_user1@localhost                                                                                   |
    +-----------------------------------------------------------------------------------------------------------------------+
    | GRANT USAGE ON *.* TO 'cpdomain_user1'@'localhost' IDENTIFIED BY PASSWORD '*49FDCFE1EB93E79C252E71C3E56AD87558F61EF6' |
    | GRANT ALL PRIVILEGES ON `cpdomain\_mysql1`.* TO 'cpdomain_user1'@'localhost'                                          |
    +-----------------------------------------------------------------------------------------------------------------------+
    
     
    Last edited: May 5, 2017
  3. eva2000

    eva2000 Administrator Staff Member

    30,160
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,135
    Local Time:
    8:18 PM
    Nginx 1.13.x
    MariaDB 5.5

    Initial cPanel/WHM Backups



    Migrating from cPanel/WHM to Centmin Mod LEMP stack doesn't require all the cPanel/WHM data your site has and only really needs your site account public web root files /home/username/public_html, your MySQL databases and your MySQL database users. However, to be 100% safe, you will want to generate a native cPanel/WHM full site account backup and download them for safe keeping just in case you want to restore the site account/domain to a new cPanel/WHM server.

    The native cPanel/WHM full site account backups are done via /scripts/pkgacct command which literally packages up your entire /home/username and linked MySQL databases, users and email POP/IMAP3 and log data into a tarball .tar.gz file. This can take a very long time for large data set sized site accounts so you will want to run this in a Screen session or Tmux session which allows the session to survive SSH disconnections.

    Got Enough Disk Free Space ?



    Important, ensure cPanel/WHM server has enough disk free space in /home to store the entire size of your site account data at /home/username and your MySQL database data at /var/lib/mysql

    Finding Out Disk Usage For Your Site Account

    To find out roughly your disk usage footprint for your cPanel/WHM site account use du command

    For /home/username i.e. /home/cpdomain
    Code (Text):
    du -sh /home/cpdomain/
    

    example output
    Code (Text):
    du -sh /home/cpdomain/
    4.1M    /home/cpdomain/
    

    For MySQL database named cpdomain_mysql1
    Code (Text):
    du -sh /var/lib/mysql/cpdomain_mysql1/
    

    example output
    Code (Text):
    du -sh /var/lib/mysql/cpdomain_mysql1/
    196K    /var/lib/mysql/cpdomain_mysql1/
    

    If you have more than one MySQL database for cpdomain user, they would all be prefixed with cpdomain_
    Code (Text):
    find /var/lib/mysql -type d -name "cpdomain_*" -exec du -sh {} \;
    

    example output
    Code (Text):
    find /var/lib/mysql -type d -name "cpdomain_*" -exec du -sh {} \;
    196K    /var/lib/mysql/cpdomain_mysql1
    


    Full Backup Of Your Site Account

    Install Screen
    Code (Text):
    yum -y install screen
    

    Create Screen session named backup and attach it
    Code (Text):
    screen -dmS backup
    screen -r backup
    

    Now the command to backup your site account username is
    Code (Text):
    /scripts/pkgacct username
    

    using above example cpdomain username
    Code (Text):
    /scripts/pkgacct cpdomain
    

    or if you don't want to gzip compress and only tar it
    Code (Text):
    /scripts/pkgacct username --nocompress
    

    using above example cpdomain username
    Code (Text):
    /scripts/pkgacct cpdomain --nocompress
    


    Example output you'd see for /scripts/pkgacct run
    Code (Text):
    /scripts/pkgacct cpdomain
    [2017-05-04 14:09:23 +0000] pkgacct started.
    [2017-05-04 14:09:23 +0000] pkgacct version 10 - user : cpdomain - tarball: 1 - target mysql : default - split: 0 - incremental: 0 - homedir: 1 - mailman: 1 - backup: 0 - archive version: 3 - running with uid 0
    [2017-05-04 14:09:23 +0000] pkgacct using '/usr/local/cpanel/3rdparty/bin/pigz -1 --processes 2 --blocksize 1024 --rsyncable' to compress archives
    [2017-05-04 14:09:23 +0000] pkgacct working dir : /home/cpmove-cpdomain
    [2017-05-04 14:09:23 +0000] Copying Reseller Config...[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying Suspension Info (if needed)...[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying SSL certificates, CSRs, and keys...[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Storing SSL domain......[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying Domain Keys....[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying Counter Data....[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying Bandwidth Data....Summary databases … done!
    [2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying Dns Zones.......cpdomain.com...[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying Mail files....[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying proftpd file....[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying www logs.......log file sizes [0 byte(s)]......cpdomain.com-ssl_log......cpdomain.com...[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copy userdata...[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copy custom virtualhost templates...[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying mailman lists and archives....[2017-05-04 14:09:23 +0000] Done copying mailman lists and archives.
    [2017-05-04 14:09:23 +0000] Copying homedir.............
    [2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Calculating nobody files............
    [2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Performing “Postgresql” component....
    [2017-05-04 14:09:23 +0000] Completed “Postgresql” component.
    [2017-05-04 14:09:23 +0000] Performing “Mysql” component....
    [2017-05-04 14:09:23 +0000] Determining mysql dbs...[2017-05-04 14:09:23 +0000] ...mysqldump version: 5.6.35...[2017-05-04 14:09:23 +0000] ...mysql version: 5.6...[2017-05-04 14:09:23 +0000] Saving mysql privs...[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] ...Done
    [2017-05-04 14:09:23 +0000] Storing mysql dbs............
    cpdomain_mysql1[2017-05-04 14:09:23 +0000] (2584 bytes)
    [2017-05-04 14:09:23 +0000] ...Done
    [2017-05-04 14:09:23 +0000] Completed “Mysql” component.
    [2017-05-04 14:09:23 +0000] Copying cpuser file.......[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying crontab file.......[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Performing “Quota” component....
    [2017-05-04 14:09:23 +0000] Completed “Quota” component.
    [2017-05-04 14:09:23 +0000] Performing “Integration” component....
    [2017-05-04 14:09:23 +0000] Completed “Integration” component.
    [2017-05-04 14:09:23 +0000] Performing “AuthnLinks” component....
    [2017-05-04 14:09:23 +0000] Completed “AuthnLinks” component.
    [2017-05-04 14:09:23 +0000] Performing “APITokens” component....
    [2017-05-04 14:09:23 +0000] Completed “APITokens” component.
    [2017-05-04 14:09:23 +0000] Storing Subdomains....
    [2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Storing Parked Domains....
    [2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Storing Addon Domains....
    [2017-05-04 14:09:23 +0000] Copying password.......[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Copying shell.......[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] Creating Archive ....[2017-05-04 14:09:23 +0000] Done
    [2017-05-04 14:09:23 +0000] pkgacctfile is: /home/cpmove-cpdomain.tar.gz
    [2017-05-04 14:09:23 +0000] md5sum is: e1d923ff2a2e5897de51cd3f102e654a
    [2017-05-04 14:09:23 +0000]
    [2017-05-04 14:09:23 +0000] size is: 2879901
    [2017-05-04 14:09:23 +0000]
    [2017-05-04 14:09:23 +0000] homesize is: 4218880
    [2017-05-04 14:09:23 +0000]
    [2017-05-04 14:09:23 +0000] homefiles is: 205
    [2017-05-04 14:09:23 +0000] pkgacct completed
    


    Default saved location is in /home i.e. /home/cpmove-username.tar.gz or /home/cpmove-username.tar. For this example it would be at /home/cpmove-cpdomain.tar.gz
    Code (Text):
    ls -lah /home/cpmove-cpdomain.tar.gz
    -rw------- 1 root root 2.8M May  4 14:09 /home/cpmove-cpdomain.tar.gz
    


    Optionally Transfer Packaged Account To Centmin Mod



    If you have enough disk space for 3x or 4x times your total site account data size, you can use rsync to transfer the packaged full backup to your Centmin Mod LEMP stack server just for added safe keeping and usually, server to server transfers are much faster than local ISP internet connections.

    For demo purposes assume
    • Centmin Mod LEMP stack remote server's IP address is 111.222.333.444 on port 22
    • You have whitelisted on both cPanel/WHM and Centmin Mod remote server the ip and ports in CSF Firewall as outlined in 1st post of this thread here. If not read below.

    CSF Firewall Configuration



    First, properly whitelist source and remote server's IP address and sshd ports in CSF Firewall.

    On cPanel/WHM source data server add to /etc/csf/csf.allow the following which whitelists TCP connections to destination default sshd port 22 on remote destination server IP 111.222.333.444. Change sshd port if it is not 22 on remote destination server.
    Code (Text):
    tcp|out|d=22|d=111.222.333.444

    then restart CSF Firewall service
    Code (Text):
    csf -r

    On Centmin Mod LEMP remote destination server add to /etc/csf/csf.allow which whitelists TCP connections to destination default sshd port 22 from source data server's IP 1.2.3.4
    Code (Text):
    tcp|in|d=22|s=1.2.3.4

    then restart CSF Firewall service
    Code (Text):
    csf -r


    Rsync Transfers

    Then Rsync transfer the full backup. You can do this to any remote linux server and doesn't have to be Centmin Mod remote server.

    Rsync dry-run test transfer using arcfour for fastest possible transfers. Note first time you connect to a new remote, you will get a message about the authenticity of the remote host ip and the RSA key fingerprint and whether you want to continue connecting. Answer yes.

    Then you'd be prompted for your remote Centmin Mod servers root user password to login.
    Code (Text):
    rsync -avzin --progress --stats -e "ssh -p 22" /home/cpmove-cpdomain.tar.gz root@111.222.333.444:/home/
    

    Rsync live transfer remove n flag
    Code (Text):
    rsync -avzi --progress --stats -e "ssh -p 22" /home/cpmove-cpdomain.tar.gz root@111.222.333.444:/home/
    

    example output from live rsync transfer run
    Code (Text):
    rsync -avzi --progress --stats -e "ssh -p 22" /home/cpmove-cpdomain.tar.gz root@111.222.333.444:/home/
    sending incremental file list
    <f+++++++++ cpmove-cpdomain.tar.gz
         2879901 100%    5.90MB/s    0:00:00 (xfer#1, to-check=0/1)
    
    Number of files: 1
    Number of files transferred: 1
    Total file size: 2879901 bytes
    Total transferred file size: 2879901 bytes
    Literal data: 2879901 bytes
    Matched data: 0 bytes
    File list size: 38
    File list generation time: 0.001 seconds
    File list transfer time: 0.000 seconds
    Total bytes sent: 2880956
    Total bytes received: 31
    
    sent 2880956 bytes  received 31 bytes  640219.33 bytes/sec
    total size is 2879901  speedup is 1.00
    

    SSH log into your Centmin Mod remote server and check /home/cpmove-cpdomain.tar.gz exists
    Code (Text):
    ls -lah /home/cpmove-cpdomain.tar.gz
    -rw------- 1 root root 2.8M May  4 14:09 /home/cpmove-cpdomain.tar.gz
    
     
    Last edited: Jul 11, 2017
  4. eva2000

    eva2000 Administrator Staff Member

    30,160
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,135
    Local Time:
    8:18 PM
    Nginx 1.13.x
    MariaDB 5.5

    Using cPanel Full Backup On Centmin Mod



    Now you have a choice to make, use the transferred data full cPanel backup you transferred over at /home/cpmove-cpdomain.tar.gz to populate your Centmin Mod server or do a separate transfer for just your site account public web root files /home/username/public_html, your MySQL databases and your MySQL database users.

    Below guide in this specific post is for using the full cPanel backup on Centmin Mod server.

    Step 1. First step create a working directory at /home/cpanel-data and move your /home/cpmove-cpdomain.tar.gz to it
    Code (Text):
    mkdir -p /home/cpanel-data
    mv /home/cpmove-cpdomain.tar.gz /home/cpanel-data
    

    listing directory contents at /home/cpanel-data
    Code (Text):
    ls -lah /home/cpanel-data
    total 2.8M
    drwxr-xr-x   2 root root 4.0K May  4 14:58 .
    drwxr-xr-x. 12 root root 4.0K May  4 14:58 ..
    -rw-------   1 root root 2.8M May  4 14:09 cpmove-cpdomain.tar.gz
    

    If you are sure you have enough disk free space, extract the tarball full back up file
    Code (Text):
    cd /home/cpanel-data
    tar xvzf cpmove-cpdomain.tar.gz
    

    Directory listing after extraction should of extracted directory at /home/cpanel-data/cpmove-cpdomain
    Code (Text):
    ls -lah
    total 2.8M
    drwxr-xr-x   3 root root 4.0K May  4 14:59 .
    drwxr-xr-x. 12 root root 4.0K May  4 14:58 ..
    drwxr-x---  34 root  502 4.0K May  4 14:09 cpmove-cpdomain
    -rw-------   1 root root 2.8M May  4 14:09 cpmove-cpdomain.tar.gz
    

    listing of contents at /home/cpanel-data/cpmove-cpdomain
    Code (Text):
    ls -lah /home/cpanel-data/cpmove-cpdomain
    total 172K
    drwxr-x--- 34 root  502 4.0K May  4 14:09 .
    drwxr-xr-x  3 root root 4.0K May  4 14:59 ..
    -rw-------  1 root root    0 May  4 14:09 addons
    drwx------  2 root root 4.0K May  4 14:09 bandwidth
    drwx------  2 root root 4.0K May  4 14:09 bandwidth_db
    -rw-------  1 root root  182 May  4 14:09 bandwidth_db.json
    drwx------  2 root root 4.0K May  4 14:09 counters
    drwx------  2 root root 4.0K May  4 14:09 cp
    drwx------  2 root root 4.0K May  4 14:09 cron
    -rw-------  1 root root    0 May  4 14:09 digestshadow
    drwx------  2 root root 4.0K May  4 14:09 dnszones
    drwx------  4 root root 4.0K May  4 14:09 domainkeys
    -rw-r--r--  1 root root    0 May  4 14:09 has_sslstorage
    drwx--x--x 12  502  502 4.0K May  4 13:24 homedir
    -rw-------  1 root root   15 May  4 14:09 homedir_paths
    drwx------  2 root root 4.0K May  4 14:09 httpfiles
    drwx------  2 root root 4.0K May  4 14:09 ips
    drwx------  2 root root 4.0K May  4 14:09 locale
    drwx------  2 root root 4.0K May  4 14:09 logs
    drwx------  2 root root 4.0K May  4 14:09 meta
    drwx------  2 root root 4.0K May  4 14:09 mm
    drwx------  4 root root 4.0K May  4 14:09 mma
    drwx------  2 root root 4.0K May  4 14:09 mms
    drwx------  2 root root 4.0K May  4 14:09 mysql
    -rw-------  1 root root 1.2K May  4 14:09 mysql.sql
    drwx------  2 root root 4.0K May  4 14:09 mysql-timestamps
    -rw-------  1 root root    0 May  4 14:09 nobodyfiles
    -rw-------  1 root root    0 May  4 14:09 pds
    -rw-r-----  1 root root  334 May  4 13:09 proftpdpasswd
    drwx------  2 root root 4.0K May  4 14:09 psql
    -rw-------  1 root root    1 May  4 14:09 quota
    drwx------  2 root root 4.0K May  4 14:09 resellerconfig
    drwx------  2 root root 4.0K May  4 14:09 resellerfeatures
    drwx------  2 root root 4.0K May  4 14:09 resellerpackages
    -rw-------  1 root root    0 May  4 14:09 sds
    -rw-------  1 root root    0 May  4 14:09 sds2
    -rw-------  1 root root  106 May  4 14:09 shadow
    -rw-------  1 root root    9 May  4 14:09 shell
    drwx------  2 root root 4.0K May  4 14:09 ssl
    drwx------  2 root root 4.0K May  4 14:09 sslcerts
    -rw-------  1 root root   12 May  4 14:09 ssldomain
    drwx------  2 root root 4.0K May  4 14:09 sslkeys
    drwx------  2 root root 4.0K May  4 14:09 suspended
    drwx------  2 root root 4.0K May  4 14:09 suspendinfo
    drwxr-xr-x  2 root root 4.0K May  4 14:09 userconfig
    drwx------  2 root root 4.0K May  4 14:09 userdata
    drwx------  2 root root 4.0K May  4 14:09 va
    drwx------  2 root root 4.0K May  4 14:09 vad
    -rw-r--r--  1 root root   39 May  4 14:09 version
    drwx------  2 root root 4.0K May  4 14:09 vf
    


    Step 2. Restoring the site account data

    We are only concerned with the directories homedir, and mysql and maybe mysql.sql file which has a backup of your MySQL user's usernames and grant privileges. You do not want to blindly import mysql.sql into Centmin Mod server though.

    MySQL data

    The MySQL user details would of be gathered from previous set in showing MySQL user grants command ran on cPanel/WHM server side i.e.
    Code (Text):
    mysql -e "show grants for cpdomain_user1@'localhost';"
    +-----------------------------------------------------------------------------------------------------------------------+
    | Grants for cpdomain_user1@localhost                                                                                   |
    +-----------------------------------------------------------------------------------------------------------------------+
    | GRANT USAGE ON *.* TO 'cpdomain_user1'@'localhost' IDENTIFIED BY PASSWORD '*49FDCFE1EB93E79C252E71C3E56AD87558F61EF6' |
    | GRANT ALL PRIVILEGES ON `cpdomain\_mysql1`.* TO 'cpdomain_user1'@'localhost'                                          |
    +-----------------------------------------------------------------------------------------------------------------------+
    


    Public web root data

    Listing for homedir at /home/cpanel-data/cpmove-cpdomain/homedir where you should only really be focused on public_html web root contents at /home/cpanel-data/cpmove-cpdomain/homedir/public_html
    Code (Text):
    ls -lah /home/cpanel-data/cpmove-cpdomain/homedir
    total 72K
    drwx--x--x 12  502    502 4.0K May  4 13:24 .
    drwxr-x--- 34 root    502 4.0K May  4 14:09 ..
    lrwxrwxrwx  1  502    502   34 May  4 13:24 access-logs -> /usr/local/apache/domlogs/cpdomain
    -rw-r--r--  1  502    502   18 May  4 13:09 .bash_logout
    -rw-r--r--  1  502    502  176 May  4 13:09 .bash_profile
    -rw-r--r--  1  502    502  124 May  4 13:09 .bashrc
    -rw-r-----  1  502    502   30 May  4 13:09 .contactemail
    drwx------  4  502    502 4.0K May  4 13:14 .cpanel
    drwx------  4  502    502 4.0K May  4 13:09 .cphorde
    drwxr-x---  3  502 mail   4.0K May  4 13:12 etc
    drwxr-x---  2  502 nobody 4.0K May  4 13:09 .htpasswds
    -rw-------  1  502    502   41 May  4 13:12 .lastlogin
    drwx------  2  502    502 4.0K May  4 13:24 logs
    drwxr-x--x 10  502    502 4.0K May  4 13:09 mail
    drwxr-x---  3  502    502 4.0K May  4 13:09 public_ftp
    drwxr-x---  3  502 nobody 4.0K May  4 13:14 public_html
    drwxr-xr-x  5  502    502 4.0K May  4 13:09 ssl
    drwxr-xr-x  3  502    502 4.0K May  4 13:12 tmp
    lrwxrwxrwx  1  502    502   11 May  4 13:09 www -> public_html
    -rw-r--r--  1  502    502  658 May  4 13:09 .zshrc
    


    Listing for /home/cpanel-data/cpmove-cpdomain/mysql which contains your mysql database cp_domain_mysql1.create file which is the sql queries sued to create the database, the actual MySQL database backup cpdomain_mysql1.sql and the other 2 files are not required by Centmin Mod.
    Code (Text):
    ls -lah /home/cpanel-data/cpmove-cpdomain/mysql
    total 24K
    drwx------  2 root root 4.0K May  4 14:09 .
    drwxr-x--- 34 root  502 4.0K May  4 14:09 ..
    -rw-r--r--  1 root root 1.4K May  4 14:09 cpdomain_mysql1.create
    -rw-r--r--  1 root root 2.6K May  4 14:09 cpdomain_mysql1.sql
    -rw-------  1 root root    5 May  4 14:09 openfileslimit
    -rw-r--r--  1 root root   40 May  4 14:09 roundcube.sql
    


    Step 3. Next step is to import the MySQL database cpdomain_mysql1 on Centmin Mod server. These commands are all done in same SSH session as root user.

    For 100% reproduction of your MySQL database schema from cPanel you can use /home/cpanel-data/cpmove-cpdomain/mysql/cpdomain_mysql1.create SQL queries to create the empty database first. I am using additional mysql client options assigned to CLIENTOPT variable to prevent mysql time outs and mysql server gone away messages. You'd want to temporarily edit /etc/my.cnf wait_timeout = 1800 value to 28800 seconds and restart mysql server first as well.
    Code (Text):
    CLIENTOPT='--max_allowed_packet=256M --net_buffer_length=65536'
    mysql $CLIENTOPT < /home/cpanel-data/cpmove-cpdomain/mysql/cpdomain_mysql1.create
    

    alternatively if you want the MySQL database created with Centmin Mod MariaDB MySQLs default properties
    Code (Text):
    mysqladmin create cpdomain_mysql1
    

    Use either method not both to create the MySQL database cpdomain_mysql1. You'd have to repeat this for each of your mysql databases with cpdomain_ prefix.

    check that database cpdomain_mysql1 was created
    Code (Text):
    mysql -e "show databases;"
    

    example output
    Code (Text):
    mysql -e "show databases;"
    +--------------------+
    | Database           |
    +--------------------+
    | cpdomain_mysql1    |
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    

    Next step is importing actual MySQL data from sql backup file at /home/cpanel-data/cpmove-cpdomain/mysql/cpdomain_mysql1.sql into the newly created cpdomain_mysql1 database we just made. This can take seconds, minutes or even hours to complete depending on size of database and your server /etc/my.cnf settings and server hardware specs.
    Code (Text):
    CLIENTOPT='--max_allowed_packet=256M --net_buffer_length=65536'
    mysql $CLIENTOPT cpdomain_mysql1 < /home/cpanel-data/cpmove-cpdomain/mysql/cpdomain_mysql1.sql
    

    verify the database tables were imported changing the last part of command LIKE 'cpdomain_mysql1';" to your databasename
    Code (Text):
    mysql -t -e "SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows,2),' Rows') AS 'Number of Rows',ENGINE AS 'Storage Engine',CONCAT(ROUND(data_length/(1024*1024),2),'MB') AS 'Data Size',CONCAT(ROUND(index_length/(1024*1024),2),'MB') AS 'Index Size' ,CONCAT(ROUND((data_length+index_length)/(1024*1024),2),'MB') AS'Total', ROW_FORMAT, TABLE_COLLATION FROM information_schema.TABLES WHERE table_schema LIKE 'cpdomain_mysql1';"
    

    output
    Code (Text):
    +--------------------+----------------+----------------+-----------+------------+--------+------------+-------------------+
    | Table Name         | Number of Rows | Storage Engine | Data Size | Index Size | Total  | ROW_FORMAT | TABLE_COLLATION   |
    +--------------------+----------------+----------------+-----------+------------+--------+------------+-------------------+
    | cpdomain_mysql1.t1 | 0 Rows         | InnoDB         | 0.02MB    | 0.08MB     | 0.09MB | Compact    | latin1_swedish_ci |
    +--------------------+----------------+----------------+-----------+------------+--------+------------+-------------------+
    

    Now to replay the MySQL user cpdomain_user1 grants and permissions on Centmin Mod LEMP server you would use the data gathered from cPanel server show grants command which is also found in /home/cpanel-data/cpmove-cpdomain/mysql.sql extracted file
    Code (Text):
    mysql -e "show grants for cpdomain_user1@'localhost';"
    +-----------------------------------------------------------------------------------------------------------------------+
    | Grants for cpdomain_user1@localhost                                                                                   |
    +-----------------------------------------------------------------------------------------------------------------------+
    | GRANT USAGE ON *.* TO 'cpdomain_user1'@'localhost' IDENTIFIED BY PASSWORD '*49FDCFE1EB93E79C252E71C3E56AD87558F61EF6' |
    | GRANT ALL PRIVILEGES ON `cpdomain\_mysql1`.* TO 'cpdomain_user1'@'localhost'                                          |
    +-----------------------------------------------------------------------------------------------------------------------+
    

    Replay those 2 SQL queries on Centmin Mod server as root user in SSH tagging on end of them a semi-colon ;
    1st command
    Code (Text):
    mysql -e "GRANT USAGE ON *.* TO 'cpdomain_user1'@'localhost' IDENTIFIED BY PASSWORD '*49FDCFE1EB93E79C252E71C3E56AD87558F61EF6'"
    

    2nd command

    Due to backslashes having different meaning on SSH command line to mean a command, the GRANT command needs to change and remove the backslashes for
    Code (Text):
    `dbname2`.*
    

    to become
    Code (Text):
    dbname2.*
    

    So becomes SSH command to run, it will return empty if successful
    Code (Text):
    mysql -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON dbname2.* TO 'dbuser1'@'localhost';"
    

    Verify the cpdomain_user1 user was created with appropriate grant privileges
    Code (Text):
    mysql -e "show grants for cpdomain_user1@'localhost';"                     
    +-----------------------------------------------------------------------------------------------------------------------+
    | Grants for cpdomain_user1@localhost                                                                                   |
    +-----------------------------------------------------------------------------------------------------------------------+
    | GRANT USAGE ON *.* TO 'cpdomain_user1'@'localhost' IDENTIFIED BY PASSWORD '*49FDCFE1EB93E79C252E71C3E56AD87558F61EF6' |
    | GRANT ALL PRIVILEGES ON `cpdomain\_mysql1`.* TO 'cpdomain_user1'@'localhost'                                          |
    +-----------------------------------------------------------------------------------------------------------------------+
    


    Step 4. Import site public web root data from /home/cpanel-data/cpmove-cpdomain/homedir/public_html to Centmin Mod site domain vhost web root at /home/nginx/domains/cpdomain.com/public which would of been created when you created your domain Nginx vhost account prior using centmin.sh menu option 2, 22 or nv command outlined here Nginx Vhost & NSD DNS Setup - CentminMod.com LEMP Nginx web stack for CentOS

    Which would of created your cpdomain.com nginx vhost account structure and outputted the info at end
    Code (Text):
    -------------------------------------------------------------
    vhost for cpdomain.com created successfully
    
    domain: http://cpdomain.com
    vhost conf file for cpdomain.com created: /usr/local/nginx/conf/conf.d/cpdomain.com.conf
    
    upload files to /home/nginx/domains/cpdomain.com/public
    vhost log files directory is /home/nginx/domains/cpdomain.com/log
    


    copy the data in /home/cpanel-data/cpmove-cpdomain/homedir/public_html to /home/nginx/domains/cpdomain.com/public by first changing into source directory and doing a recursive copy command perserving permissions and disabling cp alias with backslash and the chown change user and group of files
    Code (Text):
    cd /home/cpanel-data/cpmove-cpdomain/homedir/public_html
    \cp -Rpf * /home/nginx/domains/cpdomain.com/public
    chown -R nginx:nginx /home/nginx/domains/cpdomain.com/public
    

    listing directory for /home/nginx/domains/cpdomain.com/public
    Code (Text):
    ls -lah /home/nginx/domains/cpdomain.com/public
    total 3.4M
    drwxr-s--- 3 nginx nginx 4.0K May  4 18:13 .
    drwxr-s--- 6 nginx nginx 4.0K May  4 18:13 ..
    -rw-r--r-- 1 nginx nginx  86K May  1 14:49 001.png
    -rw-r--r-- 1 nginx nginx 5.7K May  1 14:49 001.png.webp
    -rw-r--r-- 1 nginx nginx  93K May  1 14:49 002.png
    -rw-r--r-- 1 nginx nginx 8.7K May  1 14:49 002.png.webp
    -rw-r--r-- 1 nginx nginx  63K May  1 14:49 003.png
    -rw-r--r-- 1 nginx nginx 5.7K May  1 14:49 003.png.webp
    -rw-r--r-- 1 nginx nginx  81K May  1 14:49 004.png
    -rw-r--r-- 1 nginx nginx 9.9K May  1 14:49 004.png.webp
    -rw-r--r-- 1 nginx nginx 110K May  1 14:49 005.png
    -rw-r--r-- 1 nginx nginx  15K May  1 14:49 005.png.webp
    -rw-r----- 1 nginx nginx 1.6K May  4 18:13 403.html
    -rw-r----- 1 nginx nginx 1.6K May  4 18:13 404.html
    -rw-r----- 1 nginx nginx 2.1K May  4 18:13 500.html
    -rw-r----- 1 nginx nginx 2.1K May  4 18:13 502.html
    -rw-r----- 1 nginx nginx 2.2K May  4 18:13 503.html
    -rw-r----- 1 nginx nginx 7.6K May  4 18:13 503.jpg
    -rw-r----- 1 nginx nginx 2.1K May  4 18:13 504.html
    -rw-r----- 1 nginx nginx 2.2K May  4 18:13 50x.html
    -rw-r--r-- 1 nginx nginx  71K May  1 14:49 bees.png
    -rw-r--r-- 1 nginx nginx 5.0K May  1 14:49 bees.png.webp
    

    Now your Nginx vhost config files would be at /usr/local/nginx/conf/conf.d/cpdomain.com.conf and/or /usr/local/nginx/conf/conf.d/cpdomain.com.ssl.conf as per Centmin Mod Configuration Files - CentminMod.com LEMP Nginx web stack for CentOS and would need to be altered according for your specific web app/script's Nginx rules i.e. Nginx Configuration Examples - CentminMod.com LEMP Nginx web stack for CentOS

    If you used centmin.sh menu option 22 to auto install Wordpress on centmin mod server, then your Nginx vhosts will already have the correct Wordpress Nginx rules, just need to edit wp-config.php and replace the existing mysql username/password and mysql database name, with the one for your imported mysql database name, username/password

    Preview Centmin Mod Domain Before DNS Updates



    If you want to preview cpdomain.com on new centminmod server without updating DNS, on Windows PC edit your windows HOSTS file at c:\Windows\System32\Drivers\etc\hosts (see guide at Modify your hosts file | Knowledge Center | Rackspace Hosting or install Hostman app HostsMan - abelhadigital.com which can manage the file too and allows easy dns flushing when you make changes to the hosts file.

    c:\Windows\System32\Drivers\etc\hosts contents to preview without DNS update
    Code:
    centminmodserver-ip-address cpdomain.com
    to disable preview comment it out and flush dns for your system
    Code:
    #centminmodserver-ip-address cpdomain.com
    Hostsman app to flush dns and edit the c:\Windows\System32\Drivers\etc\hosts file
     
    Last edited: Jul 8, 2017
  5. eva2000

    eva2000 Administrator Staff Member

    30,160
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,135
    Local Time:
    8:18 PM
    Nginx 1.13.x
    MariaDB 5.5

    cPanel/WHM Migration Without Pkgacct Transfer



    Previous post shows how you would use cPanel /scripts/pkgacct method to package and do full backup of your cPanel site username account and transfer that back to Centmin Mod server for extraction and importing of mysql database, mysql user and site public web root files.

    This next method is for just transferring mysql database, mysql user and site public web root files without using cPanel /scripts/pkgacct and assumes the same CSF Firewall rules are whitelisting both servers first and that you already created Centmin Mod Nginx vhost domain using centmin.sh menu option 2, 22 or nv command outlined here Nginx Vhost & NSD DNS Setup - CentminMod.com LEMP Nginx web stack for CentOS

    Step 1. Setup Screen session so disconnections from SSH will allow processes to survive till completion.

    Install Screen
    Code (Text):
    yum -y install screen
    

    Create Screen session named migrate and attach it
    Code (Text):
    screen -dmS migrate
    screen -r migrate
    


    Step 2. Log into cPanel/WHM source data server and define your remoteip, port details on SSH command line. You need to type these into your SSH client session to set their values. They will only survive in the current SSH client session. If you exit it, you will need to retype these before you run the rest of the commands outlined below. Which will also create a directory at /home/backupsql to storage your MySQL database backups
    Code (Text):
    remoteip=111.222.333.444
    port=22
    backupdir=/home/backupsql
    DUMPOPT='-Q -K --max_allowed_packet=256M --net_buffer_length=65536 --routines --events --triggers --hex-blob'
    CLIENTOPT='--max_allowed_packet=256M --net_buffer_length=65536'
    mkdir -p $backupdir
    


    Rsync relevant data which assumes on remote destination server, centmin mod is installed but no vhosts or mysql databases have been created. It also assumes /root/.my.cnf is setup for mysql root user password which is automatically done on initial Centmin Mod installs

    file data with rsync options -avzin where n is for dry run so no data is actually transferred. If all the dry runs look good, remove n to become -avzi for the below commands.

    Rsync Dry Run

    On cPanel/WHM server in SSH type:
    Code (Text):
    rsync -avzin --progress --stats -e "ssh -p $port" /home/cpdomain/public_html/ root@$remoteip:/home/nginx/domains/cpdomain.com/public/
    

    Dry run output example would end with stats like
    Code (Text):
    Number of files: 117
    Number of files transferred: 0
    Total file size: 3190617 bytes
    Total transferred file size: 0 bytes
    Literal data: 0 bytes
    Matched data: 0 bytes
    File list size: 3458
    File list generation time: 0.001 seconds
    File list transfer time: 0.000 seconds
    Total bytes sent: 3847
    Total bytes received: 388
    
    sent 3847 bytes  received 388 bytes  941.11 bytes/sec
    total size is 3190617  speedup is 753.39 (DRY RUN)
    

    Notice 0 files were transferred because, I had previously used cPanel /scripts/pkgacct method to populate and restore data from /home/cpanel-data/cpmove-cpdomain/homedir/public_html to /home/nginx/domains/cpdomain.com/public

    If you didn't do cPanel /scripts/pkgacct method, then dry run rsync command out tell you the number of files transferred
    Code (Text):
    Number of files: 117
    Number of files transferred: 117
    Total file size: 3190617 bytes
    Total transferred file size: 3011158 bytes
    Literal data: 0 bytes
    Matched data: 0 bytes
    File list size: 3458
    File list generation time: 0.001 seconds
    File list transfer time: 0.000 seconds
    Total bytes sent: 3847
    Total bytes received: 388
    
    sent 3847 bytes  received 388 bytes  498.24 bytes/sec
    total size is 3190617  speedup is 753.39 (DRY RUN)
    


    Live Rsync Run

    Now live rsync run minus the n flag. On cPanel/WHM server in SSH type:

    Code (Text):
    rsync -avzi --progress --stats -e "ssh -p $port" /home/cpdomain/public_html/ root@$remoteip:/home/nginx/domains/cpdomain.com/public/
    


    On Centmin Mod LEMP stack server in SSH as root user, change user/group ownership for the files
    Code (Text):
    chown -R nginx:nginx /home/nginx/domains/cpdomain.com/public
    

    verify the listing directory for /home/nginx/domains/cpdomain.com/public
    Code (Text):
    ls -lah /home/nginx/domains/cpdomain.com/public
    total 3.4M
    drwxr-s--- 3 nginx nginx 4.0K May  4 18:13 .
    drwxr-s--- 6 nginx nginx 4.0K May  4 18:13 ..
    -rw-r--r-- 1 nginx nginx  86K May  1 14:49 001.png
    -rw-r--r-- 1 nginx nginx 5.7K May  1 14:49 001.png.webp
    -rw-r--r-- 1 nginx nginx  93K May  1 14:49 002.png
    -rw-r--r-- 1 nginx nginx 8.7K May  1 14:49 002.png.webp
    -rw-r--r-- 1 nginx nginx  63K May  1 14:49 003.png
    -rw-r--r-- 1 nginx nginx 5.7K May  1 14:49 003.png.webp
    -rw-r--r-- 1 nginx nginx  81K May  1 14:49 004.png
    -rw-r--r-- 1 nginx nginx 9.9K May  1 14:49 004.png.webp
    -rw-r--r-- 1 nginx nginx 110K May  1 14:49 005.png
    -rw-r--r-- 1 nginx nginx  15K May  1 14:49 005.png.webp
    -rw-r----- 1 nginx nginx 1.6K May  4 18:13 403.html
    -rw-r----- 1 nginx nginx 1.6K May  4 18:13 404.html
    -rw-r----- 1 nginx nginx 2.1K May  4 18:13 500.html
    -rw-r----- 1 nginx nginx 2.1K May  4 18:13 502.html
    -rw-r----- 1 nginx nginx 2.2K May  4 18:13 503.html
    -rw-r----- 1 nginx nginx 7.6K May  4 18:13 503.jpg
    -rw-r----- 1 nginx nginx 2.1K May  4 18:13 504.html
    -rw-r----- 1 nginx nginx 2.2K May  4 18:13 50x.html
    -rw-r--r-- 1 nginx nginx  71K May  1 14:49 bees.png
    -rw-r--r-- 1 nginx nginx 5.0K May  1 14:49 bees.png.webp
    


    To read up more on rsync usage see

    Step 3. Backing up MySQL databases for transfer. On cPanel/WHM server as root user in SSH type the following if you haven't already

    Code (Text):
    remoteip=111.222.333.444
    port=22
    backupdir=/home/backupsql
    DUMPOPT='-Q -K --max_allowed_packet=256M --net_buffer_length=65536 --routines --events --triggers --hex-blob'
    CLIENTOPT='--max_allowed_packet=256M --net_buffer_length=65536'
    mkdir -p $backupdir
    


    Then to backup databases locally list all your mysql database names in space separated entry in DBNAME variable so if you had 2 domains set DBNAME='cpdomain_mysql1 cpdomain_mysql2'

    As example only has one MySQL database name - you will be prompted for Centmin Mod root user password as a remote connection is made to create the database name and then backup locally to cPanel/WHM server directory at /home/backupsql/cpdomain_mysql1.sql
    Code (Text):
    DBNAME='cpdomain_mysql1'
    for db in $DBNAME; do ssh root@$remoteip -p $port mysqladmin create $db; mysqldump $DUMPOPT $db > $backupdir/$db.sql; done
    

    The assumption is on Centmin Mod remote server the mysql database name doesn't exist yet. If it does you'd get an error saying already exists but the local mysql backup does continue
    Code (Text):
    mysqladmin: CREATE DATABASE failed; error: 'Can't create database 'cpdomain_mysql1'; database exists'
    

    You can verify the backup file /home/backupsql/cpdomain_mysql1.sql listing it
    Code (Text):
    ls -lah /home/backupsql/cpdomain_mysql1.sql
    -rw-r--r-- 1 root root 2.6K May  4 18:53 /home/backupsql/cpdomain_mysql1.sql
    


    Step 4. Once you have backed up all databases. Transfer the MySQL database local backup directory /home/backupsql completely to remote Centmin Mod server using again rsync

    Rsync Dry Run you will be prompted for Centmin Mod root user password as a remote connection
    Code (Text):
    rsync -avzin --progress --stats -e "ssh -p $port" ${backupdir}/ root@$remoteip:${backupdir}/
    

    Sample output
    Code (Text):
    sending incremental file list
    created directory /home/backupsql
    cd+++++++++ ./
    <f+++++++++ cpdomain_mysql1.sql
    
    Number of files: 2
    Number of files transferred: 1
    Total file size: 2584 bytes
    Total transferred file size: 2584 bytes
    Literal data: 0 bytes
    Matched data: 0 bytes
    File list size: 45
    File list generation time: 0.001 seconds
    File list transfer time: 0.000 seconds
    Total bytes sent: 60
    Total bytes received: 18
    
    sent 60 bytes  received 18 bytes  12.00 bytes/sec
    total size is 2584  speedup is 33.13 (DRY RUN)
    

    So 2 files are going to be transferred, the /home/backupsql directory and the file /home/backupsql/cpdomain_mysql1.sql file.

    Rsync Live Run minus n flag
    Code (Text):
    rsync -avzi --progress --stats -e "ssh -p $port" ${backupdir}/ root@$remoteip:${backupdir}/
    


    Once transferred, on remote Centmin Mod server verify that /home/backupsql exists
    Code (Text):
    ls -lah /home/backupsql
    total 12K
    drwxr-xr-x   2 root root 4.0K May  4 18:53 .
    drwxr-xr-x. 13 root root 4.0K May  4 19:00 ..
    -rw-r--r--   1 root root 2.6K May  4 18:53 cpdomain_mysql1.sql
    


    Step 5. On Centmin Mod server, next step is importing actual MySQL data from sql backup file at /home/backupsql/cpdomain_mysql1.sql into the newly created cpdomain_mysql1 database we just made. This can take seconds, minutes or even hours to complete depending on size of database and your server /etc/my.cnf settings and server hardware specs. You'd want to temporarily edit /etc/my.cnf wait_timeout = 1800 value to 28800 seconds and restart mysql server first as well.

    Type as root user in SSH
    Code (Text):
    CLIENTOPT='--max_allowed_packet=256M --net_buffer_length=65536'
    mysql $CLIENTOPT cpdomain_mysql1 < /home/backupsql/cpdomain_mysql1.sql
    

    verify the database tables were imported changing the last part of command LIKE 'cpdomain_mysql1';" to your databasename
    Code (Text):
    mysql -t -e "SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows,2),' Rows') AS 'Number of Rows',ENGINE AS 'Storage Engine',CONCAT(ROUND(data_length/(1024*1024),2),'MB') AS 'Data Size',CONCAT(ROUND(index_length/(1024*1024),2),'MB') AS 'Index Size' ,CONCAT(ROUND((data_length+index_length)/(1024*1024),2),'MB') AS'Total', ROW_FORMAT, TABLE_COLLATION FROM information_schema.TABLES WHERE table_schema LIKE 'cpdomain_mysql1';"
    

    output
    Code (Text):
    +--------------------+----------------+----------------+-----------+------------+--------+------------+-------------------+
    | Table Name         | Number of Rows | Storage Engine | Data Size | Index Size | Total  | ROW_FORMAT | TABLE_COLLATION   |
    +--------------------+----------------+----------------+-----------+------------+--------+------------+-------------------+
    | cpdomain_mysql1.t1 | 0 Rows         | InnoDB         | 0.02MB    | 0.08MB     | 0.09MB | Compact    | latin1_swedish_ci |
    +--------------------+----------------+----------------+-----------+------------+--------+------------+-------------------+
    

    Now to replay the MySQL user cpdomain_user1 grants and permissions on Centmin Mod LEMP server you would use the data gathered from cPanel server show grants command
    Code (Text):
    mysql -e "show grants for cpdomain_user1@'localhost';"
    +-----------------------------------------------------------------------------------------------------------------------+
    | Grants for cpdomain_user1@localhost                                                                                   |
    +-----------------------------------------------------------------------------------------------------------------------+
    | GRANT USAGE ON *.* TO 'cpdomain_user1'@'localhost' IDENTIFIED BY PASSWORD '*49FDCFE1EB93E79C252E71C3E56AD87558F61EF6' |
    | GRANT ALL PRIVILEGES ON `cpdomain\_mysql1`.* TO 'cpdomain_user1'@'localhost'                                          |
    +-----------------------------------------------------------------------------------------------------------------------+
    

    Replay those 2 SQL queries on Centmin Mod server as root user in SSH tagging on end of them a semi-colon ;
    1st command
    Code (Text):
    mysql -e "GRANT USAGE ON *.* TO 'cpdomain_user1'@'localhost' IDENTIFIED BY PASSWORD '*49FDCFE1EB93E79C252E71C3E56AD87558F61EF6'"
    

    2nd command

    Due to backslashes having different meaning on SSH command line to mean a command, the GRANT command needs to change and remove the backslashes for
    Code (Text):
    `dbname2`.*
    

    to become
    Code (Text):
    dbname2.*
    

    So becomes SSH command to run, it will return empty if successful
    Code (Text):
    mysql -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON dbname2.* TO 'dbuser1'@'localhost';"
    

    Verify the cpdomain_user1 user was created with appropriate grant privileges
    Code (Text):
    mysql -e "show grants for cpdomain_user1@'localhost';"                  
    +-----------------------------------------------------------------------------------------------------------------------+
    | Grants for cpdomain_user1@localhost                                                                                   |
    +-----------------------------------------------------------------------------------------------------------------------+
    | GRANT USAGE ON *.* TO 'cpdomain_user1'@'localhost' IDENTIFIED BY PASSWORD '*49FDCFE1EB93E79C252E71C3E56AD87558F61EF6' |
    | GRANT ALL PRIVILEGES ON `cpdomain\_mysql1`.* TO 'cpdomain_user1'@'localhost'                                          |
    +-----------------------------------------------------------------------------------------------------------------------+
    


    Step 6. Now your Nginx vhost config files would be at /usr/local/nginx/conf/conf.d/cpdomain.com.conf and/or /usr/local/nginx/conf/conf.d/cpdomain.com.ssl.conf as per Centmin Mod Configuration Files - CentminMod.com LEMP Nginx web stack for CentOS and would need to be altered according for your specific web app/script's Nginx rules i.e. Nginx Configuration Examples - CentminMod.com LEMP Nginx web stack for CentOS

    If you used centmin.sh menu option 22 to auto install Wordpress on centmin mod server, then your Nginx vhosts will already have the correct Wordpress Nginx rules, just need to edit wp-config.php and replace the existing mysql username/password and mysql database name, with the one for your imported mysql database name, username/password

    Preview Centmin Mod Domain Before DNS Updates



    If you want to preview cpdomain.com on new centminmod server without updating DNS, on Windows PC edit your windows HOSTS file at c:\Windows\System32\Drivers\etc\hosts (see guide at Modify your hosts file | Knowledge Center | Rackspace Hosting or install Hostman app HostsMan - abelhadigital.com which can manage the file too and allows easy dns flushing when you make changes to the hosts file.

    c:\Windows\System32\Drivers\etc\hosts contents to preview without DNS update
    Code:
    centminmodserver-ip-address cpdomain.com
    to disable preview comment it out and flush dns for your system
    Code:
    #centminmodserver-ip-address cpdomain.com
    Hostsman app to flush dns and edit the c:\Windows\System32\Drivers\etc\hosts file
     
    Last edited: Jul 8, 2017
  6. eva2000

    eva2000 Administrator Staff Member

    30,160
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,135
    Local Time:
    8:18 PM
    Nginx 1.13.x
    MariaDB 5.5

    Summary



    The above steps outline how to transfer a cPanel/WHM site account domain to Centmin Mod LEMP server for data files, mysql database and mysql user/passwords. These steps are basically the same process for any site transfer from server to server regardless of control panels. Sure directory paths would be different etc but rsync, mysqldump, mysql client import and replaying mysql usernames for insertion are always the same.

    These skills are must learn and should be practiced regularly to become second nature as you willl always need these skills when you move servers.

    You can do test migrations from live cPanel/WHM to test Centmin Mod server without updating domain DNS and using above trick preview the domain on Centmin Mod server via hosts file edits. You don't even need to update domain DNS and just switch between live cPanel/WHM and test Centmin Mod domain copies just for testing until you are comfortable with a live migration.
     
Thread Status:
Not open for further replies.