Wordpress & Web Development

How to Do an Automated Remote Backup of Your WordPress Blog

Ryan Dube 05-10-2011

This weekend, my website got hacked for the first time ever. I figured it was an event that was bound to happen eventually, but I still felt a bit shocked and more than a little surprised that someone would bother to do such a thing. I was lucky that I had a backup of my website which I had made about a month earlier, and since index.php never really changes unless I make a site design change, I was able to replace the defaced file with my original one, and no harm was done.


Still, it made me realize just how dangerous it is to make such infrequent backups. It also made me realize the extent of the damage that could have occurred if the database itself had got hacked – I could have lost over a month’s worth of blog posts.

Protecting Yourself With Automated WordPress Site Backups

The problem is I just don’t have time to go in every day, week, or even month, and back up my blog. I’m sure most of you reading this feel the same way. There really isn’t a nicely streamlined, automated solution that allows you to schedule a full backup of your files and database, and get the exported backup somewhere off the web server. Aibek listed some online tools that may help, but in those cases you are dependent on some outside service or website to make it all work.

Configuring Automatic Backups

I decided to spend half of my Sunday putting together a solution. The following setup makes use of two scheduling WordPress plugins, WordPress Backup and DB Manager.  The first backs up your files, and the second backs up your database – both on a schedule. In the last part of the article, I’ll show you how to automate the FTP transfer of those files onto a remote server or PC.

wordpress site backup

Your first step is to install the WordPress Backup plugin, taking careful note of the installation instructions and implementing the .htaccess file where required. Then go to the configuration area for it. Here is where you can tell the plugin how often to do a backup of your wordpress uploaded images, theme files and plugins.


backup wordpress blog

Make note of the backup directory, you’re going to need this later. The three files stored there will be plugins.zip, uploads.zip and themes.zip.

Next, install the DB Manager plugin. You could also use something like the database plugin Dean described. Pay attent to the .htaccess configuration instructions. Don’t skip the instructions or the backup won’t work properly. Go to the Database Options in your WordPress menu and make a note of the backup path.

backup wordpress blog


There will be multiple files up to the backup archive you define. To FTP these files we’ll have to use wildcards (I’ll show you how).

Set up your database backup on a schedule by changing the Automatic Scheduling settings.

backup wordpress blog

Now that your WordPress files and database will be backed up locally to a location on your web server, it’s time to schedule an FTP job to get those files off the server and onto your local PC.


Scheduling An FTP Transfer

A scheduled FTP transfer is not easy to come by. Most FTP clients that can do it want you to pay for their premium product to do so. To get around this, you need FTP scripting commands that you can schedule, and that’s exactly what WinSCP allows you to do.

Download and run the interactive WinSCP app. Once you’ve established an FTP connection, click on “Session” and save the session.

how to backup wordpress

Once you’ve saved the session details, you can close the application and then open up a text file. Call it anything you like, but remember the name. You will want to type something similar to the following (replace the paths with the paths above that you’ve noted as you set up each plugin).


I created a folder on my local server under D:\backup\TSW_Files where I want to FTP all of those files. Under D:\backup\, I placed the following script file called myfile.txt:

option batch on
option confirm off
open topsecretwriters
get public_html/wp-content/xxxxx/themes.zip d:\backup\TSW_Files\
get public_html/wp-content/xxxxx/uploads.zip d:\backup\TSW_Files\
get public_html/wp-content/xxxxx/plugins.zip d:\backup\TSW_Files\
get public_html/wp-content/xxxxxxx-db/*topsec6_topwp.sql.gz d:\backup\TSW_Files\

The first path in the “get” command is your remote web server path, and the second path is your local backup PC/server path. Next, create a text batch job called backupWP.bat and store it in the c:\program files\WinSCP\ folder. That text file should have the following lines:

@echo off
winscp.com /script=d:\backup\myfile.txt

The myfile.txt script can really be stored anywhere, so long as you keep the path listed in the batch job accurate.

Now, whenever the batch job launches, it will call WinSCP.com, which will in turn run the FTP script commands you defined in your txt file. All you have to do now is schedule backupWP.bat to run using Windows Scheduler (All Programs -> Accessories -> System Tools -> Windows Scheduler).

how to backup wordpress

Now, you’ve basically set up a system where your WordPress block takes regular backups of important WordPress files and the WordPress database to folders on your web server, and you can FTP those backed-up files off your server to a remote location using your daily FTP script.

wordpress site backup

So, there you have it. Once you’ve set up the system above, you never have to give backing up your blog another thought. Automating the entire process will free you up to do more important things, like writing your first novel, or playing with your kids. Pretty cool, isn’t it?

Try the setup above with your own blog and let us know if you were able to make any improvements in the setup, or if you know of any plugins that work as well as these two for a WordPress site backup. Share your thoughts in the comments section below.

Image Credit: Gualtiero Boffi

Related topics: Data Backup, Wordpress, Wordpress Plugins.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Anonymous
    December 2, 2011 at 4:09 pm

    THANK YOU x infinity, this is a ridiculously useful tip. 

  2. Peter
    October 12, 2011 at 10:11 pm

    You could also use wget on your client and schedule a task to pull the archived files from the server.

    • Ryan Dube
      October 16, 2011 at 2:25 pm

      Cool idea Peter - that's true, that should work as well.

  3. Justin Scott
    October 7, 2011 at 2:25 am

    Not a bad guide but I think my method is faster, easier and safer. http://itsjustjustin.com/?p=4803 Just some food for thought.

  4. James Bruce
    October 6, 2011 at 8:38 am

    Great article Ryan, I hadn't thought of scheduling FTP, but's quite ingenious really. Sorry to hear to got hacked - did you ever find out how they got in? Timthumb vulnerability? 

    For Mac readers - It sounds like a similar FTP automation can be set up on Mac with Transmit (http://www.theosquest.com/2007/06/16/scheduling-website-backups-with-transmit/) using automator and iCal alarm trigger.

    • Ryan Dube
      October 6, 2011 at 11:58 pm

      Hey James - no idea. All I heard from the web host was that the hacker got in via a "security vulnerability" and that it was the host's fault in combination with one particular account (not mine, thank god). Thanks for adding the bit for Mac users - I always hope there's a good alternative for Mac users so appreciate that addition.

  5. Ankur
    October 6, 2011 at 4:54 am

    Very useful for blog owners. would surely try this 

  6. Weapon Blog
    October 6, 2011 at 1:33 am

    Wow, that sounds great.  I'll definitely be giving this a try.