Beforehand: Create SSH keys and add them to your GIT account on the GIT server.

apt-get install etckeeper / yum install etckeeper

nano /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`
   echo "  $LOCAL_PATH"
   mkdir -p $MIRROR_ROOT/$DIRPATH
   rsync -a --del $LOCAL_PATH $MIRROR_ROOT/$DIRPATH
}
# mirror_dir "/opt/streamline"
# mirror_file "/var/lib/named/named.conf"
chmod 755 /etc/etckeeper/commit.d/20mirror-outside-files
mkdir -p /etc/etckeeper.mirror.d
nano /etc/etckeeper/etckeeper.conf
VCS="git"
PUSH_REMOTE="origin"
cd /etc
etckeeper init
git init
git remote add origin git@HOSTNAME:REPONAME
etckeeper commit "First commit"
git push -u origin master

Adding changes

etckeeper commit "Added a line to the hosts file"

More info: https://www.digitalocean.com/community/tutorials/how-to-manage-etc-with-version-control-using-etckeeper-on-centos-7

Advertisements