开发者

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

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 or ssh+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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜