Article Listing 1 Listing 2 Listing 3 Listing 4
Listing 5 Listing 6 Listing 7 Listing 8 Listing 9
Listing 10 Listing 11 Listing 12 dec2004.tar

Listing 2 snapshot

#!/bin/ksh

#***************************************************
# Listing 2:
# File: snapshot
#
# Description:
#
# This script creates a snapshot file.  If the snapshot
# already exists, it is overwritten if the -o flag
# is used otherwise the program terminates with a prompt.
#
# Author: John Spurgeon (john.p.spurgeon@intel.com)
#
#***************************************************

if [ -z "$ENTRAP" ]
then
   $(dirname $0)/entrap
   exit 0
fi

OVERWRITE=$FALSE 

while getopts oh OPTION
do
   case "$OPTION"
   in
      o)  OVERWRITE=$TRUE;;
      h)  echo "$(basename $0) [-o] snapshot_name"
          exit 0;;
    \?)   exit 1;;
   esac
done

if [ "$OPTIND" -gt "$#" ]
then
   echo "[$(basename $0)] Error: Missing label!" >& 2
   exit 1
fi

shift $(($OPTIND - 1))
SNAPSHOT_DIR=$SNAPSHOT_ROOT/$1

if ! [ -d $SNAPSHOT_DIR ]
then
   mkdir $SNAPSHOT_DIR
fi

while read DIR FILE
do
   if [ $OVERWRITE -ne $TRUE ] && [ -f $SNAPSHOT_DIR/$FILE ]
   then
      echo "[$(basename $0)] Error: $SNAPSHOT_DIR/$FILE already exists!" >& 2 
      echo "[$(basename $0)] Tip: Use the -o option to overwrite an \
        existing snapshot." >& 2
      continue
   fi

   if ! [ -d $DIR ]
   then
      echo "[$(basename $0)] Error: Directory $DIR does not exist!" >& 2
      exit 1
   fi

   echo "Processing: $DIR"

   # Use a temporary file so the data can be sorted.
   TEMP_FILE=$TEMP_DIR/snapshot$$
    
   # Make sure the file is empty.
   > $TEMP_FILE

   # Use the find command to take a snapshot.
   find $DIR -mount -exec $ATTRIBUTES {} ';' >> $TEMP_FILE

   # Sort the data and remove the temporary file.
   sort -d $TEMP_FILE > $SNAPSHOT_DIR/$FILE
   rm $TEMP_FILE

done < $CONFIG_FILE


#!/bin/ksh