Sourced from: https://serverfault.com/questions/211425/can-etckeeper-be-used-to-track-config-files-outside-of-etc
Create a new etckeeper script: vim /etc/etckeeper/commit.d/20mirror-outside-files
#!/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 "/path/tp/foo"
mirror_dir "/path/to/bar"
# special case where we don't want to mirror a sub-directory
# we could also add a dummy .gitignore to the 'bin' directory
#rsync -a --exclude=ansible/ /home/greg/bin/ $MIRROR_ROOT/home/greg/bin/
Make the script executable: chmod +x /etc/etckeeper/commit.d/20mirror-outside-files