[Linux Admin] How to track configuration changes with etckeeper

in #sysadmin6 years ago

If you manage a Linux based machine you have likely run into problems where you accidentally edited a configuration file in /etc or even deleted it and had regrets. Any system administrator knows you should back up a configuration file before editing it. How often do you do that though?

What is etckeeper?

etckeeper is a small set of scripts that will create a version control repository in /etc (where most systemwide configuration files are stored) and automatically check-in changes including metadata like file permissions.

etckeeper supports Git, Mercurial, Darcs, and Bzr repos, I use the Git which is the default option.

etckeeper will automatically check-in and commit changes to /etc when installing and uninstalling a package via your system package manager. When making changes by hand, you can have etckeeper check them in and commit them with a single command.

How to install etckeeper

sudo apt install etckeeper

How to use etckeeper

When etckeeper is installed, it will create a repository automatically by silently issuing the sudo etckeeper init command.

If you prefer to use something other than git, you can issue the command sudo etckeeper uninit and change the configuration file to choose a different version control. You will need to re-issue sudo etckeeper init to initialize the repository.

Once etckeeper is installed, it will automatically track files changed when using the system package manager to uninstall or install packages. etckeeper will also automatically commit changes on a daily basis if you haven't done so manually. Although I recommend manually committing changes as you make them.

To manually commit changes to /etc you just have to issue the following command.

sudo etckeeper commit "Update DNS server list"

This will automatically check-in the changed files and commit them with the message "Update DNS server list". The more frequently you use sudo etckeeper commit the more granular and specific your commits will be. Just like with programming, you want to keep your commits to the least amount changes to solve a particular problem.

If you are updating the hostname, changing DNS server, setting some sysctl parameters, these should be unique commits unless they are all required to solve one problem.

If you just type sudo etckeeper commit without a message, it will open your default text editor to allow you to create a longer commit message.

How to recovery changes?

Depending on the version control software chosen for etckeeper (defaults to Git) you just use the normal commands you would use.

For example, let's say we change the hostname in /etc/hostname , and we have committed the changes using `sudo etckeeper commit "Set hostname to nginxproxy". Later you want to see what has changed you can use the following git command:

sudo git diff HEAD^ HEAD -- /etc/hostname

If you do not know how to use version control, I highly recommend you learn. If of course you are in need of such things.

themarkymark.png

My recent popular posts

Sort:  

Way to late for me:
https://steemit.com/crontab/@isnochys/the-story-of-crontab-r
;)

Hmm.. Would it even save /var/spool/crontab?
Anyway, who needs backup?
Sissies! :))

It only handles /etc

Thanks for sharing this @themarkymark... Very helpful. I already bookmarked this! Surely be needing it.


Happy Steeming

thats a great post of technology..actually this post is helpful for us...

The very first time i encounter this ish i was really bad at everything...it nice of you sharing it

Short, concise and clear. Thank you, I will use this from now on.

@themarkymark i just heard of linus os esp parrot sec from my course mate in school, i have shallow knowledge on a particular stuff. i am having issues on dual booting .
Your help on this will be appreciated sir @udezee.
Your post makes linus os likeable to window.
Lol

Not mark, but you could load up your second OS into a VMWare.

This, or even HyperV which comes with Windows or VirtualBox.

Hey @themarkymark. Thank you so much for sharing this it's so helpful. Will bookmark it definitely! Thanks for sharing!

Cool tutorial Marky.
Next you should do a tutorial on how to hack Bitcoin passwords with the BRUTALIS system.
Cheers

Don't need Brutalis, can build your own cheaper.

muy buena publicación, gracias por la información