#!/bin/sh # fsdelta - Find the total size of all files changed in the last day # Useful primarily to find the rate of change on a filesystem for # determining the incramental backup size. # # Tested on: # Linux (RHEL 4): OK # AIX (5.3): OK # OS X (10.4): OK # Solaris (10): OK (Set shell to /usr/bin/ksh) # # Portability notes: # Works across most platforms because most Unicies seem to implement sh as # a sh-compatible version of (or hard link to) bash. This functionality breaks # on Solaris. # I would prefer to use the proper shell, rather than sneaking the math # lines into sh through the bash/ksh compatibility that is assumed but # ksh is not availible by default on Linux. # The correct answer is to use the proper shell for your environment which # most likely will be either ksh or bash. # The shell is specified for those running csh or other incompatible shells. # # License notes: # Public domain, free to use, re-distribute, modify # # Usage notes: # fsdelta finds the total size of all files changed in the last day, not the # ammount of I/O done to the filesystem. These two values can vary # significantly if writing *a lot* to one (small) file, or if writing small # ammounts to multiple large files. ### Variables ### # FS_ROOT - The directory to check within for change delta # User changeable: On command line FS_ROOT= # TOTAL_SZ - The total size of all files # User changeable: No. Leave at 0 TOTAL_SZ=0 # FACTOR - The size factor of TOTAL_SZ # User changeable: No. Leave at B(ytes) FACTOR=B # DAYS - The number of days to check back # User changeable: Yes, but 1 should be "proper" unit of measure DAYS=1 ### Code ### # Check for input. If no input then write to stderr if [ "$1" = "" ] then echo "ERROR: No path was specified for input." 1>&2 exit fi if [ "$1" = "-h" -o "$1" = "--help" ] then echo "fsdelta - Find the change / delta of a filesystem" echo " Usage: fsdelta " exit fi # Set the directory we want to search from the command line FS_ROOT=${1} # Walk the directory, looking for sizes (in bytes) only, sum the sizes # Note: We have to do the awk here (and return size only) because if find # returns the filename it will screw up the for-loop if the filename # has a space in it. for SIZE in `find ${FS_ROOT} -ctime -${DAYS} -type f -ls | awk '{ print $7 }'` do TOTAL_SZ=$(( ${TOTAL_SZ} + ${SIZE} )) done # "Factor-up" the total size to a more readable number if [ ${TOTAL_SZ} -gt 10240 ] then TOTAL_SZ=$(( ${TOTAL_SZ} / 1024 )) FACTOR=K fi if [ ${TOTAL_SZ} -gt 10240 ] then TOTAL_SZ=$(( ${TOTAL_SZ} / 1024 )) FACTOR=M fi if [ ${TOTAL_SZ} -gt 10240 ] then TOTAL_SZ=$(( ${TOTAL_SZ} / 1024 )) FACTOR=G fi # Print out the total size of files changed in the last day echo ${TOTAL_SZ} ${FACTOR} Total