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:
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:
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:
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:
After login, uncompress the WordPress database backup file with the following command:
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.
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.