Simple CMS Backup using Bash Script

This is a simple bash script for getting a full backup most any mysql-backed CMS (WordPress, ExpressionEngine, etc.).

If you want to just see the code, as you may be able to re-purpose/use some of it, check it out on github: https://github.com/iainlbc/simple-cms-backup

What it does

  • Gets mysqldump of database
  • Gets copy of filesystem directory (ie: /var/www/public_html/wordpress)
  • Compresses both into a archive named today’s date (ie: 2012-24-1.tar.gz)
  • Sends the backup archive offsite via FTP (you’ll need an ftp server somewhere to send your backup too)
  • Sends a notification email upon competition with details of Success/Failure

What it doesn’t do

  • Remove old backup’s based on retention logic (this is next on the list)
  • Back up multiple sites
  • Scheduling of the backup itself (Just create a symlink of the script to /etc/cron.daily)
  • Incremental/Differential Backups
  • Allow for storage of backups on S3, Cloudfiles, External Harddrive, etc.

Alternatives

Sure I am using this in production, but that doesn’t mean I recommend it for you. Before you install this rudimentary backup script, perhaps you should explore some more robust, well maintained/tested solutions:

  • Backup: A RubyGem written for Linux and Mac OSX.  Backup has built-in support for various databases, storage protocols/services, syncers, compressors, encryptors and notifiers which you can mix and match. It was built with modularity, extensibility and simplicity in mind.
  • VaultPress: Commercial Paid Solution, at time of writing $15/month, by far the best backup solution for a WP site, developed by the same guys who wrote/maintain the WordPress codebase.
  • HollandBackup: Holland is an Open Source backup framework originally developed at Rackspace and written in Python.
  • WordPress-S3-Backup: Ruby Rake script to backup your WordPress blog database and site to Amazon S3

Installation

Two methods of installation are available, using GIT or extracting an Archive. The archive will be kept up to-date within reason, use GIT if you want you want the absolute latest and greatest. Install onto the server where your CMS/web-app lives, that wish you back up.

GIT

cd /opt/
git clone git@github.com:iainlbc/simple-cms-backup.git

From Archive

cd ~
wget iainlbc.com/simple-cms-backup/latest.tar.gz
tar -xzvf latest.tar.gz /opt/simple-cms-backup/

Configuration

You need to update the values in the Configuration File (the directory/mysql database name, etc.)

nano /opt/simple-cms-backup/scripts/config.cfg

Usage

After you’ve inserted your values into config.cfg, you can run a backup manually:

/opt/simple-cms-backup/scripts/./backup.sh

Scheduling

This script assumes you will schedule the script to run using Cron or some other mechanism. No functionality for scheduling exists within the script itself. Here is how I scheduled the script to run every day, on CentOS (may vary for your distribution):

ln -s /opt/simple-cms-backup/scripts/backup.sh /etc/cron.daily/backup.sh