Using rsnapshot through ftp, backing up WordPress

Share on Twitter
Share on TumblrSave on DeliciousShare via email

I love rsnapshot for managing backups, and I showed before how to set it up.

Recently, I helped set up a WordPress-based website for my local tango community. As an integral part of that, I wanted to back it up and keep the advantage of the incremental backup, if possible.

Backing up a WordPress site is a problem with two parts:

  1. backing up the MySQL database
  2. backing up the files (code and media uploads)

Backing up the database

The backing up of the MySQL database can be handled in two different ways:

  1. use mysqldump within rsnapshot to dump the database; this requires having ssh access to the server or minimally being able to schedule cron jobs. This was not the case with this server, so I had to look further.
  2. use a plugin to handle this. I tried several of them, and I finally settled for WP-DB-Backup, which is the simplest of them all. It says in the description that it works until WP 3.1.4, but it worked well for me under 3.3.1; just changed a line or two to remove a warning in the admin interface.

Backing up the files

This is the trickier part, especially when using a cheap server that does not give ssh access or the ability to schedule cron jobs. My solution was to add an entry to my /etc/rsnapshot.conf on one of my VPSs to backup the content of the server through FTP. The issue here is that rsync, of which rsnapshot is a mere wrapper, does not work through ftp; this is where wget comes to help.

wget is a very powerful little piece of software, readily available on Linux systems, that I usually used to download a file from a web server without having to fire up the browser. However, it offers much more than that, including user authentication and some rsync-like functions, like mirroring, excluding files/directories, etc.

I added the following line to my /etc/rsnapshot.conf:

# TipoTango site
backup_script   /usr/bin/wget --user=ftpusername --password=ftppassword --mirror ftp://ftpserveraddress/public_html --exclude-directories=Maildir,imap,backups -nH -P /var/cache/rsnapshot/.sync/tipotango   unused0

A couple of notes on this command:

  • ftpusername, ftppassword and ftpserveraddress need to be replaced by their actual values
  • the --exclude option contains a comma-separated-list of folder names to avoid
  • I’m using the sync_first option, so each sync is always under the $RSNAPSHOT_ROOT/.sync directory
  • the options -nH and -P instruct wget to not keep the ftpservername in the directory structure of the mirrored copy

The first backup took some time, as wget needs to crawl the whole contents of the server; for subsequent backups, it checks the contents of an index file on each directory and only copies modified files, so it’s much faster taking up just a few seconds.