Linux: Track changes of a folder by git and cron

Hi,

this post describes howto to track changes to a folder with some (text) files in it.

Let use assume we want to track the zone files of a bind name server daemon.

  • The files are located in /var/named
  • The track frequency is 3h

Install necessary packages (here for debian/Ubuntu/Mint), gitk is just needed if you want to use a X11 GUI for compare changes

root@debdev # apt-get update
root@debdev # apt-get -y install git gitk

First we have to create a git repository, add all files and make a first commit. For security reasons use the named user.

root@debdev # cd /var/named
root@debdev # git init
root@debdev # chown -R named:named /var/named/.git

Change User

root@debdev # su named -s /bin/bash
bash-4.1 $  git add --all
bash-4.1 $  git commit -m "DNS repository init."

Create a cron job. The job is running every 3 hours and creates a git tag when changes are detected.
Open crontab

bash-4.1 $  crontab -e

and add the job.

# Git Job for tracking bind zone files
0 */3 * * * (cd /var/named && git add --all && git commit -a -m " `date`" && git tag -a `date +\%Y\%m\%d-\%H\%M` -m `date +\%Y\%m\%d-\%H\%M`)

Michael

Leave a Reply Cancel reply