When Your git Server Dies

I’ve written before about how I use git to keep my two main machines in sync. The other day the linux server that I kept the repositories on died. I had turned it off for a few seconds to deal with a power problem and afterwards it wouldn’t spin up. That was a little annoying because I’d recently rebuilt the OS. The big problem, though, was that it was the machine that hosted my git repositories.

Until I could replace the machine, I needed a temporary home for those repositories. Happily, I use git instead of something like subversion so my two machines had the full history for each repository. All I needed to do was make a directory on aineko, my iMac, to hold the repositories, clone the repositories into that directory, create the git-daemon-export-ok file in each repository, and finally point the individual repositories on each machine to aineko instead of the linux machine.

Easy enough but I wasn’t looking forward to the drudgery of it all. I decided to solve the problem once and for all by automating the process. It’s nothing special but if anyone else has the misfortune to lose the server hosting their repositories, perhaps this will help.

#! /bin/bash
# -*- mode: sh -*-
REPOS="/Users/jcs/org /Users/jcs/medical /Users/jcs/tax /Users/jcs/.emacs.d /Users/jcs/tt"
for r in $REPOS
do
    git clone --bare $r `basename $r`".git"
    touch `basename $r`".git/git-daemon-export-ok"
    sed 's/url = bedia:/url = aineko:/' $r"/.git/config" > tmp
    mv tmp $r"/.git/config"
done

Now all I had to do was create the new directory, put this script in it, and run it. I also had to run it, without the git clone and touch on my other machine to point the repositories to the new server. Once I get a new server and configure it, I can just copy the repository directory on aineko to the new machine.

This entry was posted in Programming and tagged . Bookmark the permalink.