Skip to content

Instantly share code, notes, and snippets.

@krabello
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krabello/f48d7c647c66ea685be6 to your computer and use it in GitHub Desktop.
Save krabello/f48d7c647c66ea685be6 to your computer and use it in GitHub Desktop.
Dump all MySQL databases into individual archived files
#! /bin/bash
TIMESTAMP=$(date +"%F")
BACKUP_DIR="/tmp/$TIMESTAMP/mysqldump"
MYSQL_USER="*********"
MYSQL=/usr/bin/mysql
MYSQL_PASSWORD="*********"
MYSQLDUMP=/usr/bin/mysqldump
mkdir -p $BACKUP_DIR
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema)"`
for db in $databases; do
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/$db.gz"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment