Created
June 22, 2010 09:33
-
-
Save freeatnet/448242 to your computer and use it in GitHub Desktop.
Straightforward script to keep MySQL DB schema sql file in a project under SVN control
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
PROJECT_NAME='PROJECT_NAME' | |
MYSQL_HOST='localhost' | |
MYSQL_DB='website' | |
MYSQL_USERNAME='root' | |
MYSQL_PASS='toor' | |
wc_rev=`svn info | grep "Revision" | cut -d ' ' -f2` | |
backup_stamp=$PROJECT_NAME'-'`date +"%d-%m-%Y_%H-%M"`'-r'$wc_rev'.sql' | |
if [ -f db_schema.sql ]; | |
then | |
echo "Warning: deleting old db_schema.sql, last changed rev "`svn info db_schema.sql | grep "Last Changed Rev" | cut -d ' ' -f4` | |
mv db_schema.sql db_schema.sql.bak | |
fi; | |
echo '-- '$backup_stamp > db_schema.sql | |
mysqldump -h$MYSQL_HOST -u$MYSQL_USERNAME -p$MYSQL_PASS $MYSQL_DB >> db_schema.sql | |
if [ -f db_schema.sql.bak ]; | |
then | |
diff db_schema.sql.bak db_schema.sql | |
echo "Terminate the script now if you want the backup copy" | |
sleep 15 | |
rm -f db_schema.sql.bak | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment