Skip to content

Instantly share code, notes, and snippets.

@dtseiler
Created November 20, 2010 05:39
Show Gist options
  • Select an option

  • Save dtseiler/707648 to your computer and use it in GitHub Desktop.

Select an option

Save dtseiler/707648 to your computer and use it in GitHub Desktop.
#!/bin/bash
DATESTAMP=`date +%Y%m%d`
SITESFILE=${HOME}/.drupalsites
# SITESFILE contents are in the following format:
# SITENAME:DBNAME:DBUSER:DBPASSWD
DRUPALDIR=/path/to/drupal
BACKUPDIR=${HOME}/backups/${DATESTAMP}
mkdir -p ${BACKUPDIR}
# Backup the drupal codebase
echo -n "Backing up ${DRUPALDIR} ... "
cd ${DRUPALDIR}/../
tar -cjpf ${BACKUPDIR}/drupal_${DATESTAMP}.tar.bz2 drupal
echo "Done."
cd ${BACKUPDIR}
# Backup MySQL Databases
cat $SITESFILE | while read line; do
#echo $line
line=(${line//:/ })
echo -n "Backing up MySQL db ${line[1]} ... "
DUMPFILE=${line[0]}_${DATESTAMP}.sql
mysqldump -u ${line[2]} -p${line[3]} ${line[1]} > ${DUMPFILE}
gzip ${DUMPFILE}
echo "Done."
done
echo "Backup completed, all files are in ${BACKUPDIR}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment