开发者

Export and import database on Git push and pull

I need my database to be in sync across two local computers, without using a server in between. After some research I thought I could use Git hooks to do the task for me.

What I basically want is to run mysqldump on git push (and add the SQL file to the commit) and mysqlimpor开发者_运维问答t on git pull to and from the remote repository.

I couldn't find any specific hooks for this. I tried the pre-commit hook, but this didn't add the SQL file in the current commit. I then tried prepare-commit, but without luck.

Has anyone got an answer for this one?


This solution by Ben Kulbertis uses the pre-commit and post-merge git hooks to do the job. Works like a charm!

http://ben.kulbertis.org/2011/10/synchronizing-a-mysql-database-with-git-and-git-hooks/


I'd write a wrapper for your system, maybe "commit.php" or "git-ci.sh" or something. Then you can use bash or perl or python or php or whatever you are comfortable with and run each command one by one, finishing with the commit.

I suggest this after running into similar issues with trying to add to the commit that the pre-commit hook is running. Also, there are no "push" or "pull" hooks on the downstream side (I use a central repository so this might work if you have two machines pushing and pulling with each other as you seem to).

I have a two sided deploy script for one of my web sites where I have a long pre-commit script but on the web server I have a wrapper like this that fetches, then inspects the commit, outputs a report and gives me options about whether to merge and rsync with another server, etc. It replaced a "pull" hook that would probably be a major security hazard.

Hans

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜