Export and import databases on Git push and pull

I need my database to synchronize on two local computers without using a server between them. After some research, I thought I could use Git hooks to complete this task for me.

Basically I want to run mysqldump on git push (and add the SQL file to commit) and mysqlimport in git pull to the remote repository.

I could not find any specific hooks for this. I tried pre-commit hook, but this did not add the SQL file to the current commit. Then I tried prepare-commit , but no luck.

Has anyone got an answer for this?

+4
source share
2 answers

Ben Coulbertis uses this solution to fix the pre-commit and post-merge git bindings. It works like a charm!

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

+2
source

I would write a wrapper for your system, perhaps "commit.php" or "git -ci.sh" or something else. Then you can use bash or perl or python or php, or whatever is convenient for you, and run each command one by one, ending with a commit.

I suggest this after you encounter similar problems, trying to add to the commit that the pre-commit hook is running. In addition, there is no โ€œpushโ€ or โ€œpullโ€ hook on the downstream side (I use a central repository so that this can work if you have two machines that push and pull with each other, as you think).

I have a two way deployment script for one of my websites where I have a long pre-commit script, but on a web server I have a wrapper like this one that retrieves, then checks the commit, gives a report and gives me options about merging and rsync with another server, etc. He replaced the โ€œpullโ€ hook, which would probably be a serious security risk.

Hans

+2
source

All Articles