March 8, 2006

Using versioning for your configuration files

Author: Radu Fericean

Some time ago I read an article about versioning your /home files with Concurrent Versions System (CVS). The article appealed to me because I like the idea of always being able to undo a mistake, compare my current work with a previous version, and keep a backup of my important files. But the thought that I would litter my home directory with a lot of CVS directories was enough to keep me from implementing it. Recently, however, I've thought about applying versioning to administration files.

The idea itself isn't new -- it has been done before with CVS and Subversion -- but new versioning systems spare us from littering our directories with CVS, .svn, or other files, and let us select only the files we want to be versioned without disturbing anything else in that directory. You can version your files, creating a single directory in your / directory, and be in the business after learning fewer than 10 simple commands.

For this project I turned to the free Python-based Bazaar-NG versioning system.

The traditional steps for modifying a configuration file begin with making a backup: cp file.conf file.conf_old. Edit the file, restart the application, and if something goes wrong, restore the old file and restart. Sometimes you end up having a lot of files with different _termination tags that give a hint of the version they represent.

A new and better approach begins with installing and initializing a versioning system. Add the configuration files you need to the versioning system. Every time you modify a file, and it works, register your new version. If it doesn't work, revert to the last working version. Transparently, keep as many versions as you want and simply revert to any of them when you want to compare or share them.

Here's a quick how-to for getting this system working using Bazaar-NG.

  1. Once you've installed Bazaar-NG, type bzr init / to initialize the versioning system for all directories on your system.
  2. Add a file to the versioning system with the command bzr add /etc/fstab(fstab is just an example; add whatever you need). Repeat this command for all the files you want to be versioned. You can add more files later.
  3. To commit the first version of an added file and give it a short description, type a command such as bzr ci -m "clean version of fstab". If you omit the -m parameter, your defined $EDITOR will pop up and allow you to write your change description.

To return to an older version of a given file, type bzr log /path/to/file to look for the revision number you want to go back to. Then enter bzr cat -rdesired_rev_number /path/to/file > /path/to/file to actually revert to that revision for the given file.

If you ever want to get rid of the versions database, simply remove the .bzr subdirectory in the / directory and your system will be as clean as before you started to version your files.

Other helpful commands:

  • bzr revert /path/to/file will discard modifications since the last commit. This is useful to quickly test some new options and then reverting to the working configuration file captured in the latest revision.
  • bzr diff -rsome_rev_number..other_rev_number allows you to see the modifications between the two revisions in standard diff format.

There are plenty other features you can try, such as specifying ignored files patterns and keeping multiple servers synchronized. Look at a Bazaar-NG tutorial or a tutorial of the versioning system of your choice.

Click Here!