Skip to content

Instantly share code, notes, and snippets.

@shamiao
Created January 26, 2015 04:31
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 shamiao/39c373ce5d2b4e107d8b to your computer and use it in GitHub Desktop.
Save shamiao/39c373ce5d2b4e107d8b to your computer and use it in GitHub Desktop.
l4homestead-dbbackup v0.0.1
#! /bin/bash
# l4homestead-dbbackup
# v0.0.1
#
# 2014 - 2015 (C) SHA Miao
#
# Published under MIT License. See LICENSE file for details.
#
MYSQL_USERNAME=homestead
MYSQL_PASSWORD=secret
MYSQL_DATABASES=$(
mysql --user=$MYSQL_USERNAME --password=$MYSQL_PASSWORD \
--batch -e "show databases;" | \
tail -n +2 | \
awk '!/^(information_schema|performance_schema|mysql)$/'
)
while read -r MYSQL_DATABASE; do
mysqldump --user=$MYSQL_USERNAME --password=$MYSQL_PASSWORD \
--skip-comments --skip-opt --databases $MYSQL_DATABASE > $MYSQL_DATABASE.sql
git add $MYSQL_DATABASE.sql
done <<< "$MYSQL_DATABASES"
git config --global user.email "dbadmin@example.com"
git config --global user.name "Database Dumper"
GIT_MSG_DATE=`date --rfc-3339=second`
git commit -m "$GIT_MSG_DATE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment