我正在将一些 svn 存储库移至 Git。所以,我基本上尝试做的是:
- 设置一台带有裸 Git 存储库的服务器,我将从中拉取和推送到该存储库
- 为第一台服务器上的所有存储库设置一些备份服务器。
所以,假设我的服务器上有一个目录,例如:$HOME/git/
,它有裸存储库。例如:
~/git/project1.git
~/git/project2.git
~/git/project3.git
...
我的备份服务器可能是该服务器的镜像,或者将备份的数据保存在档案中或其他任何位置。我想我可以做类似的事情:
git clone --bare ssh://gitserver/~user/git/projectX.git
或者可能:
$ cd ~/git/project1.git
$ git bundle create ~/gitbackup/project1.bdl --all
然后将所有项目中的所有捆绑包复制到我的备份服务器。
然而,拥有很多项目无论采用哪种策略都会是一项乏味的任务,因此在每种情况下我都需要制作一些脚本来自动执行任务。
我想知道你们是怎么做的?也许有比我已经考虑的更好的方法来做到这一点。任何提示将不胜感激。
总体思路是:
- 在您的备份服务器上创建裸存储库
- have hooks http://git-scm.com/docs/githooks(可能是一个接收后挂钩 http://toroid.org/ams/etc/git-repository-mirrors)在您的主裸 Git 存储库上,自动将收到的任何内容推送到相应的 Git 备份存储库,或者通过git:协议或ssh+git:协议 https://git-scm.com/book/id/v2/Git-on-the-Server-The-Protocols#_the_ssh_protocol.
还有其他技术早在2008年 http://web.archive.org/web/20090518010102/http://www.bramschoenmakers.nl/en/node/551, 基于gibak http://web.archive.org/web/20081219090018/http://eigenclass.org/hiki/gibak-backup-system-introduction,但想法保持不变。
接收后挂钩的示例:
-
this one http://gist.github.com/68811 from 格兰特·林伯格 http://github.com/glimberg:
#!/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 http://www.stopdropandrew.com/2010/01/20/making-an-authoritative-git-repo-auto-push-to-github.html(红宝石)
#!/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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)