How to Backup WordPress Site via SSH from Windows

Backup is an important task for any website administrator. This tutorial is going to show you how to backup WordPress site via SSH. We perform this backup from a Windows machine. On my previous tutorial, I have shown how to install WordPress on Debian 9 server. It’s a great way to deploy a WordPress site, but backup is another way that you must consider. In case of errors, hacker attack or any other causes, if we have regular backup, we can easily restore our website in a minute.

Actually there are easier ways to backup WordPress site, using backup Plugin. But the good WordPress backup plugin cost some money. Personally, I have never use one of them. I prefer to do manual backup for my websites. Its not that difficult. By manually backup my website, I can have more power and flexibility.

Most tasks on this tutorial is done using command line. But don’t worry, we have your back. It’s not that hard to backup via SSH. Following are the detailed information about my WordPress site. You can visit via: http://theplanetfootball.com

Our WordPress site details:

  • Installed on Debian 9 hosted in Linode
  • Database name: planetfootball
  • WordPress directory: /var/www/html/planetfootball (This is where our wordpress files and config)

What you will need

Steps to Backup WordPress Site via SSH from Windows machine

Step 1. Connect to the server

Download and install Putty and WinSCP, its free. First, we need to log in to our remote server. Open Putty and type the server IP address. It should looks like this

You will need to enter username and password to log in to your server. Next, we will mostly work using command line. Once login, you should see the following interface on Putty.

Ok now, we are ready to do some magic.

Step 2. Backup MySQL Database

This step will backup MySQL/MariaDB database. You will need root password for MySQL/MariaDB server. On this example, my database name is “planetfootball”. I will backup this entire database into single file. It’s easier to backup entire database rather than backup each tables. But, it’s all depends on you.

Command to backup MySQL Database

cd /tmp/backup
mysqldump -u root -p --databases planetfootball > planetfootball.sql

The command above will attempt to backup planetfootball database into planetfootball.sql file. This file will be saved under /tmp directory. Change the database name and backup name that match with yours.

Click the following image to see the command in action

At this point, we have successfully backed up our MySQL database. Proceed to the next step to backup the WordPress directory.

Step 3. Backup WordPress Installation directory

In my case, I installed WordPress inside /var/www/html/planetfootball directory. I will compress and then backup the WordPress directory.

cd /var/www/html
tar -cf planetfootball.tar.gz planetfootball

The command will backup the planetfootball directory and save it to planetfootball.tar.gz. We can then move this file to our backup directory for example /tmp/backup.

mv planetfootball.tar.gz /tmp/backup

Step 4. Download backup file

So now, we have two file inside /tmp/backup:

  • planetfootball.sql (MySQL dump file)
  • planetfootball.tar.gz (WordPress directory backup)

We can download these two files and save it locally. We can use WinSCP to copy these two files to our local computer. Open WinSCP and login to your remote server. Open the /tmp/backup directory where our backup files reside.

backup wordpress site via ssh

Simply drag and drop the files to local directory and you are done.

We have successfully backup WordPress site via SSH and stay tuned on this blog. In the next post, I will show you how to restore this backup to the server. Cheers.

Be the first to comment

Leave a Reply