Etckeeper is a handy tool that uses git to keep track of changes to anything in /etc (or any other folder you choose). It’s very simple to use and can help you quickly identify and undo stupid changes. Here’re some quick instructions to help you get started.

Install git and etckeeper on CentOS/RHEL, configure daily autocommit, and run the initial commit of your /etc/directory:

Here’s how to view history of changes/commits:

Here’s how to restore a file (/etc/hosts, in this example) from a particular autocommit:

By default, etckeeper keeps track of /etc, but you can specify a different folder or even multiple folders. For example, in addition to /etc I needed to add /var/adm/bin, where I keep most of my system scripts. A force of habit from my Solaris years. Here’s what you need to do:

To schedule a daily auto-commit, edit /etc/etckeeper/daily and make it look something like this. Note the for loop to deal with multiple monitored directories.

Searching etckeeper logs is fairly easy. The quick script below can help you with this task. Say, if you need to find commits that contain changes to /etc/sudoers, you would run it like so: etckeeper-track /etc/sudoers.

 

Leave A Reply

Please enter your comment!
Please enter your name here