Backup server config with a repository

Have you ever modified a batch of your awesome server config files just to find that nothing works any more? are you keeping your server options on a paper block or on another machine? go the easy way and backup all of your changes for the foreseeable future!

Existing tools

The easiest option is to use etckeeper. etckeeper allows /etc to be stored in a git, mercurial, darcs, or bzr repository. It hooks into apt (and other package managers including yum and pacman-g2) to automatically commit changes made to /etc during package upgrades. It tracks file metadata that revison control systems do not normally support, but that is important for /etc, such as permissions of /etc/shadow. etckeeper it's packaged in Debian, Ubuntu, Fedora, etc.

for the diy-ers: with git

If you want to feel the bolts and cogs, here is an easy way of doing this with git awesomeness:

cd /etc
git init
git add hostname
git commit -m "Initial commit." hostname
git branch stock  //for stock config
git branch play   //for playing config

//one example of use: add a config to the stock branch
git checkout stock
apt-get install squid
git add squid/squid.conf
git commit -m "Adding stock config file." squid/squid.conf
git checkout master

//other example of use: play with configs
git checkout play
git commit -m "Partially finished experiment." squid/squid.conf
git checkout master
git merge play // when the experiment is working and we want to keep it

observations:

  • this can be extended to the whole /. git should just work with binary files, see the chapter of this [book][book].

  • without configuring setgitperms, git does not record filesystem thingies:

    • file groups
    • file owners
    • file permissions (other than "is this executable")
    • extended attributes

other options could be: bup rdiff-backup

Sources:

http://joeyh.name/code/etckeeper/

http://anuradha.sayura.net/2010/01/using-git-to-manage-config-files.html

http://serverfault.com/questions/5410/using-revision-control-for-server-configuration-files

http://serverfault.com/questions/341199/git-as-a-backup-tool-am-i-a-silly-person

Víctor Cuadrado Juan

I'm Víctor Cuadrado Juan, a developer and FOSS enthusiast, in love with Linux. Currently living in Nürnberg, Germany. Feel free to waste your precious time around here, or to contact me: me at viccuad.me .