Skip to content

Instantly share code, notes, and snippets.

@ijin82
Last active June 14, 2017 12:06
Show Gist options
  • Save ijin82/480e630a5a576d9ec788a6e0ad4bf76f to your computer and use it in GitHub Desktop.
Save ijin82/480e630a5a576d9ec788a6e0ad4bf76f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Optional variables for a backup script
MYSQL_USER="root"
MYSQL_PASS="secret"
BACKUP_DIR=./$(date +%Y-%m-%d_%H%M%S);
test -d "$BACKUP_DIR" || mkdir -p "$BACKUP_DIR"
# Get the database list
for db in $(mysql -B -s -u $MYSQL_USER --password=$MYSQL_PASS -e 'show databases')
do
case "$db" in
performance_schema|mysql|information_schema)
# ignore some databases
echo "-> IGNORED DB: $db"
continue
;;
*)
# dump each database in a separate file
echo "processing: $db ..."
mysqldump -u $MYSQL_USER --password=$MYSQL_PASS "$db" | gzip > "$BACKUP_DIR/$db.sql.gz"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment