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 :
- Prepare the system (of the server ParisVM) to be migration-ready.
- Stop the server and take a snapshot of the disk.
- Create the new server (LuxVM) and a disk in the desired location.
- Create a new disk from the snapshot taken previously.
- 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 126.96.36.199
auto eth0 iface eth0 inet dhcp
Also, remove eth0 from the variable
So, we will change this:
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.
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.
Next, restart SSH:
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.