Created
January 18, 2022 11:26
-
-
Save michabbb/140853b5b8ac13701e187a37f2d2096f to your computer and use it in GitHub Desktop.
backup mysql schema with git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NOW=`date +%Y%m%d%H%M%S` | |
GIT_MYSQL=/backup/mysql | |
for T in `mysql -u root -N -B -e 'SELECT t.TABLE_NAME FROM information_schema.TABLES t WHERE t.TABLE_SCHEMA = "my_database" AND t.ENGINE != "MEMORY"'`; | |
do | |
echo "Backing up $T" | |
mysqldump -d --lock-tables=false --single-transaction=TRUE --skip-comments -u root my_databaswe $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