Latest news from 5wire Networks

How to migrate a Linux VPS Cloud Server with rsync

If you’re looking to move to a different Virtual Server Cloud Hosting Provider for your Linux Server,  you will be looking to do so with minimal effort.

We recommend using rsync to manage the migration due to its ease of use and efficiency. Rsync is a powerful utility that synchronizes files and directories between two locations while minimizing data transfer by only copying the differences between the source and destination.

This is a basic step-by-step guide on how to migrate a Linux server using rsync.

Prerequisites

  • Destination Server is your new Linux VPS Cloud Server
  • Source Server is your existing Linux VPS Cloud Server

Prepare the Destination Server

The Destination Server is your new Linux VPS Cloud Server. This is where you will be transferring your files to.

  • Install the new Linux Cloud Server that will act as the Destination Server
  • You must use the same Linux Kernel / Operating System

When you have installed the Destination Server, we recommend running package update by the command line and rebooting the server as a precaution if the installation did not fetch the latest updates.

apt-get update -y

yum update -y

Reboot the server once all packages updated.

SSH Configuration

SSH will be used to transfer the files using rsync. 

Planning the Migration

Decide which directories and files you need to migrate from the Source Server to the Destination Server.

You may wish to exclude any files or directories from the migration, such as the Network Configuration.

Make sure that you have a Snapshot / Backup of your Source Server before continuing after this step.

Perform the Migration

  1. Log in to the Source Server via SSH
  2. Use the rsync command to copy the files and directories from the Source Server to the Destination Server.

rsync -avz --exclude=EXCLUDE_PATTERN SOURCE_DIRECTORY/ DESTINATION_SERVER:DESTINATION_DIRECTORY/

  • -a (archive): Preserves permissions, ownership, timestamps, etc.
  • -v (verbose): Provides verbose output.
  • -z (compress): Compresses data during transfer to reduce bandwidth usage.
  • --exclude: Allows you to specify patterns of files or directories to exclude from the sync. Replace EXCLUDE_PATTERN with your exclusion pattern.
  • Replace SOURCE_DIRECTORY with the directory you want to migrate from on the source server.
  • Replace DESTINATION_SERVER with the username and IP address or hostname of the destination server.
  • Replace DESTINATION_DIRECTORY with the directory you want to migrate to on the destination server.

Verify the Migration

Once the migration has been completed, verify that all necessary files and directories have been transferred.

Testing

Reboot the server and test that everything has migrated and is working as expected.

Sometimes when running a Live System with a large amount of disk space, files may change on the Source Server. By running the rsync command again, only files that have been changed on the Source Server will be transferred and will overwrite on the Destination Server.

Update DNS and Configuration

When you are satisfied that all files have been transferred, and the migration requires a change to DNS or network configuration, make sure to update them now.

After this, you’re good to go!

Common Questions 

SSH Port

Using any port other than 22 for rsync will require an additional parameter to be added to the command line. Assuming you’re using port 1234 for SSH, add the following to the rsync command

-e 'ssh -p 1234'

How to show rsync progress?

To display the progress of the rsync during the migration add the following to the command line:

--progress

Destination Server will have a different IP address

When moving your Linux Virtual Private Server to a new host, you will not be able to transfer the IP address from the previous host. When your Destination Server is installed, and your new IP address is configured, you must exclude the network configuration directory from the Source Server in the rsync command.

Below is an example of the exclusion for AlmaLinux:

--exclude /etc/sysconfig/network-scripts/

How to exclude multiple folders with rsync?

You can exclude multiple files and directories in the rsync command. You can use the --exclude options multiple times in one command.

--exclude /etc/sysconfig/network-scripts/ --exclude /home/