I am looking for an implementation (on Linux) of a mechanism which would automatically and transparently version any changes in a directory (recursively). This is intended to be an addition (possibly replacement if all the requested features are available) to standard versioning (SVN, git, ...)
A product on MS Windows which does this is AutoVer (to have a better idea of the requirements). I would love to have something like that but aimed at Linux in a non-graphical environment.
I saw that there are some attempts to have this functionnality on Linux, the closest one I found is autoversionning on Subversion but it is not obvious to implement on existing environments (servers where, for instance, configuration files are local).
Maybe something working with inotify
?
Thank you in advance for any pointers! WoJ
Answer
1. General purpose method using bazaar & inotify
This is untested by me but I found this write up that makes use of bzr
(bazaar) & inotifywait
to monitor a directory and version control the files in it using bazaar.
This script does all the work of watching the directory for changes:
#!/bin/bash
# go to checkout repository folder you want to watch
cd path/to/www/parent/www
# start watching the directory for changes recusively, ignoring .bzr dir
# comment is made out of dir/filename
# no output is shown from this, but wrinting a filename instead of /dev/null
# would allow logging
inotifywait –exclude \.bzr -r -q -m -e CLOSE_WRITE \
–format=”bzr commit -m ‘autocommit for %w/%f’” ./ | \
sh 2>/dev/null 1>&2 &
# disown the pid, so the inotify thread will get free from parent process
# and will not be terminated with it
PID=`ps aux | grep inotify | grep CLOSE_WRITE | grep -v grep | awk ‘{print $2}’`
disown $PID
# this is for new files, not modifications, optional
inotifywait –exclude \.bzr -r -q -m -e CREATE \
–format=”bzr add *; bzr commit -m ‘new file added %w/%f’” ./ | \
sh 2>/dev/null 1>&2 &
PID=`ps aux | grep inotify | grep CREATE | grep -v grep | awk ‘{print $2}’`
disown $PID
exit 0;
2. Managing /etc
For the special case of managing your system's /etc
directory, you can use the app etckeeper.
etckeeper is a collection of tools to let /etc be stored in a git, mercurial, darcs, or bzr repository. It hooks into apt (and other package managers including yum and pacman-g2) to automatically commit changes made to /etc during package upgrades. It tracks file metadata that revison control systems do not normally support, but that is important for /etc, such as the permissions of /etc/shadow. It's quite modular and configurable, while also being simple to use if you understand the basics of working with revision control.
Here's a good tutorial to get you started with it.
3. Using git and incron
This technique makes use of git
and incron
. For this method you need to do the following:
A. Make a repo
% mkdir $HOME/git
% cd $HOME/git
% git init
B. Create a $HOME/bin/git-autocommit
script
#!/bin/bash
REP_DIR="$HOME/git" # repository directory
NOTIFY_DIR="$HOME/srv" # directory to version
cd $REP_DIR
GIT_WORK_TREE=$NOTIFY_DIR /usr/bin/git add .
GIT_WORK_TREE=$NOTIFY_DIR /usr/bin/git commit -a -m "auto"
C. Add an entry to incrontab
% sudo incrontab -e $HOME/srv IN_MODIFY,IN_CREATE,IN_MOVED_FROM,IN_MOVED_TO $HOME/bin/git-autocommit
4. Using Flashbake
Another option is to use a tool like Flashbake. Flashbake is the version control system that Cory Doctorow (of BoingBoing fame) uses to write his books.
Flashbake uses git under the hood to track changes but is somewhere between doing automated backups and using a plain version control system yourself.
Cory wanted the version to carry prompts, snapshots of where he was at the time an automated commit occurred and what he was thinking. I quickly sketched out a Python script to pull the contextual information he wanted and started hacking together a shell script to drive git, using the Python script’s output for the commit comment when a cron job invoked the shell wrapper.
No comments:
Post a Comment