Eli Fulkerson .com HomeProjectsHelper-scripts-for-netapp-filer
 


Helper Scripts for the NetApp filer

Description:

Scripts to help automate usage of a NetApp Filer.

Platform:

Unix. Expects the NetApp to be mounted via nfs


avgdate

Parses the contents of a directory (non-recursive) and reports back the most common timestamp. If there is a tie, it will just chose one of them with no guarantees. This is useful when looking at a NetApp's .snapshot directory, since all the entries within it have the exact same timestamp. (Which day did nightly.4 run again?) In the case of backups, most of the files within the backup directory should have the same date stamped on them, so this script accurately maps backup directories to the proper day.

Update: apparently you can just use ls -lu to see the timestamp you are interested in, the -u timestamp is correctly set. But here is the script anyway:

#!/bin/bash

# Figure out what the most common timestamp is in the top level of a
# list of directories, and spit it out.

# Why is this useful?  Because the NetApp snapshot directory is listed
# as... nightly.0, nightly.1, etc... and all the timestamps at that level
# are identical.  This script lets you quickly find which directory is
# from a particular day.  Also we are lazy.

# requires... bash, awk, uniq, sort, tail, tr, printf

# This script lives at http://www.elifulkerson.com


# if we didn't get a target, go ahead and use * in the local directory
if [ $# = 0 ]
then
   dirs=`ls`
else
   dirs=$*
fi

echo "Avg Date   Directory";
echo "---------- ---------";

for file in $dirs; do
  if [ -d $file ]
  then
    ls -al $file |awk '{print $6}'|uniq -c|sort -n|tail -n 1|awk '{print $2}'|tr '\n' ' '
    printf "%s \n" $file
  fi
done;

Download (plain text)


versions

Checks for other versions of a specified file within the ./.snapshot directory. Since on the NetApp all the files within .snapshot will be identically named to the original, this works very quickly. You can then check timestamps/filesizes on all the different versions and determine which one you are looking for.


#!/bin/bash

# check the current snapshots directory for other versions of a specific
# filename (using full local path), and do an ls -ald on them to see when
# timestamps, size, etc change.

# This expects the directory structure that NetApp filer's use for their
# snapshots, otherwise it won't work so well.

# Purposefully did not use 'find', because it takes too long.

if [ $# = 0 ]
then
   echo "You must specifiy a target file, using its full path from the netapp mount"
else
 
   target=$*;
   
   cd .snapshot
   for dirs in `ls`; do
       ls -ald $dirs/$target
   done;
   cd ..
fi

Download (plain text)