by Scott Schecter

Free Off-site WordPress Backup With Cron And Git


What is your WordPress backup strategy? Having an off-site backup of any web application is absolutely critical. This protects you not only against hardware failures, but also against software errors. This includes errors introduced in the source upstream, security events, and even those caused by you.

This is especially true for sites whose content changes very frequently such as WordPress based sites. We use WordPress to run our blogs here at Schecter & Co. and historically we have used a plugin called BackWPup to perform our off-site WordPress backup nightly. However, recently this plugin became unusable so it was clear to me it was time to find a better solution. Instead of relying on another 3rd party plugin or paying for an additional service to perform these backups I decided to create my own simple off-site WordPress backup solution.

The solution I created is a small shell script that is run from a cron job nightly at midnight. It copies all of the needed files to restore the site to a local git repository on the server. It then pushes these files to a remote git repository for safe keeping. Below is an oversimplified version of the shell script to illustrate the general idea.

The shell script:

The cron job:

Using the above you can easily automate an off-site WordPress backup of your site for safekeeping. You will also know the site is being successfully backed up nightly since you receive an email report of the cron job output assuming you have your server configured correctly. You also get revision history for your site by using this approach which is an added bonus. At Schecter & Co. we intentionally use a very minimal amount of plugins on our WordPress based sites to increase stability and reduce security issues. This has enabled us to remove one more plugin and we are quite pleased with the outcome.


Leave a Comment

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