How to migrate a linux vps to another


Rsync is a powerful tool for migrate a linux vps to another.

Step 1: install in the new VPS with your old operating system

To find your Red Hat Enterprise Linux release use:

cat /etc/redhat-release

The result likes:

[root@tutorialspots ~]# cat /etc/redhat-release
CentOS release 5.10 (Final)

To find your kernel version use:

uname –a

The result likes:

[root@tutorialspots ~]# uname -a
Linux tutorialspots 2.6.32-042stab113.11 #1 SMP Fri Dec 18 17:32:04 MSK 2015 i686 i686
 i386 GNU/Linux

version linux system

Install this version of Linux (or approximate) in your new vps.

Step 2: Test the connection between the two servers

Use this command line in the new VPS:

ssh user@oldserverip

Example:

[root@tutorialspots ~]# ssh root@104.168.172.186
The authenticity of host '104.168.172.186 (104.168.172.186)' can't be establishe
d.
RSA key fingerprint is 23:9d:60:d8:2c:2c:32:42:20:7e:38:c0:c0:83:44:6c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '104.168.172.186' (RSA) to the list of known hosts.
root@104.168.172.186's password:
Last login: Wed Apr  6 17:57:47 2016 from xx.xx.xx.xx

Step 3: Check if Rsync is installed

By using this command line in your new VPS:

which rsync

Result:

[root@tutorialspots ~]# which rsync
/usr/bin/rsync

If this tool isn’t installed, install it by using the command line:

With CentOS

yum install rsync

With Ubunbu

apt-get install rsync

Step 4: Choose the exclude list

Here are some exclude lists:

With Centos

/etc/fstab
/etc/sysconfig/network-scripts/*
/proc/*
/tmp/*
/sys/*
/dev/*
/mnt/*
/boot/*
/root/*
/etc/ssh/*

With Ubuntu

/etc/fstab
/etc/network/*
/proc/*
/tmp/*
/sys/*
/dev/*
/mnt/*
/boot/*
/root/*
/etc/ssh/*

You can choose your own list.

Step 5: Stop mysql service in old VPS

service mysqld stop
[root@tutorialspots ~]# service mysqld stop
Stopping MySQL:                                            [  OK  ]

Step 6: migrate your VPS by rsync tool

Use this command (for CentOS)

rsync -auHxv -–numeric-ids -–exclude=/etc/fstab -–exclude=/etc/sysconfig/network-scripts/* -–exclude=/proc/* –exclude=/tmp/* -–exclude=/sys/* -–exclude=/dev/* -–exclude=/mnt/* -–exclude=/boot/* -–exclude=/root/* --exclude=/etc/ssh/* root@oldVPSip:/* /

Example result:

...
var/spool/repackage/
var/tinydns/
var/tinydns/env/
var/tinydns/env/IP
var/tmp/
var/www/
var/www/cgi-bin/
var/www/error/
var/www/error/HTTP_BAD_GATEWAY.html.var
var/www/error/HTTP_BAD_REQUEST.html.var
var/www/error/HTTP_FORBIDDEN.html.var
var/www/error/HTTP_GONE.html.var
var/www/error/HTTP_INTERNAL_SERVER_ERROR.html.var
var/www/error/HTTP_LENGTH_REQUIRED.html.var
var/www/error/HTTP_METHOD_NOT_ALLOWED.html.var
var/www/error/HTTP_NOT_FOUND.html.var
var/www/error/HTTP_NOT_IMPLEMENTED.html.var
var/www/error/HTTP_PRECONDITION_FAILED.html.var
var/www/error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
var/www/error/HTTP_REQUEST_TIME_OUT.html.var
var/www/error/HTTP_REQUEST_URI_TOO_LARGE.html.var
var/www/error/HTTP_SERVICE_UNAVAILABLE.html.var
var/www/error/HTTP_UNAUTHORIZED.html.var
var/www/error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
var/www/error/HTTP_VARIANT_ALSO_VARIES.html.var
var/www/error/contact.html.var
var/www/error/include/
var/www/html/
var/www/icons/
var/www/icons/README
var/www/icons/README.html
var/www/icons/a.png
var/www/icons/alert.black.png
var/www/icons/alert.red.png
var/www/icons/apache_pb.png
var/www/icons/apache_pb2.gif
var/www/icons/apache_pb2.png
var/www/icons/apache_pb2_ani.gif
var/www/icons/back.png
var/www/icons/ball.gray.png
var/www/icons/ball.red.png
var/www/icons/binary.png
var/www/icons/binhex.png
var/www/icons/blank.png
var/www/icons/bomb.png
var/www/icons/box1.png
var/www/icons/box2.png
var/www/icons/broken.png
var/www/icons/burst.png
var/www/icons/c.png
var/www/icons/comp.blue.png
var/www/icons/comp.gray.png
var/www/icons/compressed.png
var/www/icons/continued.png
var/www/icons/dir.png
var/www/icons/diskimg.png
var/www/icons/down.png
var/www/icons/dvi.png
var/www/icons/f.png
var/www/icons/folder.open.png
var/www/icons/folder.png
var/www/icons/folder.sec.png
var/www/icons/forward.png
var/www/icons/generic.png
var/www/icons/generic.red.png
var/www/icons/generic.sec.png
var/www/icons/hand.right.png
var/www/icons/hand.up.png
var/www/icons/icon.sheet.png
var/www/icons/image1.png
var/www/icons/image2.png
var/www/icons/image3.png
var/www/icons/index.png
var/www/icons/layout.png
var/www/icons/left.png
var/www/icons/link.png
var/www/icons/movie.png
var/www/icons/p.png
var/www/icons/patch.png
var/www/icons/pdf.png
var/www/icons/php.gif
var/www/icons/pie0.png
var/www/icons/pie1.png
var/www/icons/pie2.png
var/www/icons/pie3.png
var/www/icons/pie4.png
var/www/icons/pie5.png
var/www/icons/pie6.png
var/www/icons/pie7.png
var/www/icons/pie8.png
var/www/icons/portal.png
var/www/icons/poweredby.png -> ../../../usr/share/pixmaps/poweredby.png
var/www/icons/ps.png
var/www/icons/quill.png
var/www/icons/right.png
var/www/icons/screw1.png
var/www/icons/screw2.png
var/www/icons/script.png
var/www/icons/sound1.png
var/www/icons/sound2.png
var/www/icons/sphere1.png
var/www/icons/sphere2.png
var/www/icons/tar.png
var/www/icons/tex.png
var/www/icons/text.png
var/www/icons/transfer.png
var/www/icons/unknown.png
var/www/icons/up.png
var/www/icons/uu.png
var/www/icons/uuencoded.png
var/www/icons/world1.png
var/www/icons/world2.png
var/www/icons/small/
var/www/icons/small/back.png
var/www/icons/small/binary.png
var/www/icons/small/binhex.png
var/www/icons/small/blank.png
var/www/icons/small/broken.png
var/www/icons/small/burst.png
var/www/icons/small/comp1.png
var/www/icons/small/comp2.png
var/www/icons/small/compressed.png
var/www/icons/small/continued.png
var/www/icons/small/doc.png
var/www/icons/small/forward.png
var/www/icons/small/generic.png
var/www/icons/small/generic2.png
var/www/icons/small/generic3.png
var/www/icons/small/image.png
var/www/icons/small/image2.png
var/www/icons/small/index.png
var/www/icons/small/key.png
var/www/icons/small/movie.png
var/www/icons/small/patch.png
var/www/icons/small/ps.png
var/www/icons/small/rainbow.png
var/www/icons/small/sound.png
var/www/icons/small/sound2.png
var/www/icons/small/tar.png
var/www/icons/small/text.png
var/www/icons/small/transfer.png
var/www/icons/small/unknown.png
var/www/icons/small/uu.png
var/www/usage/
var/www/usage/ctry_usage_201212.png
var/www/usage/ctry_usage_201301.png
var/www/usage/ctry_usage_201302.png
var/www/usage/ctry_usage_201303.png
var/www/usage/ctry_usage_201304.png
var/www/usage/ctry_usage_201305.png
var/www/usage/ctry_usage_201306.png
var/www/usage/ctry_usage_201307.png
var/www/usage/ctry_usage_201308.png
var/www/usage/ctry_usage_201309.png
var/www/usage/ctry_usage_201310.png
var/www/usage/ctry_usage_201311.png
var/www/usage/ctry_usage_201312.png
var/www/usage/ctry_usage_201401.png
var/www/usage/ctry_usage_201402.png
var/www/usage/ctry_usage_201403.png
var/www/usage/ctry_usage_201404.png
var/www/usage/ctry_usage_201405.png
var/www/usage/ctry_usage_201406.png
var/www/usage/ctry_usage_201407.png
var/www/usage/ctry_usage_201408.png
var/www/usage/ctry_usage_201409.png
var/www/usage/ctry_usage_201410.png
var/www/usage/ctry_usage_201411.png
var/www/usage/ctry_usage_201412.png
var/www/usage/ctry_usage_201501.png
var/www/usage/ctry_usage_201502.png
var/www/usage/ctry_usage_201503.png
var/www/usage/ctry_usage_201504.png
var/www/usage/ctry_usage_201505.png
var/www/usage/ctry_usage_201506.png
var/www/usage/ctry_usage_201507.png
var/www/usage/ctry_usage_201508.png
var/www/usage/ctry_usage_201509.png
var/www/usage/ctry_usage_201510.png
var/www/usage/ctry_usage_201511.png
var/www/usage/ctry_usage_201512.png
var/www/usage/ctry_usage_201601.png
var/www/usage/ctry_usage_201602.png
var/www/usage/ctry_usage_201603.png
var/www/usage/ctry_usage_201604.png
var/www/usage/daily_usage_201212.png
var/www/usage/daily_usage_201301.png
var/www/usage/daily_usage_201302.png
var/www/usage/daily_usage_201303.png
var/www/usage/daily_usage_201304.png
var/www/usage/daily_usage_201305.png
var/www/usage/daily_usage_201306.png
var/www/usage/daily_usage_201307.png
var/www/usage/daily_usage_201308.png
var/www/usage/daily_usage_201309.png
var/www/usage/daily_usage_201310.png
var/www/usage/daily_usage_201311.png
var/www/usage/daily_usage_201312.png
var/www/usage/daily_usage_201401.png
var/www/usage/daily_usage_201402.png
var/www/usage/daily_usage_201403.png
var/www/usage/daily_usage_201404.png
var/www/usage/daily_usage_201405.png
var/www/usage/daily_usage_201406.png
var/www/usage/daily_usage_201407.png
var/www/usage/daily_usage_201408.png
var/www/usage/daily_usage_201409.png
var/www/usage/daily_usage_201410.png
var/www/usage/daily_usage_201411.png
var/www/usage/daily_usage_201412.png
var/www/usage/daily_usage_201501.png
var/www/usage/daily_usage_201502.png
var/www/usage/daily_usage_201503.png
var/www/usage/daily_usage_201504.png
var/www/usage/daily_usage_201505.png
var/www/usage/daily_usage_201506.png
var/www/usage/daily_usage_201507.png
var/www/usage/daily_usage_201508.png
var/www/usage/daily_usage_201509.png
var/www/usage/daily_usage_201510.png
var/www/usage/daily_usage_201511.png
var/www/usage/daily_usage_201512.png
var/www/usage/daily_usage_201601.png
var/www/usage/daily_usage_201602.png
var/www/usage/daily_usage_201603.png
var/www/usage/daily_usage_201604.png
var/www/usage/hourly_usage_201212.png
var/www/usage/hourly_usage_201301.png
var/www/usage/hourly_usage_201302.png
var/www/usage/hourly_usage_201303.png
var/www/usage/hourly_usage_201304.png
var/www/usage/hourly_usage_201305.png
var/www/usage/hourly_usage_201306.png
var/www/usage/hourly_usage_201307.png
var/www/usage/hourly_usage_201308.png
var/www/usage/hourly_usage_201309.png
var/www/usage/hourly_usage_201310.png
var/www/usage/hourly_usage_201311.png
var/www/usage/hourly_usage_201312.png
var/www/usage/hourly_usage_201401.png
var/www/usage/hourly_usage_201402.png
var/www/usage/hourly_usage_201403.png
var/www/usage/hourly_usage_201404.png
var/www/usage/hourly_usage_201405.png
var/www/usage/hourly_usage_201406.png
var/www/usage/hourly_usage_201407.png
var/www/usage/hourly_usage_201408.png
var/www/usage/hourly_usage_201409.png
var/www/usage/hourly_usage_201410.png
var/www/usage/hourly_usage_201411.png
var/www/usage/hourly_usage_201412.png
var/www/usage/hourly_usage_201501.png
var/www/usage/hourly_usage_201502.png
var/www/usage/hourly_usage_201503.png
var/www/usage/hourly_usage_201504.png
var/www/usage/hourly_usage_201505.png
var/www/usage/hourly_usage_201506.png
var/www/usage/hourly_usage_201507.png
var/www/usage/hourly_usage_201508.png
var/www/usage/hourly_usage_201509.png
var/www/usage/hourly_usage_201510.png
var/www/usage/hourly_usage_201511.png
var/www/usage/hourly_usage_201512.png
var/www/usage/hourly_usage_201601.png
var/www/usage/hourly_usage_201602.png
var/www/usage/hourly_usage_201603.png
var/www/usage/hourly_usage_201604.png
var/www/usage/index.html
var/www/usage/msfree.png
var/www/usage/usage.png
var/www/usage/usage_201212.html
var/www/usage/usage_201301.html
var/www/usage/usage_201302.html
var/www/usage/usage_201303.html
var/www/usage/usage_201304.html
var/www/usage/usage_201305.html
var/www/usage/usage_201306.html
var/www/usage/usage_201307.html
var/www/usage/usage_201308.html
var/www/usage/usage_201309.html
var/www/usage/usage_201310.html
var/www/usage/usage_201311.html
var/www/usage/usage_201312.html
var/www/usage/usage_201401.html
var/www/usage/usage_201402.html
var/www/usage/usage_201403.html
var/www/usage/usage_201404.html
var/www/usage/usage_201405.html
var/www/usage/usage_201406.html
var/www/usage/usage_201407.html
var/www/usage/usage_201408.html
var/www/usage/usage_201409.html
var/www/usage/usage_201410.html
var/www/usage/usage_201411.html
var/www/usage/usage_201412.html
var/www/usage/usage_201501.html
var/www/usage/usage_201502.html
var/www/usage/usage_201503.html
var/www/usage/usage_201504.html
var/www/usage/usage_201505.html
var/www/usage/usage_201506.html
var/www/usage/usage_201507.html
var/www/usage/usage_201508.html
var/www/usage/usage_201509.html
var/www/usage/usage_201510.html
var/www/usage/usage_201511.html
var/www/usage/usage_201512.html
var/www/usage/usage_201601.html
var/www/usage/usage_201602.html
var/www/usage/usage_201603.html
var/www/usage/usage_201604.html
var/www/usage/webalizer.png

sent 5058052 bytes  received 14609330576 bytes  7742722.45 bytes/sec
total size is 15140597351  speedup is 1.04

Now, reset your new VPS.

Note: you can use -c to decrease your banwidth.

Some issue after the migration:

Can’t login SSH

Starting a new SSH2 session. 22:54:25.277 
Connecting to SSH2 server xx.xx.32.101:22. 22:54:27.131 Connection failed. 
Connect() failed: Windows error 10061: No connection could be made because the target machine actively refused it.

ssh error

Reason: your exclude list isn’t included /etc/ssh/*
You must re-migrate.

Leave a Reply