在Debian Squeeze上使用etkeeeper和集市为您的/ etc目录使用版本控制
本教程将介绍如何使用Debian Squeeze上的etckeeper的帮助将/ etc
目录的内容存储在版本控制系统(VCS)中。 etkeeeper挂钩到Debian的软件包管理器apt中,以便每当您使用apt安装/删除软件包时,etckeeper都会将/ etc
目录中的所有更改提交到VCS; 它还跟踪文件元数据,例如对于/ etc / shadow等
文件很重要的权限。 使用etckeeper,如果更新覆盖了有价值的配置文件,则可以返回到先前版本的/ etc。
etkeveer不仅可以跟踪apt对/ etc
的更改,还会每天进行自动提交,以便您的手动更改也可以到VCS; 除此之外,您可以随时手动提交。
我不会保证这将为您工作!
1初步说明
本教程中我将使用Bazaar(bzr)作为VCS,尽管也支持git,hg和darcs。 您可以在本教程中阅读Bazaar: 在Debian Etch上使用Bazaar版本控制系统(VCS)
2安装和配置etckeeper
etckeeper和Bazaar可以安装如下:
apt-get install etckeeper bzr
接下来打开/etc/etckeeper/etckeeper.conf
...
vi /etc/etckeeper/etckeeper.conf
...并取消注释VCS =“bzr”
(确保所有其他VCS
行都注释掉):
# The VCS to use. #VCS="hg" #VCS="git" VCS="bzr" #VCS="darcs" # Options passed to git commit when run by etckeeper. GIT_COMMIT_OPTIONS="" # Options passed to hg commit when run by etckeeper. HG_COMMIT_OPTIONS="" # Options passed to bzr commit when run by etckeeper. BZR_COMMIT_OPTIONS="" # Options passed to darcs record when run by etckeeper. DARCS_COMMIT_OPTIONS="-a" # Uncomment to avoid etckeeper committing existing changes # to /etc automatically once per day. #AVOID_DAILY_AUTOCOMMITS=1 # Uncomment to avoid etckeeper committing existing changes to # /etc before installation. It will cancel the installation, # so you can commit the changes by hand. #AVOID_COMMIT_BEFORE_INSTALL=1 # The high-level package manager that's being used. # (apt, pacman-g2, yum etc) HIGHLEVEL_PACKAGE_MANAGER=apt # The low-level package manager that's being used. # (dpkg, rpm, pacman-g2, etc) LOWLEVEL_PACKAGE_MANAGER=dpkg |
请将所有其他行保留在原始状态 - 欢迎线AVOID_DAILY_AUTOCOMMITS = 1
注释掉将会进行每日自动提交的/ etc
,并且将AVOID_COMMIT_BEFORE_INSTALL = 1
注释掉,etkeeper将提交现有的更改/ etc,
然后再安装包与适应。
要初始化etckeeper,只需运行:
etckeeper init
(您可以通过运行来撤消此操作
etckeeper uninit
但这将删除VCS信息和etckeeper自己的簿记信息。 典型的用例是运行etckeeper uninit
,然后修改/etc/etckeeper/etckeeper.conf
,例如,因为要使用另一个VCS系统 - 最后再次运行etckeeper init
。 请记住,当您运行etckeeper uninit
!时,所有VCS信息将丢失!)
当您使用修改/ etc
目录的apt安装软件包时,etckeeper将自动执行第一个提交,但也可以手动执行第一个提交:
etckeeper commit "Initial commit"
您可以随时使用etckeeper commit
命令手动提交
,其次是日志消息(在这种情况下为“初始提交”
)。
3使用etckeeper
现在我们假设我们使用apt来安装修改/ etc
目录的包(如fail2ban):
apt-get install fail2ban
如果您看看输出,您将看到etckeeper在安装结束之前和之后都进行:
[...]
added logrotate.d/fail2ban
added rc0.d/K01fail2ban
added rc1.d/K01fail2ban
added rc2.d/S18fail2ban
added rc3.d/S18fail2ban
added rc4.d/S18fail2ban
added rc5.d/S18fail2ban
added rc6.d/K01fail2ban
Committed revision 2.
root@server1:~#
我们也可以使用etckeeper进行手动提交,例如手动修改文件后。 假设我们修改了/ etc / hosts
。 使用命令
bzr status /etc/
我们可以看到自上次提交以来文件发生了什么变化:
root@server1:~# bzr status /etc/
modified:
hosts
root@server1:~#
如第2章末尾所示,我们可以使用etckeeper commit
命令提交更改,例如:
etckeeper commit "Changed /etc/hosts"
root@server1:~# etckeeper commit "Changed /etc/hosts"
Committing to: /etc/
modified hosts
Committed revision 3.
root@server1:~#
4恢复更改
使用Bazaar,可以返回到/ etc
目录的先前版本(修订版),例如,如果程序包安装已经覆盖了您之前手动编辑的配置文件。
要回到以前的修订版本,我们需要知道其修订号。 例如,我们可以用bzr log
命令后跟一个文件或目录名找到它
bzr log /etc/hosts
将显示/ etc / hosts
受到影响的所有修订版本( revno 1,3,4,5
):
root@server1:~# bzr log /etc/hosts
------------------------------------------------------------
revno: 5
committer: root <root@server1.example.com.example.com>
branch nick: server1.example.com /etc repository
timestamp: Tue 2011-07-12 17:00:22 +0200
message:
Changed /etc/hosts
------------------------------------------------------------
revno: 4
committer: root <root@server1.example.com.example.com>
branch nick: server1.example.com /etc repository
timestamp: Tue 2011-07-12 16:59:03 +0200
message:
Changed /etc/hosts
------------------------------------------------------------
revno: 3
committer: root <root@server1.example.com.example.com>
branch nick: server1.example.com /etc repository
timestamp: Tue 2011-07-12 16:45:21 +0200
message:
Changed /etc/hosts
------------------------------------------------------------
revno: 1
committer: root <root@server1.example.com.example.com>
branch nick: server1.example.com /etc repository
timestamp: Tue 2011-07-12 16:43:39 +0200
message:
saving uncommitted changes in /etc prior to apt run
root@server1:~#
bzr log /etc
将显示/ etc
目录的所有修订版本:
root@server1:~# bzr log /etc
------------------------------------------------------------
revno: 5
committer: root <root@server1.example.com.example.com>
branch nick: server1.example.com /etc repository
timestamp: Tue 2011-07-12 17:00:22 +0200
message:
Changed /etc/hosts
------------------------------------------------------------
revno: 4
committer: root <root@server1.example.com.example.com>
branch nick: server1.example.com /etc repository
timestamp: Tue 2011-07-12 16:59:03 +0200
message:
Changed /etc/hosts
------------------------------------------------------------
revno: 3
committer: root <root@server1.example.com.example.com>
branch nick: server1.example.com /etc repository
timestamp: Tue 2011-07-12 16:45:21 +0200
message:
Changed /etc/hosts
------------------------------------------------------------
revno: 2
committer: root <root@server1.example.com>
branch nick: server1.example.com /etc repository
timestamp: Tue 2011-07-12 16:43:50 +0200
message:
committing changes in /etc after apt run
Package changes:
+fail2ban 0.8.4-3
------------------------------------------------------------
revno: 1
committer: root <root@server1.example.com.example.com>
branch nick: server1.example.com /etc repository
timestamp: Tue 2011-07-12 16:43:39 +0200
message:
saving uncommitted changes in /etc prior to apt run
root@server1:~#
假设我们要将/ etc / hosts
还原到第3版,我们可以这样做:
bzr revert --revision 3 /etc/hosts
如果要将整个/ etc
目录还原到修订版本2,可以按如下方式实现:
bzr revert --revision 2 /etc
5链接
- etckeeper: http : //kitenet.net/~joey/code/etckeeper/
- 义卖市场: http : //bazaar.canonical.com/en/
- Debian: http : //www.debian.org/