How to synchronize Git Repositories across 2 Servers
Asked Answered
V

2

9

I'm looking for a way to automatically synchronize Git repositories across (2) servers so they are interchangeable from a third point.

Situation is as follows: We heavily use git for all our projects, and some of the Repositories grow quite fast in size. Currently we have one central server and everyone is pushing/pulling to/from this one. However this all goes through the internet connection and therefore is not the fastest way.

The Idea: Put another server in the office, and have all the git repositories there for in-office-use. This server would need to be synchronized with the one on-line. At best the users would not even know which one they use via some dns-adjustment, so the address of the on-line server repositories resolves to the in-office-one when connected to the network there.

Is anyone already doing something similar out there? Or is there a easier way to accomplish the target.

Vivavivace answered 26/11, 2010 at 10:38 Comment(2)
Do people outside the office need to be able to push?Sammy
yes, if possible within a reasonable effortVivavivace
S
4

I would see such a mechnism easily done with the SSH protocol (meaning a framework like gitolite is in place both on the LAN repo and the WAN http repo), because then you can easily extend the ssh forced command mechanism to:

  • first check if the two repo are synchrone
  • reject the command if the local repo is less up-to-date than the remote one
  • synchronize the local repo with the remote one of needed

To do so with hooks is more complicated and would need to be carefully setup for each kind of server-side hooks in order to keep that synchronization mechanism up at all time.

Steelyard answered 26/11, 2010 at 12:43 Comment(2)
i took a quick look into the forced command description but i'm not quite sure i understand how this would work. when i make a connection to the lan-repo the forced command would then check and see if it has to sync with the wan repo (and do so if needed) and only then allow the push to go through to the repository? how would that look from the users perspective since i expect at least a little delay on push that wayVivavivace
@maxigs: the idea (and gitolite illustrates it) it to encapsulate any command you send (through ssh) with a script which will a/ validate your command b/ execute if needed something before that command c/ execute the original command d/ execute if needed something after that command. So in your case the a/ (validation step) can be checking if the repo on the server side (where the ssh forced command lives) is not more up-to-date than the local repo from which the push was initiated.Steelyard
D
0

Gitolite has a feature that will mirror repositories. You could set up the one in the office as the master, and the online one as the slave, and allow pushing to either one.

Dilan answered 15/6, 2012 at 14:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.