etckeeper 可以用来跟踪 /etc 之外的配置文件吗?

etckeeper 可以用来跟踪 /etc 之外的配置文件吗?

具体来说,我想跟踪我的grub.conf/boot/grub/grub.conf)和一些 oracle 文件(即/db/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora)。

我尝试使用链接;但是 etckeeper/git 仅跟踪链接指向的位置,而不是实际内容。而且我无法创建硬链接,因为文件位于另一个卷上。

我知道我可以设置另一个 GIT 存储库,但我宁愿将其全部放在 etckeeper 中。

更新

根据 nealmcb 的回答我想出了以下脚本:

#!/bin/sh
set -e

# Based on nealmcb's idea/script from http://serverfault.com/questions/211425/

# If you want other configuration data or files on the system also
# opportunistically tracked via etckeeper, use this script to copy them in.

# If there is a hook of some sort available related to the files
# you're mirroring, you can call etckeeper directly and track them
# proactively, rather than just opportunistically here.

MIRROR_ROOT=/etc/etckeeper.mirror.d
echo "etckeeper: mirroring outside files to $MIRROR_ROOT/:"

mirror_dir() {
   LOCAL_PATH=$1
   echo "  $LOCAL_PATH"
   mkdir -p $MIRROR_ROOT/$LOCAL_PATH
   rsync -a $LOCAL_PATH/ $MIRROR_ROOT/$LOCAL_PATH
}


mirror_dir "/boot/grub"
mirror_dir "/root"  

要添加或删除路径,只需mirror_dir在底部添加或删除调用即可。

答案1

我编辑了上述脚本以包含纯文件。

也许有人应该添加一种在脚本之外配置它的可能性(在 etckeeper 配置中?)并将其作为补丁发送给 joey hess?

#!/bin/sh
set -e

# Based on nealmcb's + ErebusBat's script from http://serverfault.com/questions/211425/

# If you want other configuration data or files on the system also
# opportunistically tracked via etckeeper, use this script to copy them in.

# If there is a hook of some sort available related to the files
# you're mirroring, you can call etckeeper directly and track them
# proactively, rather than just opportunistically here.

MIRROR_ROOT=/etc/etckeeper.mirror.d
echo "etckeeper: mirroring outside files to $MIRROR_ROOT/:"

mirror_dir() {
   LOCAL_PATH=$1
   echo "  $LOCAL_PATH"
   mkdir -p $MIRROR_ROOT/$LOCAL_PATH
   rsync -a --del $LOCAL_PATH/ $MIRROR_ROOT/$LOCAL_PATH
}

mirror_file() {
   LOCAL_PATH=$1
   DIRPATH=`dirname $LOCAL_PATH | head -n 1`
   echo "  $LOCAL_PATH"
   mkdir -p $MIRROR_ROOT/$DIRPATH
   rsync -a --del $LOCAL_PATH $MIRROR_ROOT/$DIRPATH
}
mirror_file "/var/srv/foo_bar/blog/config.py"
mirror_file "/var/srv/foo_bar_another_host/trac/conf/trac.ini"
mirror_file "/tmp/wildcards/*.jpg"

答案2

etckeeper 确实允许您将其与其他系统集成。

我还想跟踪 update-grub 在 /boot 中所做的更改,因此我将下面的代码放入/etc/etckeeper/commit.d/20mirror-outside-files

这样,任何时候由于其他原因调用 etckeeper(当我安装软件时,有时是每晚等),它都会抓取并跟踪最新 grub 配置中的修订。

我发明了将这些东西放在 /etc/Mirror/ 下的惯例外部文件路径例如,/etc/Mirror/boot/grub/grub.cfg但如果有人有其他类似惯例的先例,我很乐意听听。

#!/bin/sh
set -e

# If you want other configuration data or files on the system also
# opportunistically tracked via etckeeper, use this script to copy them in.

# If there is a hook of some sort available related to the files
# you're mirroring, you can call etckeeper directly and track them
# proactively, rather than just opportunistically here.

echo etckeeper: mirroring outside files

mkdir -p /etc/Mirror/boot/grub
cp -p /boot/grub/grub.cfg /etc/Mirror/boot/grub

更新:

请注意,出于某种原因,当您执行 apt-get remove 或 purge(例如删除旧内核)时,etckeeper 不会运行此命令。奇怪……但sudo etckeeper commit在这种情况下,您可以手动运行,或者在手动运行之后运行update-grub

答案3

etckeeper 现在有一个-d选项来指示它必须在哪个目录上进行操作。

虽然触发 etckeeper 的钩子通常使用构造为etckeeper pre-install, ...,但您必须添加改用的钩子etckeeper pre-install -d /boot/grub。这可避免您的方法中出现文件重复。

请注意,如果您认为 systemd 目标、服务等文件是配置文件(我是这么认为的 - 毕竟下的文件/lib/systemd与下的文件没有太大区别/etc/init.d),那么此-d选项将帮助您跟踪中发生的情况/lib/systemd

答案4

我认为 etckeeper 不会这样做,但有几个解决方案:

  1. 反转链接:在文件系统上放置指向 /etc/ 中文件的链接

  2. 编写脚本,将这些文件复制到 /etc(备份)和从 /etc 复制出(恢复)。然后定期或在适当的 git hook 中使用这些脚本。

相关内容