Server Migration with rsync (Linux)

This guide explains how to migrate a server from your old to your new server using rsync.


Prerequisites

  • Access to both servers (old and new) via SSH
  • The new server already has a partition layout that matches the old server
  • rsync is installed on both servers


1. Preparation

Note: Device names may vary depending on the system (e.g. nvmeXnY, sdX). Verify the correct device identifiers before proceeding.

lsblk fdisk -l

Partition and format the disks:

fdisk /dev/sdX mkfs.ext4 /dev/sdX1 mkfs.ext4 /dev/sdX2

Mount the partitions:

mkdir -p /mnt/newroot mount /dev/sdX1 /mnt/newroot

Mount the source:

mkdir -p /mnt/source mount /dev/sdY1 /mnt/source

If EFI is present:

mkdir -p /mnt/source/boot/efi mount /dev/sdY2 /mnt/source/boot/efi


2. Transferring the data with rsync

rsync -aAXHv --numeric-ids --delete --info=progress2 \ --exclude={"/proc/*","/sys/*","/dev/*","/run/*","/tmp/*","/mnt/*","/media/*","/lost+found"} \ -e "ssh -p 22" \ /mnt/source/ root@DESTSERVER:/mnt/newroot/

Verification:

du -sh /mnt/newroot


3. Post-processing

mount --bind /dev /mnt/newroot/dev mount --bind /proc /mnt/newroot/proc mount --bind /sys /mnt/newroot/sys chroot /mnt/newroot /bin/bash

Optional for paravirtualized vServer G1:

apt update apt install grub2 linux-image-cloud-amd64 qemu-guest-agent cloud-init

Reinstall the bootloader:

grub-install /dev/sdX update-grub

Check the network configuration:

nano /etc/network/interfaces nano /etc/network/interfaces.d/50-cloud-init

Reboot:

reboot


Additional resources

Rsync documentation: https://linux.die.net/man/1/rsync