Simple Drupal Remote Backup
Like many web types I have a number of small websites I look after, and I've never been happy with my backup solution. Until today.
My requirements are simple, create a backup of the database and files and save it on a local backup drive. The sites don't warrant anything fancy (like a cloud based solution that costs money). The procedure until now involved multiple, fussy steps. It turned out a single script solution is simple once a few key technologies are in place.
- SSH no-password/public-key access
Use your favourite search engine to search on the words: ssh public key authentication for a list of articles on setting up no-password, public-key ssh access. If you don't have public key ability, I suspect the script could be modified to use a password.
- Drush 4.5 on the host
If you have root access just follow the drush installation instructions. This article by Robin Monks provided the missing step for my shared-host sites: Installing Drush on a Shared DreamHost Account. The information in this article on setting up an alias, i.e. @site-name, is still valid in drush 4.5: New features in Drush 3
The Backup Script
The backup script uses the drush archive-dump command, available as of drush 4.5, to create a backup tarball that includes the database and files. The backup tarball is scp'ed to the backup drive and deleted from the host.
# Backup the Group 42 live site
drush @g42live archive-dump --destination=/home/site/backuptemp/$FILENAME
scp email@example.com:/home/site/backuptemp/$FILENAME /Volumes/Memory-Alpha/Backups/Group42/.
ssh firstname.lastname@example.org rm /home/site/backuptemp/$FILENAME
Four lines of script (plus comments) and whenever I need a site backup it's one done in one command!