VP

How to Migrate An Existing VPS to a New VPS

Migrating servers can be a mess. I recently migrated my website from Vultr to Skysilk and the server migration process was lengthy. If you’re not sure where to start, this will show you the step by step process.

In this tutorial we will go through: 

  1. Migrating the SSH keys
  2. Configuring rsync
  3. Migrating the files
  4. Database Transfer
  5. Importing the Database

But first, make sure your new server is ready to go. Deploy an Ubuntu VPS on SkySilk if you haven’t yet!`

Prerequisites:

  • Deploy an Ubuntu Server on SkySilk
  • Install LAMP Stack on your new Server

About the authorVashishtha Kapoor is a Digital Marketing enthusiast and has over 5 years of experience in SEO, PPC, Website Management and WordPress development. Vashishtha writes about WordPress customizations, web design, technology trends, and ad-tech topics.

Migrating the SSH Keys

If you prefer using your root password to login to your server (on both the old and the new server) as opposed to using SSH keys, you can skip this part of the tutorial.

To migrate your existing VPS to a new VPS, first login to the old Server using any SSH client

ssh [email protected]

Then, create a keygen on your old VPS

ssh-keygen -t rsa -b 4096 -v

Now, copy the keys in your new server. open Skysilk, login with your root password and run the command below

ssh-copy-id new-server-public-IP

In the above command, replace the new-server-public-IP highlighted with your new VPS IPv4 address.

Configuring rsync

Rsync is one of the best ways to transfer files securely between servers. To use this, first, check if it’s already installed on your VPS. 

rsync --version

It should return the above response. If the above command returns “command not found”, install it with the following line. 

apt-get install rsync

Migrating Files from the Old Server to the new Server

My old site had the public files located in /var/ww/html/

To check where the files are located, navigate to your VPS host configuration file using the command below. You will land in the configuration file directory. Check the name of the file using the ls command

cd /etc/apache2/sites-enabled | ls -ltr

It will return the file name. Now, we need to edit this file that will have the root folder location on the server.

Edit the 000-default.conf file.

nano 000-default.conf

Get the root folder location, which should be in this file

import the database when you migrate an existing vps to new vps

Now we need to cd into the root directory where your files exist. 

cd /var/www/

With ls command, you can see all folders that exist in this location. In my case, there is a folder called “Site”

It’s time to use rsync to transfer the files. change the folder’s name you want to transfer to the new VPS and the IPv4 of your new server with the command below

rsync -avP html new-server-public-IP:/var/www/

In the above command, replace the new-server-public-IP highlighted with your new VPS IPv4 address.

If you already migrated the SSH keys, you won’t have to deal with authentication. However, in my case, the SSH keys do not exist. Therefore, it will prompt me to confirm the connection. 

Type yes and press ENTER

When asked, input the root password and press ENTER. The transfer process will start and complete in a few minutes. The success screen will look like this. 

Database Transfer

To transfer the database from your old server to a new server on Skysilk, you can use the database dump utility. 

Make sure you’re in the root directory with the pwd command. If not, use the command below to change directory to /root

Login to your MySQL Shell as root

mysql -u root -p

To see the list of databases hosted on the server, run the below command in the mysql shell.

show databases;

It will return a list of the databases that you have on your server. 

+—————————-+
| Database                   |
+—————————-+
| information_schema  |
| mysql                         |
| wordpress_db            |
+—————————-+

3 rows in set (0.00 sec)

You can ignore information_schema and mysql databases. The database you need to migrate is wordpress_db

At this stage, you got to know which database you should be dumping. Now exit the MySQL shell with the below command.

exit;

For the sake of keeping it easy, first dump the database with mysqldump command as follows:

mysqldump -u root -p wordpress_db > databasebackup.sql

You will be prompted to input the root user’s password to be able to dump the database.

Once the dumping process is complete, you should be able to see the file named databasebackup.sql in /root directory.

Compress this backup file to reduce its size to facilitate the data-transfer.

tar -cvzf databasebackup.tar.gz databasebackup.sql

Transfer the zipped backup file to your new server with rsync.

rsync -avP databasebackup.tar.gz new-server-public-IP:/root

Importing the Database on New Server

We’re half way through migrating your existing VPS to your new VPS. At this point, we have pushed the website files from the old server to the new server.

Login to your New server 

ssh [email protected]

Make sure that the files have successfully been transferred by checking both the locations on the new server with the commands below.

cd /var/www/html | ls -ltr
cd /root | ls -ltr

Go ahead and extract the zipped database file. 

tar -xvzf databasebackup.tar.gz

Now you can import the database backup file to a new MySQL Database. All you need to do is run the following command. 

mysql -u root -p < databasebackup.sql

The import process may take a while. Once completed, you will have a wordpress_db database on your new server. 

Verify that you’ve successfully imported the database, first log in to MySQL shell. 

mysql -u root -p

To see the list of databases hosted on the new server, run the below command in the mysql shell.

show databases;

It will return a list of the databases that you have on your server. 

+—————————-+
| Database                   |
+—————————-+
| information_schema  |
| mysql                         |
| wordpress_db            |
+—————————-+

3 rows in set (0.00 sec)

You should be able to see the wordpress_db database on the new server. 

Exit from the MySQL shell. 

exit;

Restart the Apache Server to reload and navigate to your website. 

sudo service mysql restart
sudo service apache2 restart

Once you restart the MySQL and Apache2 server, navigate your new server public IP in the browser and you will be able to visit the website that was hosted on the old server.

Conclusion

Migrating your existing VPS to a new VPS doesn’t have to be complicated. 

With the right tools, you can migrate your existing VPS quickly and efficiently. Skysilk has one-click templates available for quick installment.

Share this post with your friends

Share on facebook
Share on twitter
Share on linkedin