Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
DB Backup to Git
# MySQL DB dump to Git commit
# Dumps the specified mysql database to the given location and commits it and
# the previous database to the Git repository.
# It is assumed you have already setup the Git respository to only be the
# a checkout of the database backup location
# To do that (in the repository):
# $ git config core.sparsecheckout true
# $ echo sql-backup/ > .git/info/sparse-checkout
# $ git read-tree -m -u HEAD
# Author: Aaron Gustafson, Easy-Designs LLC
# Copyright: Copyright (c) 2011 Easy-Designs LLC
# Since: Version 0.1
# path to Git repository
# database settings
DB_NAME="You DB Name Here"
DB_USER="Your DB Username Here"
DB_PASS="Your DB Password Here"
# svn up the content
git pull --quiet
# dump the database using the mysql administrator - so we can see all dbs
mysqldump -u$DB_USER -p$DB_PASS --opt --routines --skip-extended-insert --compact --force "${DB_NAME}" > "${FILENAME}"
# add everything we have - will throw a warning the dbname.sql already is added but its fine
git add .
# commit
git commit --quiet -m "SQL Database Dump"
# push
git push --quiet origin $REPO_BRANCH

This comment has been minimized.

Copy link
Owner Author

@aarongustafson aarongustafson commented Aug 20, 2011

Extended inserts increase the change size, so killing them should keep your repository smaller.


This comment has been minimized.

Copy link

@sambauers sambauers commented Jan 17, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment