Migrating a Server Data to another Server data

Booting into Rescue Mode

Before you initiate the transfer, you need to start the server in rescue mode. Here’s how:

Boot your server into Rescue Mode. For instructions, see Booting into Rescue Mode. Be sure to set the primary disk image to /dev/xvda and the swap image to /dev/xvdb.

After the Server has booted, connect to it via Console.

Start SSH. For instructions, see Start SSH.

Mount the blank primary disk image by entering the following command:

mount -o barrier=0 /dev/xvda
Your Server is now ready to receive the files from your existing server.

Copying the Files
You’ve created disk images on the Linode to receive the files from the existing server, and you’ve created configuration profiles to boot into rescue mode and from the new disk images. Now it’s time to transfer files from the existing server to the Linode.

Stopping Services

At this point, you should stop as many services as possible on the existing server. This includes web server daemons (Apache and nginx), database servers (PostgreSQL and MySQL), and any other non-critical services. To stop a service, enter the following command, replacing apache2 with the name of the service you want to stop:

sudo service apache2 stop
Initiating the Transfer

Now it’s time to copy the files from your existing server to your Linode. Here’s how:

Connect to your existing server via SSH and log in as root.

Enter the following command to initiate the copy, replacing 123.45.67.890 with your Linode’s IP address. (For instructions on finding your Linode’s IP address, see Finding the IP Address.)

rsync –exclude=”/sys/*” –exclude=”/proc/*” -aHSKDvz -e ssh / root@123.45.67.890:/media/xvda/
Note
If you receive a message indicating that the rsync command couldn’t be found, you’ll need to install it by entering apt-get install rsync on Ubuntu or Debian. If you’re using a different distribution, you may need to enter a different command.
The files on your existing server will be copied to your Linode. Depending on the amount of data stored on existing server, the network copy may take a long time. You can monitor the progress from your current server’s SSH session.

Configuring the Disk Images
Now the files from your existing server are stored on your Linode. You can’t boot from the new disk images yet, however. First, you’ll need to do some things to the disk images, like set the IP address to the IP address assigned to your Linode. Be sure to follow all of the instructions in this section before restarting your Linode from the new disk images!

Setting the IP Address

After the network copy is complete and the files from the existing server have been moved in to the disk images, you’ll need to update the existing server’s IP address with your Linode’s IP address. Here’s how:

On the Linode, which should still be running in rescue mode, enter the following command to change directories:

cd /media/xvda
Now enter the following command to replace all instances of your old IP address. Be sure to replace all instances of the old IP address with the new IP address. In this example, 98\\.76\\.54\\.32 is the old IP address and 12\\.34\\.56\\.78 is the Linode’s IP address:

find ./ -type f -exec sed -i ‘s/98\.76\.54\.32/12\.34\.56\.78/’ {} \;
The entire mounted filesystem will be recursively searched for any instances of your old IP address. Note that this replacement operation can take a while to complete.

Configuring Mount Points

Now you should configure mount points for the new disk images. Here’s how:

On the Linode, open the /media/xvda/etc/fstab file for editing by entering the following command:

nano /media/xvda/etc/fstab
Change the mount point for root to /dev/xvda, and the mount and swap to /dev/xvdb, as shown below:

File excerpt:/media/xvda/etc/fstab

# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/xvda / ext3 errors=remount-ro 0 1
/dev/xvdb none swap sw 0 0
proc /proc proc defaults 0 0
You have successfully configured the mount points for the disk images.

Configuring Device Nodes via Chroot

Verify that /media/xvda/dev is complete by making sure that all of the device node entries listed below are present. If they aren’t, you’ll need to chroot to the mount point and execute the MAKEDEV command. Here’s how:

Chroot to the mount point by entering the following command:

chroot /media/xvda /bin/bash
Enter the following command:

MAKEDEV /dev
If necessary, manually create xvd[a-h] device node entries by entering the following commands:

cd /dev
mknod xvda b 202 0
mknod xvdb b 202 16
mknod xvdc b 202 32
mknod xvdd b 202 48
mknod xvde b 202 64
mknod xvdf b 202 80
mknod xvdg b 202 96
mknod xvdh b 202 112
If /dev/hvc0 doesn’t exist, enter the following command:

mknod hvc0 c 229 0
Exit chroot by entering the following command:

exit
You have successfully configured device nodes via chroot.

Fixing Persistent Rules

Here’s how to fix persistent rules:

If your distribution is using udev (most distributions are these days), enter the following command on the Linode:

cd /media/xvda/etc/udev/rules.d
Open the file that creates the persistent network rules, which is usually 75-persistent-net-generator.rules, by entering the following command:

nano 75-persistent-net-generator.rules
Modify the file to remove eth* from the beginning of the kernel whitelist so that it does not create persistent rules for eth*. In this case we simply removed eth* from the beginning of the kernel whitelist. The relevant section in the file should resemble the following:

File excerpt:udev network rules

# device name whitelist
KERNEL!=”ath*|wlan*[0-9]|msh*|ra*|sta*|ctc*|lcs*|hsi*”, \
GOTO=”persistent_net_generator_end”
Remove any rules that were auto generated by entering the following command:

rm /media/xvda/etc/udev/rules.d/70-persistent-net.rules
Remove the cd rules file by entering the following command:

rm /media/xvda/etc/udev/rules.d/70-persistent-cd.rules
You have successfully fixed persistent rules.

Advertisements

Share your thoughts with us!!!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s