目录

Move a VPS to a different datacenter

The migration of VPS to a different datacenter can be completed in several steps. Of course, this can get more or less tricky, depending on the services running on your system.

To better understand, we will take this simple example. We have a VPS in Paris (named parisVM ) with only one disk, its system disk. We want to migrate this server to the Luxembourg, we will call it 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 and a disk in the desired location
  4. Create a new disk from the snapshot taken previously
  5. Update the DNS zone file(s) of the domain(s) pointing to the former VPS to point to the new VPS/IP

Commands starting with $ gandi refer to our CLI.

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

into :

auto eth0
iface eth0 inet dhcp

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

Before:

CONFIG_NODHCP="eth0"

After:

CONFIG_NODHCP=""

Step 2 - Take a snapshot

Just in case, we take a snapshot of the system disk of parisVM. First, stop the server and take a snapshot of its system disk.

This can be done using the CLI:

$ gandi disk list
$ gandi disk snapshot <system-disk-name> --name <name-of-the-snapshot>

Or via your account interface.

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.

$ gandi vm create --hostname luxVM --datacenter LU --ip-version 4 --memory 512 --cores 2 --image 'Ubuntu 14.04 64 bits LTS (HVM)' --password
password: 
**Repeat for confirmation:** 
* root user will be created.
* Configuration used: 2 cores, 512Mb memory, ip v4+v6, image Debian 7 64 bits (HVM), hostname: luxVM, datacenter: LU
Creating your Virtual Machine luxVM.
Progress: [###################################] 100.00%  00:00:57  
Your Virtual Machine luxVM has been created.
Waiting for the vm to come online

Step 4 - Create a new disk

The disk that we are going to create will contain the data of the system disk of the former server (parisVM). The copy of the data disk will be done later.

Let's create the disk:

This disk should be the same size (or bigger) as the former system disk.

$ gandi disk create --datacenter LU --name sys-lux --size 5G --vm luxVM
Creating your disk.
Progress: [#######################################] 100.00%  00:00:39
Attaching your disk.
Progress: [#######################################] 100.00%  00:00:29

Here, the disk is created and attached to the new server, luxVM.

Connect (via ssh) to the new server:

$ gandi vm ssh luxVM

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.

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

Replace it with:

PermitRootLogin yes

in

/etc/ssh/sshd_config

And 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 (previously created in step 4). The copy will be done using the dd command.

First, duplicate your system disk :

$ gandi disk create --datacenter FR --source sys-fr --vm parisVM
Creating your disk.
Progress: [##########################################################] 100.00%  00:00:22
Attaching your disk.
Progress: [##########################################################] 100.00%  00:00:23

Then SSH to the former server :

$ gandi vm ssh parisVM

Un-mount the disk just created :

df -h
/dev/xvdb       5.0G  /srv/UBUNTU14.04_64
umount /dev/xvdb

Launch the copy of the disk:

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):

$ gandi disk update sys-lux --kernel 3.2-x86_64
Updating your disk.
Progress: [###############################################] 100.00%  00:00:26

Stop the server luxVM :

$ gandi vm stop luxVM
Stopping your Virtual Machine(s) 'luxVM'.
Progress: [###########################################] 100.00%  00:00:35

Detach the disk sys-lux from luxVM :

$ gandi disk detach sys-lux
Are you sure you want to detach sys-lux? [y/N]: y
The disk is still attached to the vm 166658.
Will detach it.
Detaching your disk(s).
Progress: [########################################] 100.00%  00:00:04

Attach it again to luxVM, but this time will indicate the disk as being the one to boot from:

$ gandi disk attach sys-lux --position 0 luxembourg
Are you sure you want to attach disk 'sys-lux' to vm 'luxembourg' [y/N]: y
Attaching your disk(s).
Progress: [################################################] 100.00%  00:00:20

Start the server:

$ gandi vm start luxVM

You should be all set. But of course you want to make sure that is the case:

$ gandi vm ssh luxVM

Edit the DNS zone file(s)

Again, this can be done via your web interface or via the CLI.

Using the CLI


List existing DNS zone file entries for your domain:

$ gandi record list example.net

Delete the relevant entry (e.g. the A record for the www subdomain):

$ gandi record delete example.net --name www

Then create a new one with the IP address of your new VM:

$ gandi record create example.net --name www --type A --value <ip-of-luxVM> --ttl 3600

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