Let's try git management under /etc with etckeeper

My name is Ito and I am an infrastructure engineer.
When operating a Linux server, configuration files are frequently rewritten.

When changing settings, you will likely want to manage backups by adding a date to the end of the file name

For example, something like this

# ls -al |grep httpd.conf -rw-r--r-- 1 root root 16730 Jan 25 22:59 httpd.conf -rw-r--r-- 1 root root 16730 Jan 25 22:59 httpd.conf_20151225 -rw-r--r-- 1 root root 16730 Jan 25 22:59 httpd.conf_20160120

However, if you create a backup file every time you change settings, your files will become scattered.
The more files you have, the more chances of making mistakes. This is not good for your mental health.

In such cases, we recommend using a VCS (version control system) called etckeeper

etckeeper will of course commit it manually,

・When the yum command is executed
・When the date changes

It will automatically commit at times such as:

First, install

Let's install etckeeper.
As mentioned earlier, we need a VCS

#yum install git

Install etckeeper from the epel repository

#yum install --enablerepo=epel etckeeper

The installation was successful

# rpm -qa |grep etckeeper etckeeper-0.64-1.el5.rf

Try it out

First, create a repository

# etckeeper init Initialized empty Git repository in /etc/.git/

I'll try committing

# etckeeper commit "First commit" [master (root-commit) 970f0b3] First commit Author: vagrant<vagrant@cli> 1174 files changed, 122593 insertions(+), 0 deletions(-) create mode 100755 .etckeeper create mode 100644 yum/version-groups.conf

Check the commit log.
You can use git commands in etckeeper vcs.

# etckeeper vcs log commit 970f0b335acdf586e099d57f1bc95d442bff853f Author: vagrant<vagrant@cli> Date: Fri Jan 29 21:02:33 2016 +0900 First commit

Let's try installing Apache.
etckeeper will commit the changes along the way.

#yum install httpd (omitted) etckeeper: pre transaction commit Updating : httpd-tools-2.2.15-47.el6.centos.1.x86_64 1/4 Updating : httpd-2.2.15-47.el6.centos.1.x86_64 2/4 Cleanup : httpd-2.2.15-47.el6.centos.x86_64 3/4 Cleanup : httpd-tools-2.2.15-47.el6.centos.x86_64 4/4 etckeeper: post transaction commit Verifying : httpd-tools-2.2.15-47.el6.centos.1.x86_64 1/4 Verifying : httpd-2.2.15-47.el6.centos.1.x86_64 2/4 Verifying : httpd-tools-2.2.15-47.el6.centos.x86_64 3/4 Verifying : httpd-2.2.15-47.el6.centos.x86_64 4/4 (omitted)

Let's try editing httpd.conf and checking the log when we commit it

# etckeeper vcs log commit a6cee87ff14bcf90587e98017d8a737777bcc5c0 Author: vagrant<vagrant@cli> Date: Fri Jan 29 22:43:53 2016 +0900 edit httpd.conf commit 970f0b335acdf586e099d57f1bc95d442bff853f Author: vagrant<vagrant@cli> Date: Fri Jan 29 21:02:33 2016 +0900 First commit

Let's check the diff to see which parts were edited

# etckeeper vcs diff 970f0b335acdf586e099d57f1bc95d442bff853f 66aefb8e71a7526988c0b3d3863fd6e7e3ec0b54 diff --git a/httpd/conf/httpd.conf b/httpd/conf/httpd.conf index 579d194..5870596 100644 --- a/httpd/conf/httpd.conf +++ b/httpd/conf/httpd.conf @@ -1,3 +1,4 @@ +#test # # This is the main Apache server configuration file. It contains the # configuration directives that give the server its instructions.

I'll try to return it to a certain point

# etckeeper vcs revert a6cee87ff14bcf90587e98017d8a737777bcc5c0 Finished one revert. # On branch master nothing to commit (working directory clean)

This is roughly how to use it.
It's great because it avoids having a huge number of configuration files under /etc/!

So, that's it for how to use etckeeper.
Let's use etckeeper to beautifully manage the contents under /etc!

If you want to talk to a cloud professional

Since our founding, Beyond has used the technical capabilities we have cultivated as a multi-cloud integrator and managed service provider (MSP) to design, build, and migrate systems using a variety of cloud/server platforms, including AWS, GCP, Azure, and Oracle Cloud

We provide a custom-made cloud/server environment optimized for our customers based on the specifications and functions of the systems and applications they require, so if you are interested in the cloud, please feel free to contact us

● Cloud / Server design and construction
● Cloud / Server migration
● Cloud / Server operation, maintenance and monitoring (24 hours a day, 365 days a year)

If you found this article useful, please click [Like]!
0
Loading...
0 votes, average: 0.00 / 10
3,441
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author