4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

etckeeperを使ってみる

Posted at

設定してみる

インストール

  • バージョン管理のシステムとしてgitをインストール
yum install git
  • epelリポジトリからetckeeperをインストールします
yum install epel-release
yum install etckeeper --enablerepo=epel

リポジトリの初期化

  • gitリポジトリの作成、バックアップの開始
etckeeper init

実行結果が以下。
/etc/配下にgitリポジトリが作成されます

[root@localhost ~]# etckeeper init
Initialized empty Git repository in /etc/.git/
[root@localhost ~]# ls -al /etc/ | grep git
drwx------   7 root root      132 12月  8 20:44 .git
-rw-r--r--   1 root root      896 12月  8 20:44 .gitignore
  • 最初のコミット

手動で最初のコミットをします。

etckeeper commit "[任意のコメント]"

実行結果が以下
これで現在のファイルがコミットされました。

[root@localhost ~]# etckeeper commit "1st commit"
 create mode 100644 yum/protected.d/systemd.conf
 create mode 100644 yum/vars/contentdir
 create mode 100644 yum/vars/infra
 create mode 100644 yum/version-groups.conf
 .....

ログの確認

コミットログを確認します。
etckeeperは単独のコマンドがないので、 etckeeper vcs [gitのコマンド] を実行することで確認が出来ます。

etckeeper vcs log

実際に実行結果が以下。
1st commit がきちんとコミットされています。

[root@localhost ~]# etckeeper vcs log
commit c844247004a4308939178d536135628bb03031cc (HEAD -> master)
Author: miyuki_samitani <miyuki_samitani@xxxx.com>
Date:   Tue Dec 8 21:09:32 2020 +0900

    1st commit

実際に動くことを確認

  • httpdをインストールしてみる
yum install httpd
  • ログを確認する

上記と同様に etckeeper vcs log で確認します
httpdをインストールしたあとに自動でコミットされたものがlogとして表示されました。

[root@localhost ~]# etckeeper vcs log
commit 7699f77c60903a9b5bdcb5fe493c484db71ab9cb (HEAD -> master)
Author: miyuki_samitani <miyuki_samitani@xxxx.com>
Date:   Tue Dec 8 21:10:32 2020 +0900

    committing changes in /etc made by "/usr/bin/python /usr/bin/yum install httpd"
    
    Package changes:
    +0:apr-1.4.8-7.el7.x86_64
    +0:apr-util-1.5.2-6.el7.x86_64
    +0:httpd-2.4.6-97.el7.centos.x86_64
    +0:httpd-tools-2.4.6-97.el7.centos.x86_64
    +0:mailcap-2.1.41-2.el7.noarch

commit c844247004a4308939178d536135628bb03031cc
Author: miyuki_samitani <miyuki_samitani@xxxx.com>
Date:   Tue Dec 8 21:09:32 2020 +0900

    1st commit

設定を戻してみる

  • 設定を行う

戻す設定を入れます。
テキトーにhostsに設定を入れます。

vi /etc/hosts
==========
追加
1.1.1.1 localhost.co.jp
==========
  • commitする

ちゃんと1ファイルだけcommitされました!

etckeeper commit "hosts変更"
[root@localhost ~]# etckeeper commit "hosts変更"
[master e47ce4c] hosts変更
 1 file changed, 1 insertion(+)
  • commit logを確認
etckeeper vcs log

hosts変更 のcommitが登録されていました!

[root@localhost ~]# etckeeper vcs log
commit e47ce4c0db287540c4bf555c2970b6797d66062e (HEAD -> master)
Author: miyuki_samitani <miyuki_samitani@xxxx.com>
Date:   Tue Dec 8 21:13:30 2020 +0900

    hosts変更

commit 7699f77c60903a9b5bdcb5fe493c484db71ab9cb
Author: miyuki_samitani <miyuki_samitani@xxxx.com>
Date:   Tue Dec 8 21:10:32 2020 +0900

    committing changes in /etc made by "/usr/bin/python /usr/bin/yum install httpd"
    
    Package changes:
    +0:apr-1.4.8-7.el7.x86_64
    +0:apr-util-1.5.2-6.el7.x86_64
    +0:httpd-2.4.6-97.el7.centos.x86_64
    +0:httpd-tools-2.4.6-97.el7.centos.x86_64
    +0:mailcap-2.1.41-2.el7.noarch

commit c844247004a4308939178d536135628bb03031cc
Author: miyuki_samitani <miyuki_samitani@xxxx.com>
Date:   Tue Dec 8 21:09:32 2020 +0900

    1st commit
  • 設定を戻す

以下が戻したいコミットです。
commit e47ce4c0db287540c4bf555c2970b6797d66062e を消して、
commit 7699f77c60903a9b5bdcb5fe493c484db71ab9cb の直後に戻ってくる、ということをします。

▼現在のコミットで消したいコミット
commit e47ce4c0db287540c4bf555c2970b6797d66062e (HEAD -> master)
Author: miyuki_samitani <miyuki_samitani@xxxx.com>
Date:   Tue Dec 8 21:13:30 2020 +0900

    hosts変更

▼このcommitがされた直後に戻ってくる
commit 7699f77c60903a9b5bdcb5fe493c484db71ab9cb
Author: miyuki_samitani <miyuki_samitani@xxxx.com>
Date:   Tue Dec 8 21:10:32 2020 +0900

    committing changes in /etc made by "/usr/bin/python /usr/bin/yum install httpd"
    
    Package changes:
    +0:apr-1.4.8-7.el7.x86_64
    +0:apr-util-1.5.2-6.el7.x86_64
    +0:httpd-2.4.6-97.el7.centos.x86_64
    +0:httpd-tools-2.4.6-97.el7.centos.x86_64
    +0:mailcap-2.1.41-2.el7.noarch

こちらでもgitのコマンドを利用して、 etckeeper vcs revert [コミットID] で戻します。
コミットIDは上でも書いたように、現在のコミットで消したいコミットの e47ce4c0db287540c4bf555c2970b6797d66062e になります。

etckeeper vcs revert e47ce4c0db287540c4bf555c2970b6797d66062e

コミットメッセージを追加してくださいと表示されましたが、そのままで良いので :wq で進みます。

Revert "hosts変更"

This reverts commit e47ce4c0db287540c4bf555c2970b6797d66062e.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Changes to be committed:
#       modified:   hosts
#

リバートされました。

[root@localhost ~]# etckeeper vcs revert e47ce4c0db287540c4bf555c2970b6797d66062e
[master 1f5eded] Revert "hosts変更"
 1 file changed, 1 deletion(-)
  • commit logの確認

リバーとされたログが一番上に表示されています。
リバートもcommit logに残ります。

[root@localhost ~]# etckeeper vcs log
commit 1f5eded625f0d75f2c47fbfef1397e5549c68643 (HEAD -> master)
Author: miyuki_samitani <miyuki_samitani@xxxx.com>
Date:   Tue Dec 8 21:21:16 2020 +0900

    Revert "hosts変更"
    
    This reverts commit e47ce4c0db287540c4bf555c2970b6797d66062e.

commit e47ce4c0db287540c4bf555c2970b6797d66062e
Author: miyuki_samitani <miyuki_samitani@xxxx.com>
Date:   Tue Dec 8 21:13:30 2020 +0900

    hosts変更

  • ファイルの確認(/etc/hosts)

確認のため、 設定変更したファイルを確認しました。
1.1.1.1 localhost.co.jp はきちんと消えています。

[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@localhost ~]# 

参考

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?