Server Migration Full Process

12006

Learning Objectives

  • Understand the basic steps of server migration: including generating migration packages, migrating data, and synchronizing online.
  • Master how to use the vm os_tool script tool for server migration.
  • Learn to configure and test the new server.

1. Server Migration

Server migration generally refers to the process of transferring data, applications, services, and their configurations from one physical, virtual, or cloud environment to another.

Typically, server migration occurs for the following reasons:

  • The hardware or software of the server needs to be updated or upgraded.
  • Data center changes require migrating the server from one data center to another.
  • To enhance disaster recovery capabilities and ensure business continuity, it may be necessary to launch an identical server in a different geographical location.

Before migrating the server, it is essential to list the data to be migrated and develop a suitable migration plan to ensure a smooth transition and minimize the impact on business operations.

In this lesson, we will introduce how to use the Jianghu panel's script tool for server migration, mainly covering the following content:

  • Generating a migration data package for the data to be migrated.
  • Transferring it to the new server.
  • Restoring the data package on the new server.
  • Switching the online and offline status of the original and new servers.

Before performing the server migration, the new server must be started, and the following configurations must be completed:

  • The network between the original server and the new server is connected.
  • The Jianghu panel has been installed on the new server, along with the required plugins.
  • The SSH key for the required code repository has been configured on the new server.

2. Basic Steps of Server Migration

Server migration typically includes two main steps: first, generating a migration package containing all files, which is a full data migration process; second, restoring the data on the new server.

Generating the Migration Package:

  1. Run the Jianghu panel script tool jh 22 in the terminal and select 3. Server Migration to start generating the migration package.
  2. Select the data to be migrated, usually including: xtrabackup database backups, project files in the /www/wwwroot directory, website site data, and data from the JianghuJS manager plugin. Enter the relevant information as prompted to generate the migration package file. Since the migration package file can be large, it is recommended to ensure sufficient storage space on the server before migration.
  3. After the data migration package is generated, you can choose whether to package and transfer the migration package to the new server. If you choose to transfer, you can enter the new server's IP, SSH port, username, and password to start the transfer.

Restoring Data:

  1. After the migration package transfer is complete, first unzip the migration package file on the new server, then execute the following command in the unzipped directory to start data restoration:
bash deploy.sh  

The script file deploy.sh contains different restoration scripts prepared according to the data types selected when generating the migration package.
2. After the data restoration is complete, you can perform the following checks to ensure the data has been successfully restored:

  • Database checks
    • Check the running status of the MySQL server: Open the MySQL management interface, and you can view the current running status of MySQL in the "Services" section.
    • CheckSum comparison: Open the MySQL management interface --> "Management List" --> "Get Checksum Report" to generate a Checksum for each database and data table.
      • Calculate the Checksum of the MySQL databases on the original server and the new server, then use a text comparison tool to find data tables with inconsistent Checksum values. If there are no significant differences in Checksum, it indicates that the database restoration was successful.
      • You can ignore rapidly changing business data tables, such as _record_history, _user_session, etc.
    • Check whether the root user password for the database matches the root password of the original server.
  1. Start all projects in the JianghuJS manager.
  2. Configure the local host file to debug whether the website is functioning correctly. You can open the website page and click the "Get Site Host Configuration" button above the site list to obtain the IP address and website site list.

3. Official Online Synchronization

After restoring the migration package data, you can prepare to officially bring the new server online. This process typically includes data file synchronization, taking the old server offline, and bringing the new server online. The Jianghu panel script tool provides scripts for taking the old server offline and bringing the new server online.

Taking the Old Server Offline:

  1. Run the Jianghu panel script tool jh 22 in the old server terminal, and sequentially select 9. Server Switch --> 1. Get Server Offline Script to generate the offline script, which will be saved in /tmp/offline.sh.
  2. The offline.sh script includes steps to stop xtrabackup incremental backups, xtrabackup, mysqldump scheduled tasks, and stop email notifications.
  3. Run the offline.sh script to take the old server offline.

Bringing the New Server Online:

  1. Run the Jianghu panel script tool jh 22 in the new server terminal, and sequentially select 9. Server Switch --> 2. Get Server Online Script to generate the online script, which will be saved in /tmp/online.sh.
  2. The online.sh script includes steps to execute xtrabackup incremental recovery, update the wwwroot directory, start xtrabackup incremental backups, mysqldump scheduled tasks, and enable email notifications.
  3. Run the online.sh script to bring the new server online.
  4. Check whether the server program is running normally; if everything is fine, you can officially switch to the new server.
  5. In your domain management service, configure the DNS resolution for the website on the server to point to the IP of the new server, allowing users to access your website and services through the new server.

Note: During the process of generating, transferring, and restoring the migration package, if it takes a long time, the data and files on the old server may have been modified by users and changed. Therefore, during the server status switch, a data synchronization may often be required. The online.sh script will ask you whether you need to update files from the target server to the local server. If you choose "Yes," you can specify the directories and files that need to be updated.

Assignment

Please complete a server migration based on the content of this article, with the following requirements:

  • The website on the new server can be accessed normally.
  • The database data is complete and not lost.
  • All plugins are correctly installed and functioning properly.