Keeping git mirrors in sync

I have several sites that use Drupal, I have several servers, live, dev1, dev2 ...

Drupal codebase repo is large (112Mb), so I try to make the most of git hard-linking features, so every time I add a site, it does not duplicate this.

So, let's say, on a real server, I have a bare master repo, and all my sites are clones of this, each of which uses a different branch. It works fine on a single server, hard links are used, it is fast and efficient.

But on my dev servers, they are usually all cloned from the main repo server, which means that two sites on the same computer cannot use hard links to save space.

What I would like to do is install a bare repo mirror on each of my development servers and then clone from it.

dev1$ git clone --mirror live:master-bare-repo dev1-mirror-repo dev1$ git clone -b site1 dev1-mirror-repo site1 dev1$ git clone -b site2 dev1-mirror-repo site2 

Everything is still. But I want the mirrors to be constantly in sync. So I used post-receive hook on the dev1 mirror to do git push --mirror origin . Now, if site1 on dev1 clicks on a commit, they are magically pushed to master-bare-repo.

But what if I make changes on the live server and push this? I can’t set up the post-receive hook to click on the other (s) because it supposedly causes their post-receive hooks to fall into recursion?

Is there any smart way?

+7
source share
1 answer

First of all, you will not end up in recursion , since the post-receive hook fails when "Everything is updated" (as indicated in this other question ), which will be the result of pushing mirrors to a live server.

On the other hand, this is not the whole scalable design (every time you add a new mirror, you need to change your host on the server to add the site that you want to click). Most likely, you will find it more elegant to use the "lazy" synchronization strategy in your mirrors: when they get a push, they do not just click on the wizard, but before that they extract / pull from the wizard. This way, you don’t have to adjust the hook in the main thing, and the synchronization strategy will be completely controlled by the mirrors. The disadvantage of this strategy is that ultimately you will want to make changes to the live server that you want to distribute to the mirrors before they need to make any changes. Therefore, you should consider whether the changes in your masters are so important as to compensate for the tradeoff in scalability. Of course, the patch to make this “scalable” design also “synchronized” is to use an external cron job to periodically check for changes to master, as suggested in the comments.

+4
source

All Articles