Move a Cloud Server to a Different Datacenter

This tutorial demonstrates how to move a cloud server from one datacenter to another. To demonstrate the process necessary, we will focus on a theoretical server in Paris named ParisVM. We will work on moving the data to a server in the Luxembourg datacenter named LuxVM.

Here are the key steps to perform this type of migration :

  1. Prepare the system (of the server ParisVM) to be migration-ready.
  2. Stop the server and take a snapshot of the disk.
  3. Create the new server (LuxVM) and a disk in the desired location.
  4. Create a new disk from the snapshot taken previously.
  5. Update the DNS zone file of the domain previously pointing to ParisVM so they point to LuxVM.

Step 1 - Prepare the Migration

By default, the primary network interface is configured statically. Since network interfaces cannot be moved between datacenters, the IP address will be changed (i.e. a new network interface will be created). Therefore, we need to set the primary interface to be configured automatically (using dhcp).

So, we need to change /etc/network/interfaces from this:

auto eth0
iface eth0 inet static
  address x.x.x.x
  netmask 255.255.254.0
  gateway 185.26.125.254

To this:

auto eth0
iface eth0 inet dhcp

Also, remove eth0 from the variable CONFIG_NODHCP in /etc/default/gandi.

So, we will change this:

CONFIG_NODHCP="eth0"

To this:

CONFIG_NODHCP=""

Step 2 - Take a Snapshot

In case something goes wrong during the migration, we will take a snapshot of the system disk of parisVM. First, stop the server, then take a snapshot<volume_snapshots>` of its system disk.

Step 3 - Create the New Server

Create a new server in the datacenter of your choice. In this example we are creating a new server in Luxembourg named LuxVM.

Step 4 - Create a New Disk

In this step we will create the disk where we will copy the data from ParisVM. We won’t actually copy the data until the next step.

First, on the new cloud server LuxVm, create a new volume. For our example, we will call it sys-lux.

Next, connect via ssh to the new server.

Un-mount the disk sys-lux. The mount command will help you identify the device:

mount
/dev/sda on / type ext4 (rw,noatime,errors=remount-ro)
[...]
/dev/sdc on /srv/sys-lux type ext3 (rw,nosuid,nodev,noatime)

umount /dev/sdc

We will also need to allow root to log in with a password, since by default password authentication is disabled for root. In the file /etc/ssh/sshd_config you will replace the following:

PermitRootLogin without-password allows root login only with public key authentication.

With this:

PermitRootLogin yes

Next, restart SSH:

/etc/init.d/ssh restart

Step 5 - Copy the Data to the New System Disk

In this step we will copy the data of the system disk on the former server, ParisVM, to the new system disk created in step four. The copy will be done using the dd command.

First, duplicate your system disk on ParisVM.

Then SSH to ParisVM.

Unmount the disk you just created:

Launch the copy of the disk, replacing “ip-of-LuxVM” with the ip of your new server:

dd iflag=direct bs=8k if=/dev/xvdb | ssh <ip-of-LuxVM> "dd bs=8k of=/dev/sdc"

The copy may take more or less time depending on the size of the source disk.

Step 6 - Make the New System Disk Bootable

Assign a kernel to the system disk, sys-lux in our case.

Next, stop the server LuxVM.

Now, detach the disk sys-lux from LuxVM.

Attach the disk to LuxVM again, but this time we will indicate this disk is the one to boot from.

Then, start the server.

At this point your server should be ready. To check, connect via ssh and verify that everything is as it should be.

Step 7 - Edit the DNS Records

Update your domain’s DNS records to point the new IP address.

The change will take about 3 hours to propagate, depending on when you last browsed to your site.