Keeping /etc/ In git

On a UNIX system, the /etc/ directory is what makes it what it is. Assuming you use just open source software, and forgetting about your user data (which should be in /home/), if you have /etc/ backed up for your server you can recreate it without much difficulty. It should definitely be included in your backup schedule.

I’m a big fan of git, the version control system. I do all my development work in git repositories, even when they are just projects that only I will work on (I treat me-on-desktop and me-on-laptop as two different identities, and git means I don’t worry that I absolutely have to be 100% synchronised in both locations before I can work). I was delighted then to discover etckeeper, which lets me keep my /etc/ directory in a git repository. Further, it hooks into Debian’s apt-get system and automatically commits each change.

This lets you easily see what changes any upgrades make, what changes you’ve made over time, and helps track down what you changed if you find you’ve broken something. It’s also easy to recover a file should you make a complete mess of it or inadvertently delete it.

The default install of etckeeper didn’t quite suit me though. You see I want to be able to backup all my various systems to one central repository. I want to keep one branch per system on that central repository, making it easy to see differences between them.

After installing etckeeper, I want it to base all commits it makes off one master root commit that I have already created in the central repository. This lets all the branches come from a common root.

Here’s what I do on each system after installing etckeeper (which by default automatically installs itself and makes a root commit, but I don’t want that default setup).

# Junk etckeepers default
$ rm -rf /etc/.git
# Initialise a new etckeeper repository without commiting anything
$ etckeeper init
# Add my central repository, and fetch the 'emptyroot' branch, which
# I leave pointing permanently at the empty initial commit in that
# repository
$ git remote add -t emptyroot up ssh://gitcentral.fussylogic.co.uk/git/etc.git
$ git fetch up
# Reset the local 'master' branch to point at that empty inital
# commit
$ git reset up/emptyroot
# Add something...
$ etckeeper commit "Initial checkin of ${HOST} /etc"

Then edit .git/config to push to a branch dedicated to this host rather than the master branch and “git push” will then backup /etc whenever you like. There should be no need to ever pull, you won’t make local changes remotely. etckeeper will take care of regularly committing any local changes.

This entry was posted in FussyLogic and tagged , . Bookmark the permalink. Trackbacks are closed, but you can post a comment.

Post a Comment

You must be logged in to post a comment.