Skip to content

Instantly share code, notes, and snippets.

@kimmellj
Created June 27, 2013 14:18
Show Gist options
  • Save kimmellj/5876791 to your computer and use it in GitHub Desktop.
Save kimmellj/5876791 to your computer and use it in GitHub Desktop.
#!/bin/bash
# sonia 16-nov-05
# backup each mysql db into a different file, rather than one big file
# as with --all-databases - will make restores easier
OUTPUTDIR="/root/db_backups-2013-06-27"
MYSQLDUMP="/usr/bin/mysqldump"
MYSQL="/usr/bin/mysql"
# clean up any old backups - save space
rm "$OUTPUTDIR/*bak" > /dev/null 2>&1
# get a list of databases
databases=`$MYSQL \
-e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
# dump each database in turn
for db in $databases; do
echo $db
$MYSQLDUMP --routines \
--databases $db > "$OUTPUTDIR/$db.bak"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment