In this tutorial, we will go through all the necessary steps required in order to manually backup your WordPress site on your server. Making regular backups of your WordPress sites is highly recommended, so you can easily restore them if something unexpected happens, for example, if your site stops working because of a faulty plugin, it gets infected with malicious files, you accidentally delete the contents of your database and so on. To fully backup your WordPress site, we will split this tutorial in two parts, making a backup of your WordPress files and making a backup of your WordPress database.
Making a backup of your WordPress files
We will start with creating a backup of all of your WordPress site files.
To do so, you will first need to log in to your server via SSH.
Once logged in, you will need to navigate to your WordPress root directory. Depending on your server configuration this can be at a different location, for example, /var/www/html/wordpress/.
Your WordPress site consists of the following:
- the WordPress core installation files (stored in the wp-admin directory).
- the WordPress Themes and Plugins (stored in the wp-content directory).
- libraries and third-party components (stored in the wp-includes directory).
- Images and Files
- Additional files and static web pages
It is usually enough to only backup your wp-content directory, as the contents of wp-admin and wp-includes are usually never modified, and you can always retrieve them from the original WordPress installer.
In order to have a full working copy of your site, it would be a good idea to make a backup of all the WordPress files together.
Let say your WordPress root directory is located in /var/www/html/wordpress/. You can then execute the following command:
tar -cpzf wordpress-backup.tar.gz /var/www/html/wordpress/
This will create an archive file which contains all the WordPress files that generate your website.
Making a backup of your WordPress database
Now that you have a backup of all the WordPress files, we can move to the next step.
Your WordPress files alone are not enough if you want a complete backup of your website. All the information of your website, including your posts, comments, site configurations, user accounts and so on, is stored in your database.
You can make a full backup of your WordPress database with the mysqldump command:
mysqldump -u wp_user -p wp_database > wp_database_backup.sql
where “wp_user” is the name of the user of your WordPress database, and “wp_database” is the name of your database.
If you are not sure about the information of the database that is currently connected to your WordPress site, you can check the wp-config.php file inside your WordPress root directory and look for the following lines:
define('DB_NAME', 'your-database-name'); define('DB_USER', 'your-database-user'); define('DB_PASSWORD', 'your-database-password')
You can also create a copy of your database through phpMyAdmin or any control panel, like cPanel or DirectAdmin, if you have one installed on your server.
With this, you now have everything you need to successfully restore your WordPress site.
After you have successfully made a backup of both your WordPress files and database you can easily transfer them to your local computer via FTP or the other way around when you need to restore your website.
PS. If you liked this post, on how to backup your WordPress site, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.