This topic describes how to perform a batch migration of servers by running scripts. Batch server migration is useful when you need to migrate a large amount of servers at a time.

Context

Automated O&M tools (for example, Ansible) are generally used to manage a large group of server systems. With Ansible, you can easily complete repetitive work. For example, you can copy the same file to 100 servers or install and start the Apache service on 100 servers simultaneously.

Automated O&M tools allow you to distribute and run scripts in batches. The Cloud Migration tool provided by Alibaba Cloud is a client program that can be used without any installation or complicated configurations required.

Procedure

  1. Prepare an automated batch O&M tool.

  2. Use command lines to call the Cloud Migration tool.

    The Cloud Migration tool provides a series of command line parameters that apply to scenarios where you want to call the Cloud Migration tool. For example:
    • --noenterkey: disables interaction.
    • --nocheckversion: disables version update notification.
    • --progressfile: sets the progress log file.
  3. Create scripts for batch migration.

    Create scripts for automated batch migration task as needed. The scripts include the following operations:

    1. Distribute the Cloud Migration tool to the servers to be migrated.
    2. Configure the Cloud Migration tool.
    3. Run the Cloud Migration tool and obtain the migration task result.

Example scripts

# Send the Cloud Migration tool program to all servers.

ansible -f 6 -i host.file all -m copy -a
"src=go2aliyun_client1.2.9.1_linux_x86_64.zip dest=/temp"

# Decompress the program.

ansible -f 6 -i host.file all -m shell -a "cd /temp &&
unzip \

go2aliyun_client1.2.9.1_linux_x86_64.zip"

# Run the scripts that modifies the configuration file.

ansible -f 6 -i host.file all -m shell -a "cd
/temp/go2aliyun_client1.2.9.1_linux_x86_64 && ./config.sh"

sleep 120

# The configuration file script ". /config.sh" is used to configure the target image name according to the subnet IP address. (Other items such as AK, zone, and disk information have been configured)

#! /bin/bash

image_name=`ip a | grep inet | grep eth0 | grep brd | awk '{print
$2}' | awk -F '/' '{print $1}'| awk -F '.' '{print
"move_"$1"_"$2"_"$3"_"$4}'`

sed -i "s/IMAGE_NANE/${image_ame}/" user_config.json

 

# Run six migration scripts at the same time.

ansible -f 6 -i host.file all -m shell -a "cd
/temp/go2aliyun_client1.2.9.1_linux_x86_64 && chmod +x go2aliyun_client
&&./go2aliyun_client --nocheckversion --noenterkey"

# Obtain the cloud migration result by obtaining the generated image ID and the migration status from client_data.

# Check the status displayed in client_data. If the status is Finished, it means that the cloud migration is completed. The image_id field is the generated image ID.