SnapShooter Learning Center

You can't trust bash scripts

Backup Scripts can fail silently for months. SnapShooter is easy to use and provides you instance notifications on success or failure Learn More >

How to Backup and Restore WordPress Website Manually

Learn how to keep your Wordpress Website save and secure

Simon Bennett]
Simon Bennett
Last Updated: May 24, 2021
Table of Contents

Regularly backing up and restoring WordPress is an essential part of any WordPress administrator. It will help if terrible things happen and data gets lost. The backup and restore process is very difficult for any beginner if you host your WordPress site on VPS without any control panel. Before knowing how to perform WordPress backup manually, you need to understand how backup works and what it contains. WordPress backup contains databases and files. Files contain themes, plugins, media and other uploaded files while the database contains all posts, content and comments.

In this post, we will show you how to backup and restore a WordPress website manually.


# How to Backup WordPress with SnapShooter


# How to Backup WordPress Website

If your WordPress website is hosted on the VPS or Dedicated server where cPanel or other control panel is not installed then you can backup and restore your WordPress website with command-line.

In this section, we will show you how to backup WordPress database and files.

First, you will need to log into your server using SSH. You can do that by entering this command:

ssh root@vps-ip-address

After login, connect your MySQL console with the following command:

mysql -u root -p

Provide your MySQL root password when prompt then run the following command to list all databases in your server.

mysql> show databases;

You should see the following output:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| wpdb        |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

Now, exit from the MySQL with the following command:

mysql> exit;

As you can see, wpdb is your WordPress database. So we will need to take a backup of this database.

You can run the following command to backup wpdb database and compress it in gzip format:

mysqldump -u root -p wpdb | gzip > wpbackup.sql.gz

This command will create a compressed copy of your database.

Next, you will need to take a backup of all WordPress files and directories

First, change the directory to the WordPress document root directory with the following command:

cd /var/www/html/

Next, run the following command to create a compressed copy of your WordPress sites:

tar -cpvzf /root/wordpress.tar.gz wordpress

This command will create a compress copy of backup file named wordpress.tar.gz at /root directory.

At this point, you have the WordPress database and files are ready.


# How to Restore WordPress Website

First, you will need to copy both wordpress.tar.gz and wpbackup.sql.gz to the remote server where you want to restore a backup.

You can copy them using the SCP command as shown below:

scp wordpress.tar.gz wpbackup.sql.gz root@remote-server-ip:/root/

This will copy both backup files inside the /root directory of the remote server.

Next, log in to the other server where you want to restore the WordPress site:

ssh root@remote-server-ip

After login, uncompress the WordPress database backup file with the following command:

gunzip wpbackup.sql.gz

Next, restore the database using the mysqldump command as shown below:

mysqldump -u root -p wpdb < wpbackup.sql

You will be asked to provide your MySQL root password to restore the backup.

Next, restore the WordPress files using the following command:

tar -xvzf wordpress.tar.gz -C /var/www/html/

The above command will extract the WordPress files from the wordpress.tar.gz backup file to the Apache web root directory.


# Conclusion

WordPress backup and restore process is a very useful and fundamental process that you should know. There are a lot of WordPress plugins available to backup and restore WordPress sites. However, A manual backup is very useful when you can't access your phpMyAdmin or WordPress dashboard.


Did you find this article helpful?