Skip to content

Instantly share code, notes, and snippets.

@ryanschwartz
Created June 22, 2009 18:59
Show Gist options
  • Save ryanschwartz/134124 to your computer and use it in GitHub Desktop.
Save ryanschwartz/134124 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
###########################################################
# Back up MySQL databases
###########################################################
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
BACKUP_DIR="."
# Do not backup these databases
IGNORE="test"
# Get list of all databases
DB_LIST=`mysql -Bse 'show databases'`
for db in $DB_LIST; do
# set skip variable
skip=0
if [ "$IGNORE" != "" ]; then
for i in $IGNORE; do
[ "$db" == "$i" ] && skip=1 || :
done
fi
if [ "$skip" == "0" ]; then
mysqldump $db | gzip -9 > $BACKUP_DIR/$db.sql.gz
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment