A simple bash script to back up your Drupal sites
This script will do a database backup, zip it up with the contents of your root web directory, and then ftp the zip to a remote backup server. Just personalize it, drop it in your root web directory, and configure cron to run it nightly.
*Disclaimer: You get what you paid for, and you paid £0. Use at own risk! ;)
#!/bin/bash
HOMEDIR=***/html/
NOWDATE=`date +%C%y%m%d_%H%M`
SQLBACKUPFILE=***DB-$NOWDATE.sql
SQL_USER=***user
SQL_PASS=***password
SQL_DBNAME=***database name
FULLBACKUPZIP=***site-backup-$NOWDATE.zip
WEBDIR=***/var/www/html
HOST=***ftp host
USER=***ftp user
PASS=***ftp password
TGTDIR=***target directory
## the .netrc resides in the user's home directory, so CD there first
## This is also where we're going to store the temporary SQL and ZIP files
echo "Changing to $HOMEDIR"
cd $HOMEDIR
## Backup the database
echo "Dumping database $SQL_DBNAME..."
mysqldump -u$SQL_USER -p$SQL_PASS --opt $SQL_DBNAME --lock-tables=false >$SQLBACKUPFILE
echo "Database dump complete."
## ZIP contents of web directory, including database backup
echo "Zipping SQL script and $WEBDIR..."
zip -yr9 $FULLBACKUPZIP $SQLBACKUPFILE $WEBDIR 1>/dev/null 2>/dev/null
echo "Zip completed."
rm -f $SQLBACKUPFILE
## FTP ZIP file to target
echo "Uploading ZIP file $FULLBACKUPZIP..."
echo "\$ upload1 $FULLBACKUPZIP" | ftp $HOST
echo "Upload complete."
rm -f $FULLBACKUPZIP