1. Home
  2. CMS
  3. WordPress
  4. How to backup a WordPress site on your VPS

How to backup a WordPress site on your VPS

How to backup a WordPress site on your VPS
How to backup a WordPress site on your VPS

In this guide we are going to teach you how to manually backup your WordPress site on your VPS. We highly recommend that you have regular backups of your WordPress site so that you may easily restore it if something unusual happens. For example, if your site is broken because of a faulty plugin then it can get infected with malicious files or you might delete contents of the database accidentally, or various others. In order to make a complete backup of your WordPress site, you have to create a backup of your WordPress files and your WordPress database.
WordPress Files
For starters, you have to create a backup that includes all of your WordPress site files.
In order for this to be done, you have to log into your VPS via SSH.
After you have logged in, you must navigate to your WordPress root directory. Depending on your server’s configuration this might be at another location, for example, ‘/var/www/html/wordpress/‘.
Your WordPress site has the following files:

  • the WordPress core installation files which are stored in the wp-admin directory.
  • the WordPress Themes and Plugins which are stored in the wp-content directory.
  • libraries and third-party components which are stored in the wp-includes directory.
  • Images and Files
  • JavaScript and PHP scripts
  • Additional files and static web page

When combined, all of those files will generate your WordPress site so it is best to backup all of those files and directories.
It is generally enough to simply copy your ‘wp-content’ directory, as the contents of ‘wp-admin’ and ‘wp-includes’ are normally never edited and you may always get them from the original WordPress installer.
However, for you to have a full working copy of the site, it is a great idea to create a backup of all the WordPress files together.
In the case that your WordPress root directory is located in ‘/var/ww/html/wordpress/‘ you can do this with the command below.

tar -cpzf wp-backup.tar.gz /var/www/html/wordpress/

This should make an archive file of every WordPress file which generates your website.
WordPress Database
Your WordPress files by themselves are not enough if you would like a complete backup of the site. Every piece of information on the site, including your posts, comments, site configurations, user accounts, and so on are located in your database.
In order to create a backup of the WordPress database, we will need to execute the command below:

mysqldump -u wp_user -p wp_database > wp_database_backup.sql

‘wp_user’ is going to be the name of the user of your WordPress database and ‘wp_database’ is the name of your database. If you are not sure of the user, database name, and password for your website then you may find that information in the ‘wp-config.php’ file which is located in your WordPress folder.
With this, you will have everything you require to successfully restore your WordPress site.
Once you have successfully made a backup of both your WordPress files and database, you can transfer them to your local computer via FTP; you can also do this the other way around when you need to restore your website.

Updated on December 23, 2018

Was this article helpful?

Related Articles

Leave a Comment

[apsl-login-lite login_text='Please login with a social account']