13

Specifically I would like to track my grub.conf (/boot/grub/grub.conf) and some oracle files (i.e. /db/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora).

I attempted using links; however etckeeper/git only tracks where the link points to, not the actual contents. And I can not create hard links as the files are on another volume.

I know I could setup another GIT repository but I would rather have it all within etckeeper.

Update

Based on nealmcb's answer I came up with the following script:

#!/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"  

To add or remove a path you simply add or remove the mirror_dir call at the bottom.

ErebusBat
  • 905
  • 4
  • 12
  • 21
  • Not a real answer, but since comments aren't allowed (for me at least) above, sharing this: [How to reuse/extend etckeeper's metadata engine for git control of non-/etc filesystems, or extend git natively with said capability?](http://superuser.com/questions/367729/how-to-reuse-extend-etckeepers-metadata-engine-for-git-control-of-non-etc-file). (Please don't down-tick/ding me for posting a reference here simply because I wasn't able to comment, thx.) – Johnny Utahh Dec 14 '11 at 22:00

6 Answers6

6

I edited the above script to also include plain files.

maybe someone should add a possibility to configure this outside a script (in the etckeeper config?) and send this as a patch to 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"
jojoo
  • 444
  • 3
  • 10
4

etckeeper does allow you to integrate it with other systems.

I also wanted to track changes made by update-grub in /boot, so I put the code below in /etc/etckeeper/commit.d/20mirror-outside-files

This way any time etckeeper is called for other reasons (when I install software, sometimes nightly, etc), it will grab and track revisions in the latest grub configuration.

I invented the convention to put this stuff under /etc/Mirror/path-to-outside-file, e.g. /etc/Mirror/boot/grub/grub.cfg but if anyone has precedent for another such convention, I'd love to hear about it.

#!/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

Update:

Note that for some reason etckeeper doesn't run this when you do an apt-get remove or purge, e.g. to delete an old kernel. Odd.... But you can run sudo etckeeper commit manually in that case, or after a manual update-grub.

nealmcb
  • 297
  • 3
  • 9
3

etckeeper now has a -d option to indicate on which directory it must operate.

While hooks to trigger etckeeper generally use construct as etckeeper pre-install, ..., you will have to add hooks that use etckeeper pre-install -d /boot/grub instead. This shall avoid file duplication in your approach.

Note that if you consider that systemd target, service, ..., files are configuration files (I do - after all, files under /lib/systemd are not that different from files under /etc/init.d) then this -d option will help you to keep track of what happen in /lib/systemd.

phep
  • 414
  • 5
  • 15
1

From synopsis: etckeeper init -d /directory

But beware! the next time you run it, or next week, if you forget -d path, it'll could create a new standalone local repo with the default location in /etc.

So I'd recommend committing this important detail to it's config, in etckeeper.conf. A quick, grep /etc \``which etckeeper\``, reveals: ETCKEEPER_DIR=/etc, and so just use this variable in etckeeper.conf.

sed -i '1 i\ETCKEEPER_DIR=/' /etc/etckeeper/etckeeper.conf

From a desire to "keep" other stuff, file attributes included, etckeeper init -d / worked for me, but later forgetting the detail is annoying. So best to save this detail. Also, uninit does not undo using the VCS, it just deletes the whole local repo.

Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79
0

I prefer the global setting in etckeeper.conf

ETCKEEPER_DIR=/

while having a .gitignore that is blacklisting everything but some specific files:

*
!.etckeeper
!.gitignore
!etc/
!etc/fstab
# ...

etckeeper init worked, etckeeper add as well. However an etckeeper commit still scans all the / tree and doesn't come back. I already removed 20warn-problem-files , because I know the specific files being added. Debugging with bash -x shows

+ /etc/etckeeper/commit.d/20store-metadata updates
msssm
  • 1
  • 3
0

I don't think etckeeper will do this, but there are a couple of solutions:

  1. reverse the links: put a link out on the filesystem to a file in /etc/

  2. script the copying of those files into /etc (backup) and out of /etc (restore). Then use those scripts periodically or in an appropriate git hook.

pjz
  • 10,497
  • 1
  • 31
  • 40
  • 2
    While the reverse link is a good idea, and I use it in some cases there are cases where it won't work. Specifically don't try the reverse link for your `grub.conf` or else you won't be able to boot. – Zoredache Dec 10 '10 at 23:05
  • @Zoredache - Exactly. However the reverse link would probably work for my Oracle files. And and @pjz's copy method would probably work for anything on boot (grub + kernel conf). I will try this next week. – ErebusBat Dec 11 '10 at 18:17