Linux.com

Feature

Using versioning for your configuration files

By Radu Fericean on March 08, 2006 (8:00:00 AM)

Share    Print    Comments   

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.

Share    Print    Comments   

Comments

on Using versioning for your configuration files

Note: Comments are owned by the poster. We are not responsible for their content.

Use RCS instead

Posted by: suso_banderas on March 08, 2006 11:20 PM
CVS doesn't really lend itself to one or two files. I would recommend using RCS for configuration files instead. I've been doing it that way for years and it works much better. Just create an RCS directory in the config file directory and then co -l and ci -u config files.

#

Re:Use RCS instead

Posted by: Anonymous Coward on March 09, 2006 07:47 AM
If you use RCS (as I do) emacs or xemacs has convenient hooks to allow direct check-out/check-in from the editor itself. I have used this feature for years for maintaining development history of<nobr> <wbr></nobr>.profile,<nobr> <wbr></nobr>.kshrc and other configuration files.

RCS in this sitution may not be the most modern or most elegant, but I find it, by far, the most easy-to-use.

#

Re:Use RCS instead

Posted by: sakshale on March 10, 2006 05:45 AM
I also use RCS, but with vi... by having a simple script in my path;

#!/bin/sh
#
for file in $*
do

                co -l $file && vim $file && ci -u $file
done

I've used this script, literally, for decades.

#

Re:Use RCS instead

Posted by: karnesky on March 09, 2006 10:33 PM
The article is actually about using Bazaar-NG, not CVS. I think choice of version control system is one of personal preference. The better text editors usually have interfaces to any of the frequently used systems (at least as a plugin) & most of the commands are similar between any of them. Most can also handle "one or two files" easily (though there are typically hundreds of files in<nobr> <wbr></nobr>/etc).

#

I just use symlinks

Posted by: Anonymous Coward on March 08, 2006 11:56 PM
I use subversion and symbolic links in order to track changes on my config files.

I just put the working directory with my config files into<nobr> <wbr></nobr><tt>/opt/foo/etc/</tt> for example. Then I link the file<nobr> <wbr></nobr><tt>/opt/foo/etc/fstab.tomcatservers </tt> to<nobr> <wbr></nobr><tt>/etc/fstab</tt>

With this I can handle the same common config files onto multiple servers

#

Re:I just use symlinks

Posted by: Administrator on March 09, 2006 03:03 AM
There are quite a lot o versioning control systems (vcs) that can do the job. Since you already use one then it is not much point to change. Anyhow for the newcommers it is a good idea to experiment a little before choosing one.

Some other nice vcs (beside bazaar-ng and subversion):
mercurial, monotone, git/cogito, codeville, darcs, etc.

#

Cost in space?

Posted by: Anonymous Coward on March 09, 2006 12:01 AM
How much would this approach cost in space, if I'm constantly changing my dhcpd.conf as new machines arrive, or any other changes alike?

#

Re:Cost in space?

Posted by: Anonymous Coward on March 09, 2006 12:36 AM
Not much if you have only one repository server for all of your servers. AFAIK subversion only stores incremental changes to text files. In other words, if you dump different revisions of a file into a text files, you would see a series of "diffs" with each new revision.

So you have the whole file stored only when you import it to the repository for the first time.

See the subversion handbook for details: <a href="http://svnbook.red-bean.com/" title="red-bean.com">http://svnbook.red-bean.com/</a red-bean.com>

#

Re:Cost in space?

Posted by: Anonymous Coward on March 09, 2006 12:40 AM
Well, In the post above (previous) I was talking about my own approach with a central subversion server and many clients.

#

And the obligitory...

Posted by: Anonymous Coward on March 09, 2006 01:47 AM
...Windows has had this for years: it's called System Restore Points. Way to go, you're almost into the 21st century with the rest of the world!

#

Re:And the obligitory...

Posted by: Anonymous Coward on March 09, 2006 02:18 AM
Correct me if I'm wrong but System Restore sets restore points for your entire Windows installation, not for individual files like CVS/Subversion would. How are these the same? They can be used to achieve the same ends, but CVS/Subversion would be much more versatile than just setting a "restore point" for config files.

#

Re:And the obligitory...

Posted by: Anonymous Coward on March 09, 2006 03:42 AM
System Restore points are really more of LVM snapshots which unix has had since the 80s. So, welcome to the 80s.

#

Re:And the obligitory...

Posted by: Anonymous Coward on March 09, 2006 03:29 PM
Hehe. Sure. It's fun to troll. But your really out on a very fragile limb here. thats not versioning, as several has pointed out. From windows.com:

"Before you open the System Restore console, you may want to save your work and close all programs since System Restore requires you to restart your computer."

Welcome to windows-land. Boot, boot, boot. It's really fun. We'll try that again. Boot, boot, boot. If that's not what you wanted. We'll, just try re-booting this time. It's all about boot.

#

Re:And the obligitory...

Posted by: Anonymous Coward on March 11, 2006 12:06 PM
We'll, just try re-booting this time.

Typical technically inept unix idiot. Rebooting all the time is not as necessary in Windows as it is in linux, dumbass. I reboot my windows boxes once a year, if that, as opposed to daily for the linux boxes.

#

Re:And the obligitory...

Posted by: Anonymous Coward on March 12, 2006 08:19 AM
It's amusing how someone who calls another person an idiot is unable to keep a Linux box running for more than a day. Pot, meet mr. kettle.

#

Re:And the obligitory...

Posted by: Anonymous Coward on March 12, 2006 10:08 PM
... I reboot my windows boxes once a year...

Somebody hasn't been applying their patches then...

#

Re:And the obligitory...

Posted by: Anonymous Coward on March 15, 2006 12:10 AM
Somebody hasn't been applying their patches then...

That's because I know what I'm doing. I only apply the patches that either a) fix something that is actually broken on one of my machines (extremely rare) or b) are a valid security fix. By valid I mean "wasn't produced in response to moronic unix admins running windows boxes who can't grok how to secure the windows box" Like, for example, the one for code red. If you followed proper security best practices, that patch wasn't necessary. On the other hand, if you're a unix admin who believes an OS should be completely locked down by default and therefore never have to know anything, you got hit and hit hard. In comparison, the daily spew of security and bug fixes for Linux is almost impossible to keep up with. Sure, you can "yum update", but that only leads to non-booting systems if you're not paying attention. Grill on all you like, we've tried your crappy little OS, we're not impressed. You just keep working harder than you have to, and the rest of us who got past 1979 will enjoy the show.

#

Re:And the obligitory...

Posted by: Anonymous Coward on March 18, 2006 11:04 PM
Can you run your Windows with different versions of registry? Or, can you actually version your Windows registry?

If you can't understand the diff between snapshot and versioning, you can't understand how to secure your system.

You lazy Unix administrator just has no time teaching you the basic.

#

Re:And the obligitory...

Posted by: Administrator on March 09, 2006 03:21 AM
It is either linux getting into 21 century or you shuld read the article again<nobr> <wbr></nobr>:)

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya