1. Home
  2. Cloud and Servers
  3. Virtual Servers (VPS)
  4. Restoring a website from backup on the virtual server

Restoring a website from backup on the virtual server

In the following part we will show you how to restore your website or application from backup, that is available on the virtual server. Common websites are stored to files and database. In this guide we will show you how to restore both the files and the database.

Server requirements

  • This guide is written for current OS Ubuntu LTS distributions (14.04, 16.04, 18.04)
  • You need to gain access on the server via SSH, with root (or sudo rights)
  • You need to have purchased a Server backups service

As the first step we check the available backups via WebAdmin. Backups are located outside of the server so they wouldn’t take up your disk space. They are connected via network to the so-called mounted directory /backups. Mount can be check with a command:

root@vps:~# mount | grep /backup
backup3.websupport.sk:/ssd_backups/vps-cust/abcdefgh-1234-5678-ijkl-mnoprstuvxyz/ on /backups type nfs

If the output does not contain any mount and the server backup service is purchased, please contact our support, as it may be an error.

Restoring data

For restoring data we will use the program rsync, that is very effective for copying data. In a case you don’t have it installed on your server, the installation is simple:

root@vps:~# apt-get install rsync -y

The data copying is initiated with a command bellow. We use the úrpgra, rsync, where you will set switches for archiving (faster data transfer -a), for more detailed copying process (verbose -v), and for replacing files with those from the backup (so we would restore all from the backup —delete).

root@vps:~# rsync -av --delete <source> <destination>

Source will be in our case the backup from which we restore the data, destination is the target directory where we restore the backup to. If we would restore everything it would be /data/web/domena.tld/web from the date of 20.10.2010, we would recommend to use the following command:

root@vps:~# rsync -av --delete /backups/.zfs/snapshot/2010-10-20-00:30:00/root/data/web/domena.tld/web /data/web/domena.tld/web

The date can be of course changed dynamically according to your need. The backups are available for last 14 days.

Restoring database

Complete website restoration is most often conditioned with the database restoration as well. This step should be completed from the same time as the data restoration. Additional backups of the databases can be located by listing the directory (e.g. for date 20.10.2010):

root@vps:~# ls -la /backups/.zfs/snapshot/2010-10-20-00:30:00/mysql
total 77
drwxr-xr-x 6 root root 6 Oct 20 18:45 .
drwxr-xr-x 4 root root 4 May 30 18:55 ..
drwxr-xr-x 2 root root 9 Oct 19 18:35 2010-10-19_18-35
drwxr-xr-x 2 root root 9 Oct 20 02:40 2010-10-20_02-40
drwxr-xr-x 2 root root 9 Oct 20 10:40 2010-10-20_10-40
drwxr-xr-x 2 root root 9 Oct 20 18:45 2010-10-20_18-45

As we want to restore the database the closest to the data restoration time, we will select the time 02:40 – therefore directory 2010-10-20_02-40.

root@vps:~# ls -la /backups/.zfs/snapshot/2010-10-20-00:30:00/mysql/2010-10-20_02-40
total 4439
drwxr-xr-x 2 root root       9 Oct 20 02:40 ./
drwxr-xr-x 6 root root       6 Oct 20 02:40 ../
-rw-r--r-- 1 root root   57386 Oct 20 02:40 databaza.sql.gz

Then we can restore the database from the dump. To run the command we need the database name, username and password. We would first recommend to copy the database backup to e.g. home directory:

root@vps:~# cp /backups/.zfs/snapshot/2010-10-20-00:30:00/mysql/2010-10-20_02-40/databaza.sql.gz ~/databaza.sql.gz

After that we decompress the database with the command gunzip, which will lead to creating a file database.sql:

root@vps:~# gunzip ~/databaza.sql.gz

In the last step we import the database and replace the current database (it is necessary to change the user_name for a nem of the database user, user_pass with a password and db_name for database name):

mysql -uuser_name -puser_pass -h localhost db_name < ~/databaza.sql

For example the command with simple name (databaza), user (databaza) and password (heslo123):

mysql -udatabaza -pheslo123 -h localhost databaza < ~/databaza.sql

Also read how to access your backups on virtual server ( pristupovať ku vašim zálohám na virtuálnom serveri. )

Updated on June 16, 2021

Was this article helpful?

Related Articles