如何为Git存储库组织和设置镜像备份服务器? [英] How to organize and setup mirrored backup servers for Git repositories?
问题描述
我正在将一些svn版本库移到Git中。所以,我基本上试图做的是这样的:
- 设置一台带有Git仓库的服务器,我将从中抽取并推送到 li>
- 为第一台服务器上的所有存储库设置一些备份服务器。 ,假设我在我的服务器上有一个目录,例如:
$ HOME / git /
,它只有裸露的存储库。例如: 〜/ git / project1.git
〜/ git / project2.git
〜/ git / project3.git
...
我的备份服务器可能是此服务器的镜像,或将备份的数据保存在档案或其他内容中。我想我可以这样做:
git clone --bare ssh:// gitserver /〜user / git / projectX。 git
或者:
$ cd〜/ git / project1.git
$ p $然后将所有项目中的所有捆绑包复制到我的备份服务器上。
$ git bundle create〜/ gitbackup / project1.bdl --all
但是,拥有大量项目或者任何策略都是一项乏味的任务,因此在每种情况下,我都需要制作一些脚本来自动执行任务。
我想知道你们是怎么做的?也许有更好的办法来做到这一点,而不是我已经考虑过的。任何提示将不胜感激。
解决方案总体思路是:
在您的备份服务器上创建裸回购
有钩子(可能是接收后挂钩),然后通过 git:
协议或ssh + git:
协议。
还有其他技巧早在2008年,基于 gibak ,但这个想法保持不变。
后接收钩子的示例:
- this one from Grant Limberg :
#!/ bin / sh
#
#在成功完成
#commit后调用。
#
#把这个文件放在.git / hooks和chmod + x
BRANCH =`git branch --no-color 2> / dev / null | sed -e'/ ^ [^ *] / d'-e's / * \(。* \)/ \ 1 /'`
git push origin $ BRANCH
- that one (in ruby)
#!/ usr / bin / env ruby
STDIN.read.split(\\\
)。
oldrev,newrev,refname = line.split('')
如果refname.match(/ ^ refs \ / heads\ /(.*)/)
分支= $ 1
`git push origin#{branch}`
else
puts#{refname}很奇怪,不知道该怎么办。
结束
结束
I am moving some svn repositories to Git. So, what I basically try to do is this:
- Setup one server with bare Git repositories from which I will pull and push to
- Setup a few backup servers for all of my repositories that are on the 1st server.
So, let's say i have a directory on my server, like: $HOME/git/
, which has bare repositories. Eg:
~/git/project1.git
~/git/project2.git
~/git/project3.git
...
My backup servers may be mirrors to this server, or keep the backed up data in archives or whatever. I suppose I can do something like:
git clone --bare ssh://gitserver/~user/git/projectX.git
Or maybe:
$ cd ~/git/project1.git
$ git bundle create ~/gitbackup/project1.bdl --all
and then copy all bundles from all projects to my backup servers.
However, having a lot of projects either strategy would be a tedious task, so in each case I would need to make some scripts to automate the task.
I wonder how are you guys doing this? Maybe there is some better way to do it than what I considered already. Any tip would be appreciated.
The general idea would be to:
- create bare repo on your backup server
- have hooks (probably a post-receive hook) on your main bare Git repository to automatically push whatever is received to the corresponding Git backup repo, either through
git:
protocol orssh+git:
protocol.
There are other techniques back in 2008, based on gibak, but the idea remains the same.
Example of a post-receive hook:
- this one from Grant Limberg:
#!/bin/sh # # A hook script that is called after a successful # commit is made. # # Place this file in .git/hooks and chmod +x BRANCH=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` git push origin $BRANCH
- that one (in ruby)
#!/usr/bin/env ruby STDIN.read.split("\n").each do |line| oldrev, newrev, refname = line.split(' ') if refname.match(/^refs\/heads\/(.*)/) branch = $1 `git push origin #{branch}` else puts "#{refname} was weird, not sure what to do." end end
这篇关于如何为Git存储库组织和设置镜像备份服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!