Skip to content

Instantly share code, notes, and snippets.

@michabbb
Created January 5, 2018 18:52
Show Gist options
  • Save michabbb/0d60e56fad4c5b6531b2595924eb6030 to your computer and use it in GitHub Desktop.
Save michabbb/0d60e56fad4c5b6531b2595924eb6030 to your computer and use it in GitHub Desktop.
Backup MySQL Schema to individual files and push changes to git
#!/bin/bash
NOW=`date +%Y%m%d%H%M%S`
GIT_MYSQL=/home/backup/mysql-schema
for T in `mysql -u root -N -B -e 'show tables from xxxxxx'`;
do
echo "Backing up $T"
mysqldump -d --skip-comments -u root xxxxxx $T | sed 's/ AUTO_INCREMENT=[0-9]*//g' > $GIT_MYSQL/$T.sql
done;
git add -A && git commit -m "schema from $NOW" && git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment