简体   繁体   English

如何为Git存储库组织和设置镜像备份服务器?

[英]How to organize and setup mirrored backup servers for Git repositories?

I am moving some svn repositories to Git. 我正在将一些svn存储库移至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 设置一台具有裸Git存储库的服务器,我将从中拉出并推送到
  • 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. 因此,假设我在服务器上有一个目录,例如: $HOME/git/ ,它具有裸存储库。 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: 总体思路是:

There are other techniques back in 2008 , based on gibak , but the idea remains the same. 早在2008年 ,还有其他基于gibak的技术 ,但想法仍然相同。


Example of a post-receive hook: 接收后挂钩的示例:

#!/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
#!/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

Doesn't seem like there's anything special here -- you just need a standard backup solution. 这里似乎没有什么特别的地方,您只需要一个标准的备份解决方案即可。

I've had good luck with rsnapshot, or rsync if I just need simple backups. 我对rsnapshot或如果我只需要简单备份的rsync感到很幸运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM