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

后端 未结 2 501
花落未央
花落未央 2021-02-11 04:43

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
相关标签:
2条回答
  • 2021-02-11 04:50

    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
    
    0 讨论(0)
  • 2021-02-11 05:10

    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 讨论(0)
提交回复
热议问题