Hello Bacula Users,
                          I have written a script in bash which I used to
verify my filelist for a fileset.  Why?  I'm paranoid and wanted some sort
of confirmation that I had no errors in my filelist (I have a dozen of them
and discovered a few tab characters).  I use the output of this script to
compare against the result from the estimate command in bconsole.  I had
found that errors in my file list were not reported and wanted a convenient
debugging method.  I also didn't want to use "estimated listing" because my
list covered thousands of files.

I'm sure the bacula-top-guns out won't be interested in this but I wanted to
mail/post it somewhere in hope that it can help someone else out there.

This was also my first bash script ever, it could be better but I hope it's
not a bad start.

Gary


Here's the code:

#!/bin/bash

# Check File List  Version 1
# This Script checks a filelist for use in the bacula director fileset
# directive.
# Usage in director:  File = </path/to/file
# Used as a comparison against bconsole estimate and to assist with any
# simple mistakes.
# Can be run by any user.

ARGS=1         # Script requires 1 arguments.
E_BADARGS=65   # Wrong number of arguments passed to script.

if [ $# -ne "$ARGS" ]
# Test number of arguments to script (always a good idea).
then
 echo "Usage: `basename $0` filelist"
 exit $E_BADARGS
fi

if [ $1 -eq "--help" ]
# Test number of arguments to script (always a good idea).
then
 echo "Usage: `basename $0` filelist"
 exit $E_BADARGS
fi

echo "Checking Include Files"
# Set up Variables
filename=$1
totalFiles=0
line_count=$(wc -l < "$filename")
oldIFS="$IFS"
IFS=$'\012'

# This is a bit kludgy due to how bash handles redirection and variables...
for fileIndex in `seq $line_count`
do
 read i

 # Count and Tabs (These will be ignored by bacula)
 tabCount=`echo "$i" | grep -o "       " | wc -l`
 if (("$tabCount" > 0))
 then
   echo "Warning:  Tab Characters Found in $i"
   echo "          Line will be ignored"
   echo
   continue
 fi

 # Check for Spaces, these shouldn't be escaped.
 spaceCount=`echo "$i" | grep -o " " | wc -l`
 if (("$spaceCount" > 0))
 then
   echo "Warning:  Space Character exists in $i, be careful!"
   echo "          Space Characters shouldn't be escaped (Prefixed by
\'\\\')"
   echo
 fi

 escapedSpaceCount=`echo "$i" | grep -o "\\ " | wc -l`
 if (("$escapedSpaceCount" > 0))
 then
   echo "Warning:  Escaped Space Character exists in $i"
   echo "          Line will be ignored"
   echo
   continue
 fi

   # Count the files in that folder
   fileCount=`find "$i" | wc -l`

   # Add count to global count
   let "totalFiles += $fileCount"

done < "$filename"

echo
echo Number of files covered by bacula file list are: $totalFiles
echo

exit 0
# End Script
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users

Reply via email to