Saturday, May 18, 2013

FSVS automated snapshots

One common use for FSVS is to make automated snapshots of portions of your Linux file system.  Such as monitoring changes to log files, executables, or data directories.  The downside of this is that, even if nothing as changed, FSVS will still generate a SVN commit.  So if you are running FSVS on an hourly basis through the day, your SVN log will be cluttered with hundreds of commits that contain no useful information.

The following is an example of how we keep track of changes to a /cfmc directory on the server.  This runs hourly and is our primary backup against data loss on this server.  Because FSVS and SVN only send the differences across the wire, it's a very efficient method.  And since this is protecting client data, we're going to version control it and keep it for years.

The magic trick is the FCOUNT= line which runs FSVS and looks to see whether there were any changes to files in the monitored directory tree.  If it found changes, then we go ahead and do an automated commit.

#!/bin/sh
# Only executes FSVS if FSVS reports outstanding changes

FSVS_CONF=~/.fsvs-conf
FSVS_WAA=~/.fsvs-waa
export FSVS_CONF FSVS_WAA

cd /cfmc

FCOUNT=`/usr/local/bin/fsvs | grep -v 'dir.*\.$' | wc -l`

if [ $FCOUNT -gt 0 ] ; then
    /usr/local/bin/fsvs ci -m "Automatic FSVS snapshot"
else
    echo "Nothing changed"
fi

No comments: