Skip to content

Instantly share code, notes, and snippets.

Created December 28, 2012 15:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4398903 to your computer and use it in GitHub Desktop.
Save anonymous/4398903 to your computer and use it in GitHub Desktop.
Backup a Drupal site's database using drush, minus disposable data.
#!/bin/bash
# Check for the existance of drush on the system
if [[ ! -x /bin/drush || ! -x /usr/bin/drush ]]; then
echo "This script requires drush!"
echo
exit 3
fi
if [[ -z ${1} ]]; then
echo "Must specify destination directory for backup tarball"
echo
echo "Directory can be a complete path, or a relative path"
echo "Ex: backup-site ~/backupdir"
echo
echo "Enjoy!"
echo
echo
exit 2
fi
# Setup the backup prefix
BACKUP_PREFIX=${1}/$(hostname)
# get the date
DATE=`date +%Y%m%d`
# Dump the Drupal DB structure only
echo "Dumping database and compressing . . ."
drush sql-dump | grep -Ev "^INSERT.*(cache_.*|flood|search_.*|semaphore|sessions).*$" | bzip2 > ${BACKUP_PREFIX}-${DATE}.sql.bz2
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment