The etckeeper chronicles, part 1
One thing I have been working on in this cycle is beginning to integrate an easy solution to put /etc under revision control. I have found etckeeper, by Joey Hess, to be the right tool for the job. The version in Jaunty will feature better support of bzr as the underlying VCS, and a couple of improvements I pushed upstream. In this series of articles, I’ll present an overview of how this solution works in Jaunty and the future planned (post 9.04 release) improvements.
Why you want it
Putting /etc under revision control allows you to keep a precise history of the changes made to configuration files. This is a well-known best practice on server environments with multiple sysadmins, where being able to tell who changed what files, and when, is very useful. But this is also nice to have on home servers or on desktops ! And keeping a log is only the tip of the iceberg of possibilities that are available once you have those files under a DVCS. Think reversion to a previous revision, branching…
To install the etckeeper/bzr combination, you will simply run:
$ sudo apt-get install etckeeper bzr
Then to initialize the repository:
$ sudo etckeeper init $ sudo etckeeper commit "Initial commit" [...] Committed revision 1
This will create a bzr repository for /etc, add all files below /etc (except etckeeper ignore list) to that repository and commit (save) the current contents as revision 1.
Using etckeeper is quite simple. Whenever you make a coherent change to your configuration files, you can commit it by calling etckeeper commit:
$ sudo vi /etc/hosts $ sudo vi /etc/resolv.conf $ sudo etckeeper commit "Change domain name" [...] Committing to: /etc/ modified hosts modified resolv.conf Committed revision 2.
Who did what when ?
To be able to get a nice history of changes, you’ll have to call the underlying VCS system, which in our Jaunty setup is bzr. For example, this will give you a nice one-revision-per-line history of the revisions present in the repository:
$ sudo bzr log --line /etc 2: thc 2009-02-22 Change domain name to mycompany.com 1: thc 2009-02-22 Initial commit
Here you go, a nice captain’s log of changes made to configuration files. One feature I recently pushed back upstream is sudo integration: the username shown (thc) is the one of the user running the ‘sudo etckeeper’ command, not an undetermined ‘root’.
Now suppose you want to see what changed in revision 2 ? Try:
$ sudo bzr diff -c2 /etc === modified file 'hosts' --- hosts 2009-02-22 11:26:09 +0000 +++ hosts 2009-02-22 11:27:34 +0000 @@ -1,5 +1,5 @@ 127.0.0.1 localhost -127.0.1.1 jaunty-test.example.com jaunty-test +127.0.1.1 jaunty-test.mycompany.com jaunty-test # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback === modified file 'resolv.conf' --- resolv.conf 2009-02-22 11:26:09 +0000 +++ resolv.conf 2009-02-22 11:27:34 +0000 @@ -1,2 +1,2 @@ nameserver 22.214.171.124 -domain example.com +domain mycompany.com
Neat, uh ? You can also check the differences between the current configuration and the last-committed revision using:
$ sudo bzr diff /etc
In next episode
In part 2 of the etckeeper chronicles, we’ll see how etckeeper autocommits help in getting the right picture with minimal effort. Stay tuned !