Track changes to /etc (configuration files) with etckeeper

I'm currently setting up my new dedicated server and one of the first packages I've installed there has been etckeeper, to keep track of any changes to files in the etc (configuration) directory.

Etckeeper supports various VCS (version control systems), namely Git, Mercurial and bzr.
Bzr support is available in Ubuntu since "Hardy".

I've chosen to use "bzr". If you want to stick to the default (git), just leave out the bzr related stuff:

# Install etckeeper and bzr:
sudo apt-get install etckeeper bzr

# Read the fine documentation:
zless /usr/share/doc/etckeeper/README.gz

Quick walkthrough:

# Edit the config, chose the VCS to use:
sudo sensible-editor /etc/etckeeper/etckeeper.conf
=> VCS=bzr

# Init the repository:
sudo etckeeper init

# Verify that the file list is OK and commit:
cd /etc
sudo bzr commit -m "Initial checkin"

Now, whenever you use "apt" to install or remove programs, it will commit any changed files before and after the action (if there are any changes - not all packages install files into /etc).

Because "/etc" is now a regular repository, you can also manually commit any changes there, e.g. when editing some configuration file.
If you don't manually commit any changes, they will get picked up during the next run of apt automatically.

This is of course highly recommended for Desktop systems, too: you can always look up what changes to the system configuration have been done (including the exact time when you or somebody else has installed a particular package).

Give it a try, it won't hurt :)

Update: Thierry Carrez has written some chronicle articles about etckeeper


Comment from: Jeff Schroeder [Visitor] Email
Jeff SchroederNo offense, but why on earth would you use bzr instead of the default git? Git is much faster and space efficient than bzr.

If you had a choice between the two it seems more obvious to use git. (my 2 cents)
2008-04-24 @ 05:57
Comment from: D McKeon [Visitor] Email
D McKeonWhy just /etc - why not any path - even / ?!
(Yes, commit/apt/commit is good).
2008-04-25 @ 08:10
Comment from: Daniel [Member] Email
@Jeff: Git is (still) faster, but that doesn't make a difference with a repo of that size and the number of checkins/actions you're doing with it. Regarding the space efficiency, I remember having read something different - but that isn't important either.
I'm more used to bzr than to Git and I've helped out getting the bzr support for etckeeper into Ubuntu Hardy. "Eat your own dogfood" etc.

D McKeon:
Yes, it might be a good idea to put more than /etc under version control. I can imagine that this becomes possible with etckeeper someday, but it makes not a lot of sense for the whole file system. You rarely want to put really everything under version control and you can already manually create a repo in "/", if you want to.
It should be also possible to integrate this into the workflow when using apt-get to install or remove packages, or just add your own hook command for apt/dpkg to call your custom commit command.
2008-05-01 @ 09:36
Comment from: Anon [Visitor]
AnonI noticed in the README that it is suggested that you run:

sudo etckeeper pre-commit

before you commit when you are using bzr. I'm not sure if this needs to be done before every commit, or just the first, but that could be a problem. I'm not sure how the automatic commits after apt are supposed to work under bzr if you manually have to "pre-commit" before each commit. (Note: I'd prefer to use bzr myself, so I'd like to see any issues resolved). The relevant lines from the README:
Warning: bazaar cannot support running etckeeper's pre-commit hook. To
ensure that all file metadata is stored in bzr, you have to manually
run "etckeeper pre-commit" before committing to bazaar.

2008-05-07 @ 20:36
Comment from: Daniel [Member] Email
Anon, the pre-commit hook takes care of the file metadata (extended attibutes which are not stored in VCS, like permissions of files). This is important for some files and therefore the meta data gets stored separately (so you can checkout with the same perms through etckeeper again).
The pre-commit hook gets run automatically for the apt hook, but you only have to manually call "etckeeper pre-commit", when committing changes yourself (e.g. you've edited a file and want to commit that - and it has special permissions).

There is already a etckeeper with full bzr pre-commit support, but it did not make it for Hardy (requires bzr 1.4).
2008-05-07 @ 21:15
Comment from: Ludovic Claude [Visitor] Email
Ludovic ClaudeAnd you announce this tool just after I followed this how to and put my /etc under bzr and re-installed my computer!


Now I understand that etckeeper adds also versioning of file metadata. Is there a way to install etckeeper but keep my previous history of /etc?
2008-05-07 @ 21:59
Comment from: Daniel [Member] Email
Yes, Ludovic, it is possible to install etckeeper if there's /etc/.bzr already.
That's what I did on my desktop machine, too. You can install etckeeper and it will re-use the existing .bzr repository (remember to configure "VCS=bzr").
2008-05-08 @ 00:33
Comment from: yungchin [Visitor] Email
yungchinHey guys, thanks for pointing me here. Ludovic: sorry, I didn't know :)
This is very cool indeed!!
2008-05-08 @ 11:24
Comment from: Ian [Visitor]
IanCool. Will have to check out etckeeper sometime.
2008-06-14 @ 18:12
Comment from: guvnrDOTcom [Visitor] Email
guvnrDOTcomnice - cheers Daniel
2009-03-05 @ 20:39
Comment from: Jørn Eriksen [Visitor]
Jørn EriksenHello there,

thanks for making a receipe that is so simple!

Best regards
2009-03-06 @ 09:13
Comment from: Marius Scurtescu [Visitor]
Marius ScurtescuSo, on Hardy, the only drawback is that you have to run pre-commit manually? And this is only needed for manual changes and commits you make? What happens if you forget to run pre-commit?

The apt hook works fine, pre-commit and all?

There is some more info here:
2009-03-06 @ 19:36
Comment from: seb [Visitor]
sebHi Daniel,

just going though your HowTo and I neede to use sudo to commit.

So instead of
bzr commit -m "Initial checkin"
I needed to
sudo bzr commit -m "Initial checkin"

Else I would get an arrno 13 from bzr.

Thanks for this post which led me to etckeeper.

2009-10-12 @ 21:49
Comment from: Daniel [Member] Email
Thanks, seb. Fixed that.
2009-10-13 @ 03:05
Comment from: Gabriel [Visitor]
GabrielThanks and regards.
2009-12-18 @ 14:30
Comment from: Denis [Visitor]
Denisawesome! Thanks for creating this, shame I'm only finding about this as I am about to mostly leave dedicated (ubuntu) servers behind and move on to the cloud... But I'm sure I'll still get a chance to use it here and there :) Keep it up!
2012-05-11 @ 17:42
Comment from: Denis [Visitor]
DenisBy the way -- it's pretty nice to use the free DVCS hosting on bitbucket for storing this kind of repo. That's what I'm doing, using hg! Maybe etckeeper even wants to do a push after each package manager run if there's an upstream repo (is that the right term? new to dvcs) configured (as in: paths.default = <hosted.repo/path>). It might even be doing that already, I just haven't found out :)
2012-05-11 @ 17:47

Leave a comment

Your email address will not be revealed on this site.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)
You can just use your OpenID to provide your name, e-mail and url.