How To Do An Automated Remote Backup Of Your WordPress Blog

hacker   How To Do An Automated Remote Backup Of Your Wordpress BlogThis 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.

backup1a   How To Do An Automated Remote Backup Of Your Wordpress Blog

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.

backup2   How To Do An Automated Remote Backup Of Your 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.

backup9   How To Do An Automated Remote Backup Of Your 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.

backup10   How To Do An Automated Remote Backup Of Your 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.

backup41   How To Do An Automated Remote Backup Of Your Wordpress Blog

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\
exit

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).

backup8   How To Do An Automated Remote Backup Of Your Wordpress Blog

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.

backup6   How To Do An Automated Remote Backup Of Your Wordpress Blog

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

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

8 Comments -

Weapon Blog

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

Ankur

Very useful for blog owners. would surely try this 

James Bruce

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

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.

Justin Scott

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

Peter

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

Ryan Dube

Cool idea Peter – that’s true, that should work as well.

Anonymous

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