In order to understand why using etckeeper is a good idea, we first have to explain a little on how the configuration of Linux works.
In some cases when we install an application on our system, this application needs to store one or more configuration files on the file system. For example when you install nginx, it will store its configuration files in the directory: /etc/nginx/
. Surely you will want to modify one of the configuration files to set up one or more sites. Or maybe you want to configure nginx to act as a reverse proxy.
Other applications may use other config files on different paths, but they will pretty much always be inside the /etc
directory.
etckeeper Allows you to keep track to changes of these files and allows you to rollback the systems configuration when needed.
The first step to starting to use etckeeper is to install the package. Using rpm based distributions you can install etckeeper using yum
:
# yum install etckeeper
# dnf install etckeeper
(on newer systems)On deb based systems you can use apt
:
# apt-get install etckeeper
# apt install etckeeper
(on newer systems)After installing etckeeper we need to initialize the repository. That can be done by running the following etckeeper command:
# etckeeper init
Now that the repository is initialized it is time to commit the initial state of the configuration files:
# etckeeper commit
A screen allowing you to type a commit message appears. Please use descriptive messages so that at some point you can look back at the history and easily recognize the change.
When we update our system, sometimes we get new configuration files as well. In some cases the old file will still work and in other cases they need to be modified first. In any case etckeeper will automatically commit the state of our configuration files when updating the packages.
Since etckeeper uses a VCS it is also possible to use subcommands. For example:
etckeeper vcs diff
will execute git diff
. However you can run the etckeeper commands from any location in the file system and it will only affect the /etc
directory/repository, while the git commands need to be executed from inside the repository.