Sunday, 06 January 2008
We all know that we should backup a drupal site before performing an upgrade. Drupal.org documentation even explains how to create a backup on http://drupal.org/upgrade/backing-your-site-command-line
I just finished a small bash script which automates this process with a simple usage. From
/var/www
we can now do
./backup.sh urlofwebsite mybackup
This will perform all the operations documented in the bookpage above, and clean up any left-over files afterwards. The result is that in
/var/www a new directory
www.krimson.be-backup
www.krimson.be and an extra file
backup.sql.tar.gz
which contains (could you guess?), a gzipped dump of its database.
I've copy pasted the script below. Note, if you do not provide a second argument, a timestamp will be used to 'tag' the backup.
The file is also attached. To use it, Right-click on the attachment, Select Save As, Browse to your
/var/www/
directory and save it as
backup.sh
Afterwards you will still need to do a
to make it executable.
I will try (read: bump me a few times) to commit the script , or pass it over to 'drumm'.
Good luck!
#!/bin/bash # A simple script to create a backup of a drupal site (including it's database) if [ -z "$1" ]; then exit 1 fi if [ ! -r "$1" ]; then exit 1 fi #TODO : figure out howto retrieve the version of drupal if [ -z "$2" ]; then else tag=$2 fi output=$1-$tag cd $1 wget -O drupalsqldump.sh "http://cvs.drupal.org/viewvc.py/drupal/contributions/sandbox/drumm/tools/drupalsqldump.sh?view=co" chmod +x drupalsqldump.sh #TODO .. use pipe to convert sqldump to tar.gz in single step ./drupalsqldump.sh sites/default/settings.php > backup.sql tar -pczf backup.sql.tar.gz backup.sql rm backup.sql rm drupalsqldump.sh cd .. cp -rf $1 $output rm $1/backup.sql.tar.gz






Post new comment